日期:2014-05-20 浏览次数:20721 次
import java.util.*;
class Ticket{
protected String trainNum;
protected String startCity;
protected String toCity;
protected String date;
protected String startTime;
protected String toTime;
protected int seatAccount;
protected double ticketPrice;
static int ticketsNum;
public Ticket(){
ticketsNum++;
}
public String getTrainNum(){return this.trainNum;}
public String getStratCity(){return this.startCity;}
public String getToCity(){return this.toCity;}
public String getDate(){return this.date;}
public String getStartTime(){return this.startTime;}
public String getToTime(){return this.toTime;}
public void setTrainInfo(String tN,String sC, String tC, String d, String sT, String tT, int sA, double tP){
this.trainNum = tN;
this.startCity = sC;
this.toCity = tC;
this.date = d;
this.startTime = sT;
this.toTime = tT;
this.seatAccount = sA;
this.ticketPrice = tP;
}
public static Ticket[] ticket = new Ticket[2];//current tickets information
static void currentTrainInfo(){
for(int i = 0; i < ticket.length; i++){
ticket[i] = new Ticket();
}
ticket[0].setTrainInfo("K000", "Hefei", "Beijing", "12/07", "08:30", "09:30", 50, 34.0);
ticket[1].setTrainInfo("K111", "Shanghai", "Hefei", "21/07", "09:45", "11:00", 50, 50.5);
}
static void getTrainsInfo(){
Ticket.currentTrainInfo();
System.out.printf("%10s%9s%14s%14s%10s%10s%7s%10s\n",
"班 次","日 期","始 发 站","终 点 站","始发时间","到达时间","座位量","票 价");
for(int i = 0; i < Ticket.ticketsNum; i++){
System.out.printf(" %-6s%-7s%-10s%-10s%-10s%-9s%-7d%-7.2f\n",ticket[i].trainNum,ticket[i].date,ticket[i].startCity,
ticket[i].toCity,ticket[i].startTime,ticket[i].toTime,ticket[i].seatAccount,ticket[i].ticketPrice);
}
}
}
class Users extends Ticket{
protected String userName;
static int usersNum;
public Users(){
super();
usersNum++;
}
public static Users[] users = new Users[2];