Testing TipCalculator.java
Output:
What was the cost of your cruise? -1234.57 The cost must be a positive numberpass
Test 1
Output:
What was the cost of your cruise? 1234.57 What is your statisfaction rating? 0 is poor and 3 is great: -1 The satisfaction rating must be 0, 1, 2, or 3pass
Test 2
Output:
What was the cost of your cruise? 1234.57 What is your statisfaction rating? 0 is poor and 3 is great: -4 The satisfaction rating must be 0, 1, 2, or 3pass
Test 3
Output:
What was the cost of your cruise? 0 The cost must be a positive numberpass
Test 4
Output:
What was the cost of your cruise? 1234.57 What is your statisfaction rating? 0 is poor and 3 is great: 0 The tip should be $61.73pass
Test 5
Output:
What was the cost of your cruise? 2233.59 What is your statisfaction rating? 0 is poor and 3 is great: 1 The tip should be $223.36pass
Test 6
Output:
What was the cost of your cruise? 3233.59 What is your statisfaction rating? 0 is poor and 3 is great: 2 The tip should be $485.04pass
Test 7
Output:
What was the cost of your cruise? 4111.18 What is your statisfaction rating? 0 is poor and 3 is great: 3 The tip should be $822.24pass
Student files
TipCalculator.java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import java.util.Scanner;
/**
* Calculates the suggested tip
*/
public class TipCalculator
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
//get the cost
System.out.print("What was the cost of your cruise? ");
double cost = scan.nextDouble();
if (cost <= 0)
{
System.out.println("The cost must be a positive number");
return;
}
//get the satisfaction
System.out.print("What is your statisfaction rating? 0 is poor and 3 is great: ");
int satisfaction = scan.nextInt();
double tip = 0;
if (satisfaction == 0)
{
tip = cost * 5.0/100;
System.out.printf("\nThe tip should be $%.2f", tip);
}
else if (satisfaction == 1)
{
tip = cost * 10.0/100;
System.out.printf("\nThe tip should be $%.2f", tip);
}
else if (satisfaction == 2)
{
tip = cost * 15.0/100;
System.out.printf("\nThe tip should be $%.2f", tip);
}
else if (satisfaction == 3)
{
tip = cost * 20.0/100;
System.out.printf("\nThe tip should be $%.2f", tip);
}
else
{
System.out.println("\nThe satisfaction rating must be 0, 1, 2, or 3");
}
}
}
|
Score
8/8