-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShoppingCart.java
More file actions
32 lines (22 loc) · 840 Bytes
/
ShoppingCart.java
File metadata and controls
32 lines (22 loc) · 840 Bytes
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
import java.util.Scanner;
public class ShoppingCart {
public static void main(String[] args) {
// Shopping Cart program
Scanner scanner = new Scanner(System.in);
String item;
double price;
int quantity;
char currency = '$';
double total;
System.out.print("What item would you like to buy?: ");
item = scanner.nextLine();
System.out.print("What is the price of each "+ item + "?: ");
price = scanner.nextDouble();
System.out.print("How many " + item + "s do you want to buy?: ");
quantity = scanner.nextInt();
total = price * quantity;
System.out.println("\nYou have bought " + quantity + " " + item + "/s");
System.out.println("Your total is " + currency + total);
scanner.close();
}
}