-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpecificOperations.java
144 lines (106 loc) · 4.7 KB
/
SpecificOperations.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
139
140
141
142
143
144
import java.io.*;
import java.util.*;
public class SpecificOperations {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public LinkedList<GameDetails> addDetails() throws Exception {
LinkedList<GameDetails> returnList = new LinkedList<>();
while ( true ) {
System.out.println("Enter Name of the Game : ");
String name = br.readLine();
System.out.println("Enter Price of the Game : ");
String price = br.readLine();
System.out.println("Enter Source of the Game : ");
String source = br.readLine();
System.out.println("Enter Developer of the Game : ");
String developer = br.readLine();
System.out.println("Enter Storege of the Game : ");
String storage = br.readLine();
GameDetails g = new GameDetails(name,price,source,developer,storage);
returnList.add(g);
System.out.println("no :- to stop adding details");
System.out.println("yes :- to continue adding details");
String choice = br.readLine();
if ( choice.equalsIgnoreCase("no") ) {
break;
}
}
return returnList;
}
public void deleteDetails(LinkedList<GameDetails> gameList) throws Exception {
while ( true ) {
System.out.println("Enter the game you want to delete");
String gameForDeletion = br.readLine();
ListIterator<GameDetails> it = gameList.listIterator();
int count = 0;
while ( it.hasNext() ) {
GameDetails gd = (GameDetails)it.next();
if ( !(gd.getName().equals(gameForDeletion)) ) {
count++;
}
else {
break;
}
}
gameList.remove(count);
System.out.println("no :- to stop Deleting details");
System.out.println("yes :- to continue Deleting details");
String choice = br.readLine();
if ( choice.toLowerCase().equals("no") ) {
break;
}
}
}
public void updateDetails(LinkedList<GameDetails> gameList) throws Exception {
while ( true ) {
System.out.println("Enter the Name of the game you want to Update : ");
String temp = br.readLine();
System.out.println("Enter the choice for the field you want to update. ");
System.out.println("1 :- Name");
System.out.println("2 :- Price");
System.out.println("3 :- Source");
System.out.println("4 :- Developer");
System.out.println("5 :- Storage");
int field = Integer.parseInt(br.readLine());
System.out.println("Enter the new value for the field : ");
String newFeild = br.readLine();
ListIterator<GameDetails> it = gameList.listIterator();
while ( it.hasNext() ) {
GameDetails gd = (GameDetails)it.next();
if ( gd.getName().equals(temp) ) {
switch (field) {
case 1:
gd.setName(newFeild);
break;
case 2:
gd.setPrice(newFeild);
break;
case 3:
gd.setSource(newFeild);
break;
case 4:
gd.setDeveloper(newFeild);
break;
case 5:
gd.setStorage(newFeild);
break;
default:
System.out.println("Enter a valid Feild.");
}
}
}
System.out.println("no :- to stop Updating details");
System.out.println("yes :- to continue Updating details");
String choice = br.readLine();
if ( choice.toLowerCase().equals("no") ) {
break;
}
}
}
public void displayDetails(LinkedList<GameDetails> gameList) {
ListIterator<GameDetails> it = gameList.listIterator();
while ( it.hasNext() ) {
GameDetails gd = (GameDetails)it.next();
System.out.println(gd.name + " " + gd.price + " " + gd.source + " " + gd.developer + " " + gd.storage);
}
}
}