Java 如何实施培训班
我有以下两门课:Java 如何实施培训班,java,Java,我有以下两门课: public class Station{ private String id; private String description; private boolean isTerminus; private int numberPassengersInTransit; public Station(String id, String desc) { this.id = id;
public class Station{
private String id;
private String description;
private boolean isTerminus;
private int numberPassengersInTransit;
public Station(String id, String desc) {
this.id = id;
description= desc;
}
public String getDescription() {
return descrizione;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isTerminus() {
return isTerminus;
}
public void setTerminus(boolean isTerminus) {
this.isTerminus = isTerminus;
}
public String getId() {
return id;
}
public int getNumberPassengersInTransit() {
return numberPassengersInTransit;
}
public void addPassenger() {
numberPassengersInTransit++;
}
public void addGroupPassengers(int num) {
numberPassengersInTransit += num;
}
}
及
运行这两个类时,会出现以下错误:
public void addgrouppatients(int num){
public void addGroupPassengers(int num) {
if(numberPassengersOnBoard+num<NUMBER_MAX_PASSENGERS)
numberPassengersOnBoard++;
else
System.out.println("Error");
}
如果(numberPassengersOnBoard+numDebug您的代码!从为什么不AddGroupPassenger()
使用num
参数开始?“如何修复上述三个错误?”-您是否尝试过使用IDE的调试器?是否尝试过?它们将允许您确定测试失败的原因。然后(可能)修复它们只是想一想。你可能想检查一下如何使用调试器。
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class StationTest {
private Station sta;
@Before
public void setUp() throws Exception {
sta = new Station("STRM0001","Giardinetti");
}
@Test
public void testConstructorStation() {
assertEquals("The station id was not initialized correctly",
"STRM0001", sta.getId());
assertEquals("The description from the station was not initialized correctly",
"Giardinetti", sta.getDescription());
assertEquals("At creation the number of passengers in transit is 0.",
0, sta.getNumberPassengersInTransit());
}
@Test
public void testAddPassenger() {
sta.addPassenger();
assertEquals("After adding a passenger for the first time, the number of passengers in transit must be 1.",
1, sta.getNumberPassengersInTransit());
}
@Test
public void testAddGroupPassengers() {
sta.addGroupPassengers(5);
assertEquals("After adding a group of passengers for the first time, the number of passengers in transit must be consistent.",
5, sta.getNumberPassengersInTransit());
}
@Test
public void testAddPassengerAndThenGroupPassengers() {
sta.addPassenger();
sta.addGroupPassengers(3);
assertEquals("After adding a passenger and then a group of passengers" +
" the number of passengers in transit must be consistent.",
4, sta.getNumberPassengersInTransit());
}
@Test
public void testAggiungiGruppoPasseggeriEPoiPasseggero() {
sta.addGroupPassengers(2);
sta.addPassenger();
assertEquals("After adding a passenger and then a group of passengers" +
" the number of passengers in transit must be consistent.",
3, sta.getNumberPassengersInTransit());
}
}
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class TrenoTest {
private Train trainTest;
private Station stationTest;
@Before
public void setUp() throws Exception {
trainTest = new Train("testRM001", "Yellow arrow", stationTest);
}
@Test
public void testConstructorTrain() {
assertEquals("L'id from the train was not initialized correctly",
"testRM001", trainTest.getId());
assertEquals("The description from the train was not initialized correctly",
"Yellow arrow", trainTest.getDescription());
assertEquals("The train station was not initialized correctly. ",
stationTest, trainTest.getParkingPlace());
}
@Test
public void testRuns() {
Station st1 = new Station("STRM0001","Giardinetti");
trainTest.setParkingPlace(st1);
Station st2 = new Station("STRM0002","Termini");
assertEquals("The departure station does not coincide with the train station.",
st1, trainTest.getParkingPlace());
trenoTest.effettuaCorsa(st2);
assertEquals("The arrival station does not coincide with the train station.",
st2, trainTest.getParkingPlace());
String log = "The testRM001 train travels from Giardinetti station to Termini station.";
assertEquals("The log does not report correct information.", log, trainTest.getLog());
}
@Test
public void testAddPassenger() {
trainTest.addPassenger();
assertEquals("After adding a passenger for the first time, the number of passengers in transit must be 1.",
1, trainTest.getNumberPassengersOnBoard());
}
@Test
public void testAddGroupPassengers() {
trainTest.addGroupPassengers(5);
assertEquals("After adding a group of passengers for the first time, the number of passengers in transit must be consistent.",
5, trainTest.getNumberPassengersOnBoard());
}
@Test
public void testAddPassengerAndThenGroupPassengers() {
trainTest.addPassenger();
trainTest.addGroupPassengers(3);
assertEquals("After adding a passenger and then a group of passengers" +
" the number of passengers in transit must be consistent.",
4, trainTest.getNumberPassengersOnBoard());
}
@Test
public void testAddGroupPassengersAndThenPassenger() {
trainTest.addGroupPassengers(2);
trainTest.addPassenger();
assertEquals("After adding a passenger and then a group of passengers " +
" the number of passengers in transit must be consistent.",
3, trainTest.getNumberPassengersOnBoard());
}
}
public void addGroupPassengers(int num) {
if(numberPassengersOnBoard+num<NUMBER_MAX_PASSENGERS)
numberPassengersOnBoard++;
else
System.out.println("Error");
}
public void addGroupPassengers(int num) {
if(numberPassengersOnBoard+num<NUMBER_MAX_PASSENGERS)
numberPassengersOnBoard+= num;
else
System.out.println("Error");
}