我是 java 新手,但一直在玩数组列表,现在卡住了。
我从一个名为 Car 的类中创建了一个数组列表,其中包含三个参数,其中一个称为timesmoved。
主班
public class GarageTester {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException{
// create Bank object
Garage bashimGarage = new Garage() ;
// create Scanner object associated with input file
Scanner fileScan = new Scanner(new
File("C:\\Users\\jamison\\Desktop\\GarageData.txt")) ;
// read BankAccount data from file, create objects, and add to list
while ( fileScan.hasNextLine()) // while not eof
{
String fullText = fileScan.nextLine();
// Split the acquired string into 2 based on the whitespace
String[] splitText = fullText.split("\\s+");
// String before whitespace split
String licensePlate = splitText[0];
// String after whitespace split
String status = splitText[1];
// create Car object
Car newCar = new Car(licensePlate, status , 0) ;
// add to list
bashimGarage.addCar( newCar ) ;
}
/*
*Calculates the number of times car was temporary moved before departure
*/
bashimGarage.carDepart();
/*
*Prints list of car license plates
* Admits or declines a car to the garage
* Prints if a car departs the Garage
* When a car departs also prints the number of times it was moved
*/
bashimGarage.moveCarInGarage();
车类
public class Car {
private String licensePlate; // License Plate Number
private String status ; // Status: Arivved or Departed
private int moved; /* How many times the car
got moved out of the garage
*/
public Car ( String licenseNum, String carStatus , int timesMoved)
{
licensePlate = licenseNum ;
status = carStatus ;
moved = timesMoved;
}
public String getLicenseNum()
{
return licensePlate;
}
public String getStatus()
{
return status;
}
public int getTimesMoved()
{
return moved;
}
绝地无双
茅侃侃
相关分类