-
October 5th, 2010, 06:22 PM
#1
New to Java Programming! Need Help!
I need to create a class that calculates a customer's bill for three different internet subscription packages. The three packages are: Package A: $9.95 per month, 10 hours of access provided. Additional hours are $2 per hour. Package B: $14.95 per month, 20 hours of access are provided. Additional hours are $1 and hour. Package C: $19.95 per month, unlimited access provided.
This is what I got so far:
public class bill
{
// Constants
public static final double PACKAGEA = 9.95;
public static final double PACKAGEB = 14.95;
public static final double PACKAGEC = 19.95;
// variables of class
private int hours; // hours internet used
private String code; // type of package
// Constructor assigns the hours used and package
public bill(int hours1, String code1)
{
hours = hours1;
code = code1;
}
// Accessor, GetHours
public int GetHours()
{
return hours;
}
// Accessor, GetPackage
public String GetPackage()
{
return code;
}
----------------------------------------------------------------------------------------------------------------------
This is where I'm stuck, I need to make a conditional statement to calculate the bill but am not sure how to do this I was planning on using something like if(code.equals("A")) type of statement. Please Help!
-
October 6th, 2010, 07:02 AM
#2
Re: New to Java Programming! Need Help!
Your class at the moment doesn't contain any information on the number of hours provided and/or the cost of extra time.
You shouldn't use floating point arithmetic for computing currency values - you can get rounding errors which may result in inaccurate final values.
Really you should have a separate class for the packages that encapsulate the details of what the package offers the customer. The Package class could also compute the monthly cost given the hours used.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|