Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need help fixing

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help fixing

    For some reason this program will not give me an answer all it says is, Enter the letter of the package you purchased (either A,B, or C.)
    When "A" is entered it says, Enter the amount of hours you used.
    If any number at all is is entered it says, please enter A,B, or C).
    It should give your current charge based on what number you enter.

    package internetserviceprovider;
    import javax.swing.JOptionPane;
    /**
    *
    * @author Home
    */
    public class Main {
     
    /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
    char packageLetter;
            int hoursUsed;
            int additionalHours = 0;
            double monthlyFee = 0;
            double additionalHoursFee;
            double totalFee;
            String inputString;
     
            inputString = JOptionPane.showInputDialog("Enter the letter of the " +
                    "package you purchased (either A, B, or C.)");
            inputString = inputString.toUpperCase();
            packageLetter = inputString.charAt(0);
     
            inputString = JOptionPane.showInputDialog("Enter the number of hours " +
                    "you used.");
            hoursUsed = Integer.parseInt(inputString);
     
            {
            if (packageLetter=='A'&& additionalHours > 0 && hoursUsed > 10)
            {
                monthlyFee = 9.95;
                additionalHours = hoursUsed - 10;
                additionalHoursFee = additionalHours * 2.00;
                totalFee = monthlyFee + additionalHoursFee;
                JOptionPane.showMessageDialog(null,"The total charges is $" +
                            totalFee + ".");
            }
            if(packageLetter=='B' && additionalHours>0 && hoursUsed>20)
            {
                monthlyFee = 13.95;
                additionalHours = hoursUsed - 20;
                additionalHoursFee = additionalHours * 1.00;
                totalFee = monthlyFee + additionalHoursFee;
                JOptionPane.showMessageDialog(null,"The total charges is $" +
                            totalFee + ".");
            }
            if(packageLetter=='C')
            {
                totalFee = 19.95;
                JOptionPane.showMessageDialog(null,"The total charges is $" +
                            totalFee + ".");
            }
     
                else
                    JOptionPane.showMessageDialog(null,"Please enter either A,B, " +
                            "or C).");
            }
     
            System.exit(0);
     
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Need help fixing

    Try debugging the code by adding some println statements that print out the values of the variables used in the if statements so you can see what the computer sees and maybe understand what the problem is.

    If you want more help, add some println statements next to the JOptionPane methods that prints out what the JOptionPane methods display. Then when you execute the code everything that happens will be printed on the console which you can copy and paste here to show us what the code is doing when it executes.

    On windows: To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    Last edited by Norm; September 11th, 2012 at 03:10 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help fixing

    Can you give me an example of what you are talking about or is it like below
    package internetserviceprovider;
    import javax.swing.JOptionPane;
    /**
    *
    * @author Home
    */
    public class Main {
     
    /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
    char packageLetter;
            int hoursUsed;
            int additionalHours = 0;
            double monthlyFee = 0;
            double additionalHoursFee;
            double totalFee;
            String inputString;
     
            inputString = JOptionPane.showInputDialog("Enter the letter of the " +
                    "package you purchased (either A, B, or C.)");
            inputString = inputString.toUpperCase();
            packageLetter = inputString.charAt(0);
     
            inputString = JOptionPane.showInputDialog("Enter the number of hours " +
                    "you used.");
            hoursUsed = Integer.parseInt(inputString);
     
            {
            if (packageLetter=='A'&& additionalHours > 0 && hoursUsed > 10)
            {
                monthlyFee = 9.95;
                additionalHours = hoursUsed - 10;
                additionalHoursFee = additionalHours * 2.00;
                totalFee = monthlyFee + additionalHoursFee;
                JOptionPane.printinshowMessageDialog(null,"The total charges is $" +
                            totalFee + ".");
            }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Need help fixing

    is it like below
    I don't see any calls to the println() method that prints out the values of the variables used in the if statement. The println must be before the if statement so you can see the values of all the variables used in the if statement.
    Here is a sample that prints out one variable:
     
            System.out.println("aP ae="+ae);

    Do that for all the variables in the if.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. help fixing the code of gui
    By aperson in forum AWT / Java Swing
    Replies: 1
    Last Post: January 21st, 2012, 07:20 AM
  2. Help fixing my first program
    By javadude in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 9th, 2012, 06:52 PM
  3. Fixing the scan input
    By Twoacross in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 14th, 2011, 07:42 AM
  4. I am having a hard time fixing this error
    By KuruptingYou in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 28th, 2011, 10:12 PM
  5. [SOLVED] Error of "cannot find symbol"
    By big_c in forum File I/O & Other I/O Streams
    Replies: 31
    Last Post: April 9th, 2009, 11:20 AM