Results 1 to 4 of 4
- 09-26-2012, 06:43 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 1
- Rep Power
- 0
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);
}
}
- 09-26-2012, 07:11 PM #2
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.
- 09-26-2012, 08:09 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 49
- Rep Power
- 0
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.
- 09-27-2012, 06:54 AM #4
Member
- Join Date
- Sep 2012
- Posts
- 8
- Rep Power
- 0
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
-
How to ERROR if user presses Enter?
By net2chris in forum New To JavaReplies: 3Last Post: 10-03-2011, 05:30 PM -
Creating unspecified ammount of objects
By plm-pusik in forum New To JavaReplies: 3Last Post: 09-01-2010, 06:46 PM -
RegardingSgould Enter in user defined inbox
By Prashant.surwade in forum CLDC and MIDPReplies: 0Last Post: 09-23-2009, 01:21 PM -
[SOLVED] how to run loop unless and until user enter correct value
By mfaizan24 in forum New To JavaReplies: 21Last Post: 06-11-2009, 02:18 AM -
How do check I allow user to enter only alpha numeric and -?
By tanalyw in forum New To JavaReplies: 2Last Post: 04-16-2008, 12:18 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks