forked from angiejones/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCashier.java
More file actions
35 lines (23 loc) · 836 Bytes
/
Copy pathCashier.java
File metadata and controls
35 lines (23 loc) · 836 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
33
34
35
package chapter4;
import java.util.Scanner;
/*
* FOR LOOP:
* Write a cashier program that will scan a given number of items and tally the cost.
*/
public class Cashier {
public static void main(String args[]){
//Get number of items to scan
System.out.println("Enter the number of items you would you like to scan:");
Scanner scanner = new Scanner(System.in);
int quantity = scanner.nextInt();
double total = 0;
//Create loop to iterate through all of the items and accumulate the costs
for(int i=0; i<quantity; i++){
System.out.println("Enter the cost of the item:");
double price = scanner.nextDouble();
total = total + price;
}
scanner.close();
System.out.println("Your total is $" + total);
}
}