-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabWork.java
More file actions
149 lines (132 loc) · 6.12 KB
/
LabWork.java
File metadata and controls
149 lines (132 loc) · 6.12 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
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
145
146
147
148
149
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Objects;
import java.util.Scanner;
public class LabWork implements Comparable<LabWork>{
static int lastid = 0;
private int id; //Значение поля должно быть больше 0, Значение этого поля должно быть уникальным, Значение этого поля должно генерироваться автоматически
private String name; //Поле не может быть null, Строка не может быть пустой
private Coordinates coordinates; //Поле не может быть null
private java.time.ZonedDateTime creationDate; //Поле не может быть null, Значение этого поля должно генерироваться автоматически
private Integer minimalPoint; //Поле может быть null, Значение поля должно быть больше 0
private String description; //Длина строки не должна быть больше 5207, Поле не может быть null
private Difficulty difficulty; //Поле не может быть null
private Person author; //Поле не может быть null
public LabWork(String name, Coordinates coordinates, Integer minimalPoint, String description,
Difficulty difficulty, Person author) {
this.name = name;
this.coordinates = coordinates;
this.minimalPoint = minimalPoint;
this.description = description;
this.difficulty = difficulty;
this.author = author;
this.creationDate = ZonedDateTime.now();
this.id = lastid++;
}
public LabWork(int id, String name, Coordinates coordinates, ZonedDateTime creationDate, Integer minimalPoint,
String description, Difficulty difficulty, Person author) {
this.id = id;
this.name = name;
this.coordinates = coordinates;
this.creationDate = creationDate;
this.minimalPoint = minimalPoint;
this.description = description;
this.difficulty = difficulty;
this.author = author;
lastid = Math.max(lastid, id + 1);
}
public int getId() {
return id;
}
public Integer getMinimalPoint() {
return minimalPoint;
}
public String getName() {
return name;
}
public static LabWork insert() {
Scanner in = new Scanner(System.in);
String input = "";
String name = ""; //Поле не может быть null, Строка не может быть пустой
Integer minimalPoint; //Поле может быть null, Значение поля должно быть больше 0
String description = ""; //Длина строки не должна быть больше 5207, Поле не может быть null
Difficulty difficulty; //Поле не может быть null
do {
System.out.print("Введите название работы: ");
if (in.hasNextLine())
name = in.nextLine();
else {
System.out.println("Плохой символ");
System.exit(0);
}
} while(name.isEmpty() || name.contains(";") || Menu.isOnlyTab(name));
do {
System.out.print("Введите минимальный бал: ");
if (in.hasNextLine())
input = in.nextLine();
else {
System.out.println("Плохой символ");
System.exit(0);
}
} while(!Menu.isInteger(input) || Integer.parseInt(input) <= 0);
minimalPoint = Integer.parseInt(input);
do {
System.out.print("Введите описание работы: ");
if (in.hasNextLine())
description = in.nextLine();
else {
System.out.println("Плохой символ");
System.exit(0);
}
} while(description.isEmpty() || description.length() >= 5207 || input.contains(";") || Menu.isOnlyTab(name));
String a = Arrays.toString(Difficulty.values());
do {
System.out.println(a);
System.out.print("Выберите уровень сложности: ");
if (in.hasNextLine())
input = in.nextLine();
else {
System.out.println("Плохой символ");
System.exit(0);
}
} while(!a.contains(input));
difficulty = Difficulty.valueOf(input);
return new LabWork(name, Coordinates.insert(), minimalPoint, description, difficulty, Person.insert());
}
public String parse(char del) {
return Integer.toString(id) +
del + name +
del + coordinates.parse(del) +
del + creationDate.getYear() +
del + creationDate.getMonthValue() +
del + creationDate.getDayOfMonth() +
del + creationDate.getHour() +
del + creationDate.getMinute() +
del + creationDate.getSecond() +
del + minimalPoint +
del + description +
del + difficulty +
del + author.parse(del);
}
@Override
public int compareTo(LabWork o) {
return name.compareTo(o.name) == 0 ? creationDate.compareTo(o.creationDate) : name.compareTo(o.name);
}
@Override
public String toString() {
return "LabWork{" +
"id=" + id +
", name='" + name + '\'' +
", \n\tcoordinates=" + coordinates +
", \n\tcreationDate=" + creationDate +
", \n\tminimalPoint=" + minimalPoint +
", \n\tdescription='" + description + '\'' +
", \n\tdifficulty=" + difficulty +
", \n\tauthor=" + author +
'}';
}
@Override
public int hashCode() {
return Objects.hash(id, name, coordinates, creationDate, minimalPoint, description, difficulty, author);
}
}