-
Notifications
You must be signed in to change notification settings - Fork 0
/
Product.java
138 lines (121 loc) · 3.93 KB
/
Product.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* Product Class - Functions for buyer and seller
* @author Nirmit Agrawal, [email protected]
* @version 1.3
* @since 10-17-2022
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class Product {
public void Menu(String category) {
ArrayList<String> prod = new ArrayList<>();
try {
Scanner s = new Scanner(new File("C:\\Users\\DELL\\Desktop\\Nirmit\\ASU\\SER 515\\Assignments\\Design Pattern - Individual\\ProductInfo.txt"));
while (s.hasNext()) {
prod.add(s.next());
}
s.close();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
for (String line : prod) {
int index = line.indexOf(":");
String print = line.substring(index + 1);
if (category.equals(line.substring(0, index)))
System.out.println(print);
}
}
public String input(String username, String category) {
System.out.println("Enter the value that you want to bid for");
ArrayList<String> prod = new ArrayList<>();
ArrayList<String> available_prod = new ArrayList<>();
ArrayList<String> updated = new ArrayList<>();
try {
Scanner s = new Scanner(new File("C:\\Users\\DELL\\Desktop\\Nirmit\\ASU\\SER 515\\Assignments\\Design Pattern - Individual\\ProductInfo.txt"));
while (s.hasNext()) {
prod.add(s.next());
}
s.close();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
for (String line : prod) {
int index = line.indexOf(":");
String print = line.substring(index + 1);
if (category.equals(line.substring(0, index)))
updated.add(print);
}
try {
Scanner s = new Scanner(new File("C:\\Users\\DELL\\Desktop\\Nirmit\\ASU\\SER 515\\Assignments\\Design Pattern - Individual\\UserProduct.txt"));
while (s.hasNext()) {
String line = s.nextLine();
int index = line.indexOf(":");
String name = line.substring(0, index);
if (name.equals(username)) {
String get_prod = line.substring(index + 1);
for (String line1 : prod) {
int index1 = line1.indexOf(":");
String p = line1.substring(index1 + 1);
line1 = line1.substring(0, index1);
if (line1.equals(category) && get_prod.equals(p)) {
available_prod.add(p);
}
}
}
}
s.close();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
Scanner sc = new Scanner(System.in);
String input = sc.next();
if (available_prod.contains(input))
{
System.out.println("Value already entered - Terminating");
System.exit(-1);
}
else if (updated.contains(input)) {
return input;
} else {
System.out.println("wrong value entered - Terminating");
System.exit(-1);
}
return "false";
}
public void showcart(String username, String category) {
ArrayList<String> prod = new ArrayList<>();
try {
Scanner s = new Scanner(new File("C:\\Users\\DELL\\Desktop\\Nirmit\\ASU\\SER 515\\Assignments\\Design Pattern - Individual\\ProductInfo.txt"));
while (s.hasNext()) {
prod.add(s.next());
}
s.close();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
try {
Scanner s = new Scanner(new File("C:\\Users\\DELL\\Desktop\\Nirmit\\ASU\\SER 515\\Assignments\\Design Pattern - Individual\\UserProduct.txt"));
while (s.hasNext()) {
String line = s.nextLine();
int index = line.indexOf(":");
String name = line.substring(0, index);
if (name.equals(username)) {
String get_prod = line.substring(index + 1);
for (String line1 : prod) {
int index1 = line1.indexOf(":");
String p = line1.substring(index1 + 1);
line1 = line1.substring(0, index1);
if (line1.equals(category) && get_prod.equals(p)) {
System.out.println(get_prod);
}
}
}
}
s.close();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
}