-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditTable.java
More file actions
66 lines (53 loc) · 1.33 KB
/
EditTable.java
File metadata and controls
66 lines (53 loc) · 1.33 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
import java.util.*;
class EditTable {
Map<String, Table> tables = new HashMap<String, Table>();
Table current;
private enum dataType {number, text};
// Create a new table
void createTable(String name) {
Table newtable = new Table(name);
tables.put(name, newtable);
current = newtable;
}
void addTableHeader(String header) {
current.setHeader(header);
}
void defineType(String typein) {
if (typein == null || typein.isEmpty()) {
System.out.println("Please type in every column's type with number or text.");
return;
}
String[] words = typein.split(" ");
dataType type;
for (String word : words) {
type = dataType.valueOf(word);
switch (type) {
case number:
current.addTableColumn(new Column("double"));
break;
case text:
current.addTableColumn(new Column("String"));
break;
default:
System.out.println("Please type in number or text.");
}
}
}
// Locate to the specific table
void switchTable(String name) {
boolean flag = false; // Mark whether successful
for (String key : tables.keySet()) {
if (key == name) {
current = tables.get(key);
flag = true;
}
}
if (flag == false) {
System.out.println("Can't find the table.");
}
}
// Add table's data
// ===============TESTING===============
public static void main(String[] args) {
}
}