This repository was archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfectionTest.java
More file actions
93 lines (85 loc) · 2.11 KB
/
Copy pathInfectionTest.java
File metadata and controls
93 lines (85 loc) · 2.11 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
/**
*
* NB: DO NOT MODIFY THIS CLASS IN ANY WAY
*
* A record of a test of infection.
* The status of the test is unknown initially.
* Whether the test is positive or negative is
* only meaningful if its status is known.
*
* @author David J. Barnes
* @version 2021.11.01
*/
public class InfectionTest
{
// The test ID.
private String id;
private boolean statusKnown;
private boolean positive;
/**
* Constructor for objects of class InfectionReport
*/
public InfectionTest(String id)
{
this.id = id;
statusKnown = false;
positive = false;
}
/**
* Get the ID of the test.
* @return the ID.
*/
public String getID()
{
return id;
}
/**
* Get whether the test status is known or not.
* @return true if the status is known,
* false otherwise.
*/
public boolean isKnown()
{
return statusKnown;
}
/**
* Get whether the test is positive or not.
* NB: This method must only be called if the status
* is known, otherwise the result would be undefined.
* @return true if the result is positive, false otherwise.
*/
public boolean isPositive()
{
if(!statusKnown) {
throw new IllegalStateException("The status is not valid.");
}
return positive;
}
/**
* Set the status to be known and the positive/negative
* status to the given value.
*/
public void setStatus(boolean positive)
{
statusKnown = true;
this.positive = positive;
}
/**
* Return whether the test is positive or negative
* if the result is known.
* @return details of the test.
*/
public String getDetails()
{
StringBuilder details = new StringBuilder();
details.append(id).append(' ');
if(statusKnown) {
details.append("is ");
details.append(positive ? "positive" : "negative");
}
else {
details.append("status unknown");
}
return details.toString();
}
}