-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplegrocerystore.Java
More file actions
101 lines (78 loc) · 2.31 KB
/
simplegrocerystore.Java
File metadata and controls
101 lines (78 loc) · 2.31 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package Applecation12;
import java.util.Scanner;
public class Applecation12 {
private static String bill;
public static void v(String args[]) {
Scanner input = new Scanner(System.in);
String bill = "";
int total = 0;
Products p1 = new Products();
p1.name = "tea";
p1.id = "15247";
p1.price = 5;
p1.shelfNumber = 3;
Products p2 = new Products();
p2.name = "milk";
p2.id = "13597";
p2.price = 10;
p2.shelfNumber = 4;
Products p3 = new Products();
p3.name = "cola";
p3.id = "15863";
p3.price = 4;
p3.shelfNumber = 2;
Products p4 = new Products();
p4.name = "coffee";
p4.id = "12597";
p4.price = 3;
p4.shelfNumber = 4;
Products p5 = new Products();
p5.name = "chocolate";
p5.id = "17896";
p5.price = 4;
p5.shelfNumber = 2;
// نطلب من المستخدم يدخل 2 او 1
Products[] x = { p1, p2, p3, p4, p5 };
System.out.print("Enter one to buy or two to search : ");
int option = input.nextInt();
if (option == 1) {
int i = 1;
for (Products p : x) {
System.out.println(i + ")" + p.name + " " + p.price);
i++;
}
while (true) {
System.out.print("Enter number of product that you want to buy -1 to end : ");
int productsNumber = input.nextInt();
if (productsNumber == -1) {
break;
}
System.out.print("Enter quantity : ");
int quantity = input.nextInt();
bill += "product name : "+x[productsNumber-1].name+" price : "+ x[productsNumber-1].price+"quantity :"+quantity+"\n";
total +=quantity*x[productsNumber-1].price;
System.out.println("----------------------------------");
}
System.out.println("bill");
System.out.println("------------------------------");
System.out.println("total : "+total+" $ "); }
else if (option == 2) {
input.nextLine();
System.out.println("Enter product name : ");
String name = input.nextLine();
boolean se = true;
for(Products p: x) {
if(p.name.equalsIgnoreCase(name)) {
System.out.println("name : "+p.name+" price : "+p.price+"shelf number : "+p.shelfNumber);
se = false;
break;
}}
if (se) {
System.out.println("does not exist");
}
} else {
System.out.println("Error");
}
input.close();
}
}