d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help With Java Constructors
Add Reply New Topic New Poll
Member
Posts: 13,862
Joined: Jan 19 2008
Gold: 366.01
Jul 9 2012 09:02am
I've got the code to get the info from the user, my question is how would i use the three different constructors, instead of just using the constructor with a full set of parameters for each person?


Code
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  

     Show console dialog. It must be readable.
     Must convey your thought processes. Comment your code.
    Quality of Craftsmanship Counts      


Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
Jul 9 2012 12:42pm
isn't finding out how to do this kind of the point of this exercise?

the 1 arg and no arg constructors probably assume some form of default values. start with the full constructor first and work your way down.

This post was edited by irimi on Jul 9 2012 12:51pm
Member
Posts: 125
Joined: Jun 19 2012
Gold: 0.00
Jul 13 2012 10:17pm
Quote (irimi @ Jul 10 2012 02:42am)
isn't finding out how to do this kind of the point of this exercise?

the 1 arg and no arg constructors probably assume some form of default values. start with the full constructor first and work your way down.


I agree, try to learn about method overloading.

And a hint on how to use 3 constructors, you just need to set their properties to be used in your payBill method. The this keyword is key.

Go Back To Programming & Development Topic List
Add Reply New Topic New Poll