-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChangeData.java
More file actions
76 lines (65 loc) · 2.6 KB
/
ChangeData.java
File metadata and controls
76 lines (65 loc) · 2.6 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
package database;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.InputMismatchException;
/**
* class changeData.
*/
public class ChangeData {
/**
* the user can change data by id.
*/
public static void changeData() {
Scanner input = new Scanner(System.in);
if (!CreateData.getValues().isEmpty()) {
System.out.println("Give me the ID of the form you want to change: ");
try {
int form = input.nextInt();
int done = 0;
for (int i = 0; i < CreateData.getValues().size(); i++) {
if (i == form) {
done = 1;
}
}
if (done == 1) {
System.out.println("Which field do you want to change?");
int index = 0;
String formfield = input.next();
int flag = 0;
for (int j = 0; j < Fields.getFields().size(); j++) {
if (Fields.getFields().get(j).equals(formfield)) {
flag = 1;
}
}
if (flag == 1) {
System.out.println("Give me the new value: ");
String newvalue = input.next();
for (int i = 0; i < Fields.getFields().size(); i++) {
if ((Fields.getFields().get(i).equals(formfield))) {
index = i;
}
}
List<String> test = new ArrayList<String>();
test.addAll(CreateData.getValues().get(form));
test.set(index, newvalue);
System.out.println(test);
CreateData.getValues().put(form, test);
System.out.println("Changes done");
} else {
System.out.println("The field "
+ formfield + " does not exist.");
}
} else {
System.out.println("ID doesn't exist.");
}
} catch (InputMismatchException e) {
System.out.println("You need to enter an integer.");
}
} else {
System.out.println("The database is empty "
+ "- no data available for changes");
}
Database.menu();
}
}