Hey all, I'm having quite a bit of trouble understanding the assignment that was given to me. I don't understand how you can have several constructors... when you just need one? I'm not quite sure I understand what it's asking for as the teacher wasn't as clear as I'd like.
EDIT: just changed the class file and the main file... it is now updated... is that what they meant by three constructors?
Program 5: Class Construct & Constructors Problem Description: An Internet service provider has three different subscription packages for its customers: Package A: For $15 per month with 50 hours of access provided. Additional hours are $2.00 per hour over 50 hours. Assume usage is recorded in one-hour increments, Package B: For $20 per month with 100 hours of access provided. Additional hours are $1.50 per hour over 100 hours. Package C: For $25 per month with 150 hours access is provided. Additional hours are $1.00 per hour over 150 hours. Assume 30-day billing cycle. Design a Customer Class. The Customer Object has one principal behavior: PayBill. You will need other methods to support that behavior. Design three Constructors: Full set of parameters. Customer ID. No-Arg. Write a program that creates four Customer Objects. Each object pays the bill. Invoke each constructor. Validate all input. Demonstrate your design using the following Test Cases: Cust ID Test Case Package Hours ------- --------- ------- ----- 1101 1 A 90 2202 2 B 140 3303 3 C 190 4404 4 b 730
And here is what I have so far for the main method...
public class customerPayBill{ public static void main(String[] args){ Customer mark = new Customer("1101", "1", "A", 90); Customer julie = new Customer("2202"); Customer dubstep = new Customer("3303"); Customer joey = new Customer(); mark.payBill(); julie.payBill(); dubstep.payBill(); joey.payBill(); } }
And here is what I have for the class called Customer...
public class Customer{ private String customerID; private String testCase; private String ispPackage; private double hours; public Customer(String custID, String testC, String pack, double h){ customerID = custID; //customer ID testCase = testC; // test case # ispPackage = pack; // which package the customer has hours = h; //# of hours used up by customer } public Customer(String custID){ customerID = custID; if(customerID == "2202") { testCase = "2"; ispPackage = "B"; hours = 140; } else if (customerID == "3303"){ testCase = "3"; ispPackage = "C"; hours = 190; } } public Customer(){ customerID = "4404"; testCase = "4"; ispPackage = "B"; hours = 730; } public void payBill(){ double price = 0; if(ispPackage == "A") { price = 15 + (2.00*(hours - 50)); System.out.println("Customer ID: " + customerID + " owes the company $" + price); } else if(ispPackage == "B") { price = 20 + (1.50*(hours - 100)); System.out.println("Customer ID: " + customerID + " owes the company $" + price); } else if (ispPackage == "C") { price = 25 + (1.00*(hours - 150)); System.out.println("Customer ID: " + customerID + " owes the company $" + price); } } }
My output is
Customer ID: 1101 owes the company $95.0 Customer ID: 2202 owes the company $80.0 Customer ID: 3303 owes the company $65.0 Customer ID: 4404 owes the company $965.0