public class TipCalculator {
public static void main(String [] args) {
double rate1 = 0.1;
double rate2 = 0.15;
double rate3 = 0.2;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the purchase price: ");
double total = keyboard.nextDouble();
System.out.printf("10%%: %.2f \n", (total*rate1));
System.out.printf("15%%: %.2f \n", (total*rate2));
System.out.printf("20%%: %.2f \n", (total*rate3));
}
}
I really need help with a simple JAVA program to calculate a tip.. I am very new to JAVA. Going for I.T. but have to take this for the degree. Here are requirements:
Declare a variable for the purchase price input from the keyboard.
Declare the necessary variables for the calculations. Since there is
more than one way to do this, I will let you decide what variables to
create.
Display the three tip rates (use 10%, 15% and 20%) and amounts on
three separate lines, with appropriate labels in text.
Use: good variable names, indentations, comments, and labels for
the output.
Here is what I have so far:
import java.util.Scanner;
public class TipCalculator
{
public static void main(String [] args)
{
Scanner keyboard = new Scanner(System.in);
double tipRate1, tipRate2, tipRate3;
System.out.println("Enter the purchase price: ");
double subTotal = keyboard.nextInt ();
System.out.println("Enter how much would you like to tip: ");
double tip = 0;
tipRate1 = 0.1;
tipRate2 = 0.15;
tipRate3 = 0.2;
subTotal = keyboard.nextInt ();
System.out.print("tip rate");
System.out.println( subTotal + "tip: " + tip);
System.out.printf("A dollar amount: $%.2f", tipRate1);
}
}
Any help would be greatly appreciated.