import java.io.IOException;publicclassPerMinutePhoneextendsPhone{/**
* minutes: holds a floating-point number which represents the total number
* of minutes used during that month.
*/privatedouble minutes;/** Accessor methods */publicdoublegetMinutes(){return minutes;}/** Mutator methods */publicvoidsetMinutes(double newMinutes){
minutes = newMinutes;}/** Constructor */publicPerMinutePhone(String intCPhoneNumber,double intBaseRate)throws IOException {super(intCPhoneNumber, intBaseRate);
minutes = Input.getDouble("Minutes Used: ",0.00,500.00);double taxAmt =calcuTax();super.setTaxAmt(taxAmt);}/** to calculate the before-tax bill total */publicdoublecalcuBefTaxBill(){returnsuper.getBaseRate()+ minutes *0.25;}/** The tax calculation method */publicdoublecalcuTax(){returnsuper.getHST()*calcuBefTaxBill();}/** display of output */public String toString(){return" Amt: $ "+calcuBefTaxBill()+"\n"+" Tax: $ "+super.getTaxAmt()+"\n"+" TOTAL: $ "+(calcuBefTaxBill()+super.getTaxAmt())+"\n"+" PER MINUTE PLAN: Rate:0.25 Minutes Used: "+ minutes;}}
Phone.java
publicabstractclassPhone{/**
* phoneNumber: holds the phone number in a String object. There is no need
* for any validation of this field during input.
*/private String phoneNumber;/**
* baseRate: holds a floating-point number. This value is entered during
* keyboard input.
*/privatedouble baseRate;/**
* taxAmt: holds the calculated tax. This value is calculated when all
* customer bills are displayed.
*/privatedouble taxAmt;/** a constant for the HST tax (which is now going to be 13%). */privatefinaldouble HST =0.13;/** Accessor methods */public String getPhoneNumber(){return phoneNumber;}publicdoublegetBaseRate(){return baseRate;}publicdoublegetTaxAmt(){return taxAmt;}publicdoublegetHST(){return HST;}/** Mutator methods */publicvoidsetPhoneNumber(String newPhoneNumber){
phoneNumber = newPhoneNumber;}publicvoidsetBaseRate(double newBaseRate){
baseRate = newBaseRate;}publicvoidsetTaxAmt(double newTaxAmt){
taxAmt = newTaxAmt;}/** Constructor */publicPhone(String intPhoneNumber,double intBaseRate){
phoneNumber = intPhoneNumber;
baseRate = intBaseRate;}/** to calculate the before-tax bill total */publicabstractdoublecalcuBefTaxBill();/** The tax calculation method */publicabstractdoublecalcuTax();}
PhoneCompany.java
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.util.ArrayList;publicclassPhoneCompany{privatestatic BufferedReader stdIn =newBufferedReader(newInputStreamReader(System.in));privatestatic PrintWriter stdOut =newPrintWriter(System.out,true);privatestatic PrintWriter stdErr =newPrintWriter(System.err,true);private ArrayList<Customer> customers;publicstaticvoidmain(String[] args)throws IOException {/**
* The PhoneCompany class is used to create an object, then the
* addCustomer() and calcBills() methods are called as a result of a
* user's menu choice.
*/
PhoneCompany ph =newPhoneCompany();
ph.run();}/**
* Constructor
*/publicPhoneCompany(){
customers =newArrayList<Customer>();}/** Accessory methods */public ArrayList<Customer>getCustomers(){return customers;}/**
* Presents the user with a menu of options and executes the selected task.
*/privatevoidrun()throws IOException {int choice =getChoice();while(choice !=0){if(choice ==1){/** Add Customer */addCustomer();}elseif(choice ==2){/** Display Customer Bill */calcBills();}
choice =getChoice();}}/**
* Displays a menu of options and verifies the user's choice.
*
* @return an integer in the range [0,2]
*/privateintgetChoice()throws IOException {int input;do{try{
stdOut.println();
stdOut.print("[1] Add Customer\n"+"[2] Display Customer Bills\n"+"[0] Quit\n\n"+"Enter Choice: ");
stdOut.flush();
input = Integer.parseInt(stdIn.readLine());
stdOut.println();if(0<= input &&2>= input){break;}else{
stdErr.print("Invalid choice: "+ input);
stdOut.flush();}}catch(NumberFormatException nfe){
stdErr.println(nfe);}}while(true);return input;}/**
* The addCustomer() method will create a new Customer object and create the
* correct type of Phone object based on the user's choice. The PhoneCompany
* class must ensure that the addition of new customers will fit in the
* collection that is used to manage all the added customers.
*
* @throws IOException
*/publicvoidaddCustomer()throws IOException {
Customer customer =newCustomer();
customers.add(customer);}/**
* The calcBills() method will determine the billing total for each
* customer, then display the results.
*/publicvoidcalcBills(){double total =0.00;
stdOut.println();
stdOut.print("AirHead Phone Company\n");for(Customer customer : customers){
stdOut.println(customer.toString());
stdOut.println((customer.getCPhone()).toString());
total = total + customer.getCPhone().calcuBefTaxBill()+ customer.getCPhone().getTaxAmt();}
stdOut.println("TOTAL: "+ total);}}
TestPhoneCompany.java
import java.io.IOException;import java.io.PrintWriter;/** To test PhoneCompany class */publicclassTestPhoneCompany{privatestatic PrintWriter stdOut =newPrintWriter(System.out,true);privatestatic PrintWriter stdErr =newPrintWriter(System.err,true);publicstaticvoidassertTrue(String message,boolean condition){if(!condition){
stdErr.print("** Test failure ");
stdErr.println(message);}}publicstaticvoidmain(String[] args)throws IOException {/** Testing constructor and accessor */
PhoneCompany ph =newPhoneCompany();assertTrue("1: testing constructor and accessor",
ph.getCustomers().size()==0);/**
* Testing method addCustomer(), the customer infor as followings:
* Bill Jones
* 613-111-1111
* Base Rate: 29.00
* Flat Rate Premium: 10.00
*/
ph.addCustomer();assertTrue("2: testing addCustomer", ph.getCustomers().size()==1);assertTrue("3: testing addCustomer",(ph.getCustomers().get(0).getName().equals("Bill Jones")));assertTrue("4: testing addCustomer",(ph.getCustomers().get(0).getCPhone().getPhoneNumber().equals("613-111-1111")));assertTrue("5: testing addCustomer",(ph.getCustomers().get(0).getCPhone().getBaseRate()==29.00));assertTrue("6: testing addCustomer",(ph.getCustomers().get(0).getCPhone().getTaxAmt()==5.07));assertTrue("7: testing addCustomer",(ph.getCustomers().get(0).getCPhone().calcuBefTaxBill()+ ph.getCustomers().get(0).getCPhone().getTaxAmt()==44.07));/**
* Testing method addCustomer(), the customer infor as followings:
* Jill Wilson
* 819-222-2222
* Base Rate: 25.00
* Minutes Used: 300
*/
ph.addCustomer();assertTrue("8: testing addCustomer", ph.getCustomers().size()==2);assertTrue("9: testing addCustomer",(ph.getCustomers().get(1).getName().equals("Jill Wilson")));assertTrue("10: testing addCustomer",(ph.getCustomers().get(1).getCPhone().getPhoneNumber().equals("819-222-2222")));assertTrue("11: testing addCustomer",(ph.getCustomers().get(1).getCPhone().getBaseRate()==25.00));assertTrue("12: testing addCustomer",(ph.getCustomers().get(1).getCPhone().getTaxAmt()==13.00));assertTrue("13: testing addCustomer",(ph.getCustomers().get(1).getCPhone().calcuBefTaxBill()+ ph.getCustomers().get(1).getCPhone().getTaxAmt()==113.00));
stdOut.println("Done!");}}
Customer.javaimport java.io.IOException;public class Customer { /** The customer's name in a String object. */ private String name; /** And have a reference to a Phone object. */ private Phon...