Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Kiswar Malik   on Apr 24 In Java Category.

  
Question Answered By: Garai Chalthoum    on Apr 24

I found the answer as follows:

// PhoneBill.java
//
//
// Copyright 2004 Reynold DeMarco Jr

/**
class  for computing Phone Bills
* using LinearEquation objects.
*
* @version 1
*/

public class PhoneBill
{

public static  void main  ( String[] args  )
{

//declare doubles
double a_new, b_new, bill, end ;

//create a Terminal object
Terminal pb = new Terminal();

//get user  input parameters
b_new = pb.readDouble("Basic rate (in dollars): ");
a_new = pb.readDouble("Cost per message  unit (in cents): ");

//create a LinearEquation object
LinearEquation showBill = new LinearEquation(a_new*0.01,
b_new);

//last user input parameter  for computation
bill = pb.readDouble("Number of message units: ");

//have the LinearEquation object compute
pb.println("Phone bill is: $" + showBill.compute(bill) );

//create a second LinearEquation object
LinearEquation showEnd = new LinearEquation(100/a_new, 0.0);

//get user input  for second computation
end = pb.readInt("Amount willing to spend (in dollars): ") + -
b_new;

//have the LinearEquation object compute
pb.println("Maximum number  of message units: " +
showEnd.compute(end));

}
}

Share: