-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPetFood.java
47 lines (40 loc) · 1.17 KB
/
PetFood.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
//PetFood.java
import java.util.Scanner; // Needed for the Scanner class
/**
This program demonstates a switch statement.
*/
public class PetFood
{
public static void main(String[] args)
{
String input; // To hold the user's input
char foodGrade; // Grade of pet foodGrade
// Create a scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Promp the user for a grade of pet food.
System.out.println("Our pet food is available in " +
"three grades:");
System.out.print("A, B, and C. Which do you want " +
"pricing for? ");
input = keyboard.nextLine();
foodGrade = input.charAt(0);
// Display pricing for the selected grade.
switch(foodGrade)
{
case 'a':
case 'A':
System.out.println("30 cents per lb.");
break;
case 'b':
case 'B':
System.out.println("20 cents per lb.");
break;
case 'c':
case 'C':
System.out.println("15 cents per lb.");
break;
default:
System.out.println("Invalid choice.");
}
}
}