Results 1 to 4 of 4
  1. #1
    Diehardwalnut is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Post How do i allow user to enter ammount?

    I made this program for an assignment but i don't want to have a fixed amount for tip, i want to allow the user to enter an amount then calculate it.

    import java.util.*;
    import java.util.Scanner;

    public class TicketTip
    {
    public static void main(String[] args)
    {
    Scanner keyboard = new Scanner(System.in);
    double ammount,tip,tax,TotalTax,TotalTip,Total;

    TotalTax = .05;
    TotalTip = .15;

    System.out.println("How much is your total?:");
    ammount = keyboard.nextDouble();
    System.out.println(ammount);

    System.out.println("So, you paid " + ammount + " that means your tax is going to be");
    tax = TotalTax * ammount;
    System.out.println(tax);

    System.out.println("Excluding the tax, you'll tip 15 percent. Be sure to round");
    tip = ammount * TotalTip;
    System.out.println(tip);

    System.out.println("Your total ammount is");
    Total = ammount + tax + tip;
    System.out.printf("Total %.2f", Total);


    }
    }

  2. #2
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: How do i allow user to enter ammount?

    Please wrap your code in [code][/code] tags.
    To get the user input, you can use the Console class.
    I have found this post on this forum: How to get input from Console on how to use it.

    Edit: after looking at your code I have found that you have a Scanner. I think you can also use it to get the user input from the console.
    Last edited by PhQ; 09-26-2012 at 07:14 PM.

  3. #3
    Reeling is offline Member
    Join Date
    Jan 2012
    Posts
    49
    Rep Power
    0

    Default Re: How do i allow user to enter ammount?

    Didn't you answer your own question? Seeing as how you are already using a scanner to get user input.

  4. #4
    huupderitis is offline Member
    Join Date
    Sep 2012
    Posts
    8
    Rep Power
    0

    Default Re: How do i allow user to enter ammount?

    I think what you are wondering is how does the scanner actually get your input... Well when it's read in a console window or anything that allows typing all you have to do... is type the value and then press 'Enter'. Should work if not try using JGrasp to run your programs.

Similar Threads

  1. How to ERROR if user presses Enter?
    By net2chris in forum New To Java
    Replies: 3
    Last Post: 10-03-2011, 05:30 PM
  2. Creating unspecified ammount of objects
    By plm-pusik in forum New To Java
    Replies: 3
    Last Post: 09-01-2010, 06:46 PM
  3. RegardingSgould Enter in user defined inbox
    By Prashant.surwade in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-23-2009, 01:21 PM
  4. Replies: 21
    Last Post: 06-11-2009, 02:18 AM
  5. Replies: 2
    Last Post: 04-16-2008, 12:18 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
  •