import java.util.Scanner;
public class TipCalc
{
public static void main(String[] args);
Scanner cin = new Scanner(System.in);
{
System.out.println("Tip Calculator");
System.out.println("===============");
System.out.print("Enter check subtotal (9.25): ");
double subtotal = cin.nextDouble();
System.out.print("Enter gratuity percentage (20): ");
int gratuity = cin.nextInt();
System.out.println("");
double gratuityAmount = gratuity * .01 * subTotal;
System.out.println("\tGratuity: " + gratuityAmount);
double total = gratuityAmount + subTotal;
System.out.println("\tTotal: $" + total);
}
}
I get these errors: 3 errors found: [line: 5] Error: missing method body, or declare abstract [line: 15] Error: cannot find symbol symbol: variable subTotal location: class TipCalc [line: 17] Error: cannot find symbol symbol: variable subTotal location: class TipCalc I just started to learn Java. I am confused on to what went wrong. Any advice?
Your main method lacks a body.
public class TipCalc
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
System.out.println("Tip Calculator");
System.out.println("===============");
System.out.print("Enter check subtotal (9.25): ");
double subtotal = cin.nextDouble();
System.out.print("Enter gratuity percentage (20): ");
int gratuity = cin.nextInt();
System.out.println("");
double gratuityAmount = gratuity * .01 * subTotal; //Note: subTotal variable isn't defined
System.out.println("\tGratuity: " + gratuityAmount);
double total = gratuityAmount + subTotal;
System.out.println("\tTotal: $" + total);
}
}
That should help your formatting errors.
The method body comes immediately after such as: public void doSomething(){ <-begins body and ends with-> }
In the beginning, methods are only briefly discussed but you will go more in-depth and get the hang of it.