Page 1 of 2 12 LastLast
Results 1 to 20 of 29
  1. #1
    Kidatheart96 is offline Member
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default I don't know what I did wrong!

    I am a student in college who is working on a java program that I can't seem to finish. Whenever I compile the program, the math part in the program doesn't seem to show up.The name, car type, and number of days show up in cmd, but the subtotal, tax, and total doesn't show up at all. Here is my program so far:

    Java Code:
    import java.util.Scanner;
    import java.math.BigDecimal;
    import java.util.*;
    
    public class Bill
    {
    	private String name;
        private String CarType;
        private int NumberOfDays;
        private double Tax;
        private double Subtotal;
        private double Total;
        private double RentalRate;
    
        public void readInput()
        {
    	Scanner keyboard = new Scanner( System.in);
        System.out.println(" Please enter your name.");
        name= keyboard.nextLine();
        System.out.println(" Please enter Car type, Whether is luxury or antique car.");
        CarType= keyboard.nextLine();
        System.out.println(" Please enter number of days would you like to rent.");
        NumberOfDays= keyboard.nextInt();
        }
    
        public double Subtotal ()
        {
    	readInput();
        double RentalRate=35;
         Subtotal= RentalRate * NumberOfDays;
        return Subtotal;}
    
        public double Tax ()
        {
    	readInput();
    	double Tax;
    	Tax=0.09;
    	return Tax;}
    
        public double Total ()
        {
    	readInput ();
    	double Total;
        double Tax = 0.09;
        Total= Subtotal * 0.09;
        return Total;}
    
        public void writeOutput() {
    	Scanner keyboard = new Scanner( System.in);
        System.out.println(" Name:" + name);
    	System.out.println(" CarType:" + CarType);
    	System.out.println(" NumberOfDays:" + NumberOfDays);
    	System.out.println(" SubTotal:" + Subtotal);
    	Subtotal = keyboard.nextDouble();
    	System.out.println("Tax:" + Tax);
    	Tax = keyboard.nextDouble();
        System.out.println(" Total:" + Total);
        Total = keyboard.nextDouble(); }
    
        public static void main (String [] args) {
    		Scanner input = new Scanner(System.in);
    	    {
    	    Bill myBill = new Bill();
            myBill.readInput();
            myBill.writeOutput(); }
    	}
    }
    Last edited by Kidatheart96; 12-13-2013 at 02:41 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: I don't know what I did wrong!

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Can you copy the program's output and paste it here to show what you are talking about.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Kidatheart96 is offline Member
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Re: I don't know what I did wrong!

    I t won't let me copy it, but here is what it looks like word for word.


    Name:Jen
    CarType:Luxury
    NumberOfDays:2
    Subtotal:0.0


    The subtotal is always zero, and the tax and total don't even show up.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: I don't know what I did wrong!

    Does the program end normally? Or is it waiting for something?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: I don't know what I did wrong!

    Where do you call your methods Tax(), Subtotal(), and Total()? And why are you reading Subtotal after you print it out?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    Kidatheart96 is offline Member
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Re: I don't know what I did wrong!

    @Norm It just says press any key to continue, and then it exits out

  7. #7
    Kidatheart96 is offline Member
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Re: I don't know what I did wrong!

    @jim829 I'm sorry I don't understand your first question, could you rephrase it? I don't know why I am reading Subtotal in cmd. For some reason the rest of the math doesn't show up either.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: I don't know what I did wrong!

    It just says press any key to continue
    What is the "It" that says that? How are you executing the program? Is that message normally displayed when you execute other programs?

    I t won't let me copy it
    What is the "I t" that won't let you copy? Check again to see how to copy.
    Can you copy the full contents of the console window from when you execute the program and paste it here?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Kidatheart96 is offline Member
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Re: I don't know what I did wrong!

    Quote Originally Posted by Norm View Post
    What is the "It" that says that? How are you executing the program? Is that message normally displayed when you execute other programs?

    What is the "I t" that won't let you copy? Check again to see how to copy.
    Can you copy the full contents of the console window from when you execute the program and paste it here?
    When I say "it", I am referring to the command prompt. The command prompt will not let me copy the contents. This is what comes up in the command prompt window:

    Name: Jen
    CarType: Luxury
    NumberOfDays: 3
    Subtotal: 0.0

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: I don't know what I did wrong!

    Can you copy the whole contents of the command prompt and paste it here? You have only copied part of it. I see that the program prints this line and several others:
    Please enter your name.

    You left that out when you copied the contents of the command prompt window.


    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.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    Kidatheart96 is offline Member
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Re: I don't know what I did wrong!

    @Norm okay, here it is:

    Please enter your name.
    jen
    Please enter Car type, Whether is luxury or antique car.
    luxury
    Please enter number of days would you like to rent.
    3
    Name:jen
    CarType:luxury
    NumberOfDays:3
    SubTotal:0.0

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: I don't know what I did wrong!

    Try typing in some numbers (at least 4) when the program hangs (like it is waiting for input).


    Is that all that is on the command prompt window? Where is the command line with the java command?
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    Kidatheart96 is offline Member
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Re: I don't know what I did wrong!

    Quote Originally Posted by Norm View Post
    Try typing in some numbers (at least 4) when the program hangs (like it is waiting for input).


    Is that all that is on the command prompt window? Where is the command line with the java command?
    I tried typing in at least four numbers like you said, and this is what I got:

    Please enter your name.
    jen
    Please enter Car type, Whether is luxury or antique car.
    luxury
    Please enter number of days would you like to rent.
    3
    Name:jen
    CarType:luxury
    NumberOfDays:3
    SubTotal:0.0
    4657
    Tax:0.0

    6768
    Total:0.0
    7979
    Press any key to continue . . .

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: I don't know what I did wrong!

    That looks like the program executed all the way to the end this time. Do you understand that the program was trying to read from the console before it printed out the last part you were looking for? Look at the code to see where the code is trying to read numbers from the user. It will be right after the last line that is printed before you entered the numbers.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    Kidatheart96 is offline Member
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Re: I don't know what I did wrong!

    So now I know that it executes. I looked at the code again. Should I make some changes to this part?:
    Java Code:
    public void readInput()
        {
        Scanner keyboard = new Scanner( System.in);
        System.out.println(" Please enter your name.");
        name= keyboard.nextLine();
        System.out.println(" Please enter Car type, Whether is luxury or antique car.");
        CarType= keyboard.nextLine();
        System.out.println(" Please enter number of days would you like to rent.");
        NumberOfDays= keyboard.nextInt();
        }

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: I don't know what I did wrong!

    If that code works as you want it to, there is no need to change it. Are you having any problems with the readInput() method?
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    Kidatheart96 is offline Member
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Re: I don't know what I did wrong!

    It only worked because I entered four random numbers until the tax and total came up. I'm still not getting what I need. I need the program to output the numbers by itself. How do I do that? Do I need to make changes to the readInput() method?

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: I don't know what I did wrong!

    Where are the values computed in the code that you want to see printed?

    I need the program to output the numbers by itself
    Have you found where the program is waiting for the user to enter numbers before it prints out the messages that you are looking for? You need to remove the code that is making the program wait.
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    Kidatheart96 is offline Member
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Re: I don't know what I did wrong!

    They aren't specific numbers. They are based on what the user inputs.
    The subtotal formula = (35) * (number of days rented)
    The tax is 9%=(0.09)
    The formula for the total = (subtotal) * (0.09)
    These are the numbers that will not output by itself.

    What would the code that is making the program wait look like?

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: I don't know what I did wrong!

    Find the code that is using Scanner class methods to read input.
    If you don't understand my response, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 02:37 AM
  2. I can't find anything wrong with this but somehow it's wrong.
    By Biscuit Tickler in forum New To Java
    Replies: 2
    Last Post: 09-12-2012, 10:28 PM
  3. What Am I doing Wrong?
    By siren1111 in forum New To Java
    Replies: 3
    Last Post: 12-20-2011, 03:01 AM
  4. Replies: 10
    Last Post: 07-16-2010, 01:34 AM
  5. What am I doing wrong??
    By NoNickName in forum New To Java
    Replies: 3
    Last Post: 04-24-2009, 12:04 AM

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
  •