Results 1 to 9 of 9
  1. #1
    twyzard is offline Member
    Join Date
    Feb 2011
    Posts
    6
    Rep Power
    0

    Default Java code please help

    Hello, I am a total n00b when it comes to Java and I have this project due in two days please help me figure out how to solve this problem.


    What to do with this JAVA code?
    This is the code that I need to do without using the Joptionpane:
    An Internet service provider has three different subscription packages for its customers:
    Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
    Package B: For $13.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
    Package C: For $19.95 per month unlimited access is provided.

    Modify the code so that it calculates and displays the amount of money Package A customers would save if they purchased packages B or C, and the amount of money package b customers would save if they purchased package c or A. If there would be no savings, no message should be printed.


    This is what I have so far : Cannot use Joptionpaneshowinputdialog



    Java Code:
    import java.util.Scanner;
    /**
    This program demonstrates a switch statement.
    */
    public class ISP14
        {
            public static void main(String[] args)
                {
                    char packageLetter;
                    int hoursUsed;
                    double moneySaved1;
                    double moneySaved2;
                    double monthlyFee2;
                    double monthlyFee3;
                    int regularHours;
                    int additionalHours;
                    double monthlyFee;
                    double additionalHoursFee;
                    double totalFee;
                    double totalFee2;
                    double totalFee3;
                    String input;
    
                    Scanner keyboard = new Scanner(System.in);
    
    
                    System.out.println("Enter the letter of the " +
                    "package you purchased (either A, B, or C.)");
                    input = keyboard.nextLine();
                    packageLetter = input.charAt(0);
    
                    System.out.println("Enter the number of hours " +
                    "you used.");
                    input = keyboard.nextLine();
                    hoursUsed = Integer.parseInt(input);
    
                    switch(packageLetter)
                        {
                            case 'a':
                            case 'A':
                            monthlyFee = 9.95;
                            regularHours = 10;
                            additionalHours = hoursUsed -  regularHours;
                            additionalHoursFee = additionalHours * 2.00;
                            totalFee = monthlyFee + additionalHoursFee;
                            System.out.println("The total charges are $" + totalFee);
                            if (hoursUsed < 10)
                                totalFee = monthlyFee;
                            moneySaved1 = totalFee - totalFee2;
                            break;
    
                            case 'B':
                            case 'b':
                            monthlyFee2 = 13.95;
                            regularHours = 20;
                            additionalHours = hoursUsed - regularHours;
                            additionalHoursFee = additionalHours * 1.00;
                            totalFee2 = monthlyFee2 + additionalHoursFee;
                            if (hoursUsed < 20)
                                totalFee = monthlyFee2;
                            System.out.println("The total charges is " + totalFee);
                            break;
    
                            case 'C':
                            case 'c':
                            monthlyFee3 = 19.95;
                            totalFee3 = 19.95;
                            System.out.println("The total charges is $" +
                            totalFee + ".");
                            break;
    
                            default:
                            System.out.println("Please enter either A,B," +
                            "or C.");
    
                        }
    
                    System.exit(0);
    
                }
    
        }
    Last edited by twyzard; 02-23-2011 at 03:43 AM. Reason: Moderator edit: code tags added

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Use code tags when posting code. Make sure you recopy your code from the source as the above has lost all indentation.

    Do not dump your code on us and expect us to fix it for you. Ask a specific question and you will get a specific answer.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I added code tags to your post above, but it was unformatted to begin with (no indentations), so it is still difficult for us to read. I second Junky's request for a question. Basically my reading of your post is: "here's my assignment, here's my code, I'm stuck". It's hard to answer vague and general questions like that, and most often we will point the poster to the tutorials to help them learn Java. If you ask a very specific question though, you'll likely get a specific and helpful answer.

    Best of luck.

  4. #4
    twyzard is offline Member
    Join Date
    Feb 2011
    Posts
    6
    Rep Power
    0

    Default

    ok I indented, but I am still very lost as to how to write a string that will show the difference in prices and how much a customer could save if he were to purchase package a and used 20 hours, I know that he will save aprox. 16 bucks with package b and 10 bucks with package c , but what do I do to put it in code for example? which kind of statements do I use? if else? while? I am very lost please explain

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    What I would do is calculate the proce of all three packages and then compare them (yes with if statements) but I'm not you.

    By the way you still haven't asked a specific question. It is still "I don't know what to do".

  6. #6
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Aren't you allowed to use classes? Arrays? Methods? I really don't mean to be sarcastic. Some Java courses seem to have a very silly curriculum where they force students to do things the wrong way before they're allowed to do it the right way. My advice to you would differ depending on if you're enrolled in one of these courses.

    -Gary-

  7. #7
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    I have had 4 semesters or so doing programming in college and was asked to make my own class once or twice, it is laughable!!

  8. #8
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Well, if you're allowed to use classes, then you should create a Package class, with instance variables for baseRate, baseHours, and hourlyRate. Write a totalFee(double hours) method. Then in your main class, create three Package objects and store them in an array (or an ArrayList<Package>). Then you'll see that the rest of your logic ends up looking a lot simpler.

    I know this advice won't be very welcome when you're on such a tight deadline, and I'm sorry I couldn't give it to you sooner. If you decide not to heed it, I'm sure you figure out the if/else code you need to solve your immediate problem.

    -Gary-

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Ahhh, the old "my teacher sucks" trick.

    Assignments are set to test your understanding of the material covered so far. They do not ask you about stuff you have not covered. If you have fully understood all material then you should find the assignment easy to complete. If you are struggling then it highlights your lack of understanding and has nothing to do with your teachers vaccuum properties.

Similar Threads

  1. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  2. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 11:14 AM
  3. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 01:21 PM
  4. Java Code
    By g.ganiraju in forum New To Java
    Replies: 2
    Last Post: 10-20-2008, 02:18 PM
  5. Need a java code
    By vissu007 in forum New To Java
    Replies: 1
    Last Post: 07-11-2007, 10:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •