-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq3.java
More file actions
30 lines (28 loc) · 1.07 KB
/
q3.java
File metadata and controls
30 lines (28 loc) · 1.07 KB
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
import javax.swing.*;
public class q3 {
public static void main(String[] args) {
double total = 0;
boolean isPeas = false;
Integer amount = Integer.parseInt(JOptionPane.showInputDialog("How many items do you want? "));
String items[] = new String[amount];
double prices[] = new double[amount];
for (int num = 1; num < amount + 1; num = num + 1) {
items[num-1] = JOptionPane.showInputDialog("Enter Item " + num + ": ");
prices[num-1] = Double.parseDouble(JOptionPane.showInputDialog("Enter price for item " + num + ": "));
total = total + prices[num-1];
if (items[num-1].equals("peas")) {
isPeas = true;
};
}
for (int num = amount; num > 0; num = num -1) {
System.out.print(items[num-1] + ", ");
}
total = total / amount;
if (isPeas == true) {
System.out.print("Your total is $" + Math.round(total));
}
else {
System.out.print("No average ouput");
}
}
}