-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShipType.java
More file actions
32 lines (28 loc) · 831 Bytes
/
ShipType.java
File metadata and controls
32 lines (28 loc) · 831 Bytes
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
public final class ShipType {
private final String name;
private final int length;
private final int count;
public ShipType(String name, int length, int count) {
if (name == null || name.trim().isEmpty()) {
throw new IllegalArgumentException("Ship name must not be empty.");
}
if (length < 2) {
throw new IllegalArgumentException("Ship length must be at least 2.");
}
if (count < 1) {
throw new IllegalArgumentException("Ship count must be at least 1.");
}
this.name = name.trim();
this.length = length;
this.count = count;
}
public String getName() {
return name;
}
public int getLength() {
return length;
}
public int getCount() {
return count;
}
}