-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEx3.java
47 lines (38 loc) · 1.36 KB
/
Ex3.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
import java.util.Scanner;
public class Ex3 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int countComputer =0 , countPrinter= 0, countPhone =0;
double priceComputer = 1999.99, pricePrinteer = 55.5, pricePhone= 459.99;
while(true) {
System.out.println("Press 1 to add a computer");
System.out.println("Press 2 to add a printer ");
System.out.println("Press 3 to add a phone ");
System.out.println("Press 0 to exist");
int choice= sc.nextInt();
if (choice == 0)
break;
switch (choice) {
case 1 ://computer
System.out.println(++countComputer+"computer(s) added to cart. ");
break ;
case 2 ://printer
System.out.println(++countPrinter + "printer(s) added to cart.");
break ;
case 3 ://phone
System.out.println(++countPhone+" phone(s) added to cart ");
break ;
}
default:
System.out.println("Invalid input");
break; // we use that because end of the switch
} // end of switch
}// end of while loop
System.out.println("Your cart has" +countcomputer+ "computer(s)," + countPrinter +" printer(s)," + countPhone + "phone(s).");
double totalCost = (countComputer * priceComputer) +
(countPrinter * pricePrinter)+ (countPhone * pricePhone);
System.out.println ("Total price= " + totalCost);
}// end of main
// System.out.printf search this
//end of class
}