-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrainTest.java
More file actions
84 lines (78 loc) · 2.54 KB
/
Copy pathTrainTest.java
File metadata and controls
84 lines (78 loc) · 2.54 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
/**
* TrainTest defines a number of behaviors for the Train class
* HINT: use comments to block out the tests so that you can do
* them one at a time without getting compiler errors.
*
* @author ace
* @version 3 April 2010
*/
public class TrainTest
{
/**
* Constructor for objects of class TrainTest
*/
public TrainTest(){
}
/**
* Create a getter and a setter for the train name.
*/
public void testName(){
Train train = new Train();
train.setName("Heartland Runner");
String runner = train.getName();
if(runner.equals("Heartland Runner")){
System.out.println("test set/getName passed");
} else {
System.out.println("test set/getName failed");
}
}
/**
* Create a getter and a setter for the train length.
*/
public void testLength(){
Train train = new Train();
train.setLength(5);
int five = train.getLength();
if(five == 5){
System.out.println("test set/getLength passed");
} else{
System.out.println("test set/getLength failed");
}
}
/**
* Create a getter for the maxSpeed. Do not create a field
* for the maxSpeed, and do not create a setter for the maxSpeed.
* Use the ArrayList maxSpeed to determine the maxSpeed.
* HINT: read the documentation of the ArrayList class to
* find a method you can use.
*/
public void testMaxSpeed(){
Train train = new Train();
train.setName("Orient Express");
train.setLength(4);
String maxSpeed = train.getMaxSpeed();
if(maxSpeed.equals("321.2")){
System.out.println("test getMaxSpeed passed");
} else {
System.out.println("test getMaxSpeed failed");
}
}
/**
* Make a new constructor for Train which allows you to construct
* a train with its name and length as parameters. Keep the default
* constructor as well.
*/
public void testTrainNameLengthConstructor(){
Train train1 = new Train();
train1.setLength(3);
train1.setName("Fu Man Choo Choo");
Train train2 = new Train("Fu Man Choo Choo", 3);
if(train1.getName().equals(train2.getName())
&& train1.getLength()==train2.getLength()
&& train1.getMaxSpeed().equals(train2.getMaxSpeed())){
System.out.println("test TrainNameLengthConstructor passed");
} else {
System.out.println("test TrainNameLengthConstructor failed");
}
}
}