CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2010
    Posts
    1

    Question 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!

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

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
  •  





Click Here to Expand Forum to Full Width

Featured