首页 > IT职业 > IT生活 > 达达租车测试类,不足之处请指点
package test;
import java.util.Arrays;
public class Cars {
private String name;//汽车名
private int price;//价钱
private int peopleTotal;//载人量
private int cargo;//载货量
private String type;
public void msg(int i){}
public String[] getTypes() {
String[] types = {"passenger", "truck", "cargo"};
return types;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName(){
return this.name;
}
public void setName(String name){
this.name = name;
}
public int getPrice(){
return this.price;
}
public void setPrice(int price){
this.price = price;
}
public int getPeopleTotal(){
return this.peopleTotal;
}
public void setPeopleTotal(int peopleTotal){
this.peopleTotal = peopleTotal;
}
public int getCargo(){
return this.cargo;
}
public void setCargo(int cargo){
this.cargo = cargo;
}
}
package test;
public class passengerCar extends Cars{
public passengerCar(String name, int price, int peopleTotal) {
this.setName(name);
this.setPeopleTotal(peopleTotal);
this.setPrice(price);
this.setType("passenger");
}
public void msg(int i) {
String m = i+"t"+this.getName()+"t"+this.getPrice()+"元/天"+"tt"+"载人"+this.getPeopleTotal()+"个";
System.out.println(m);
} }
package test;
public class Truck extends Cars{
public Truck(String name, int price, int cargo) {
this.setName(name);
this.setCargo(cargo);
this.setPrice(price);
this.setType("truck");
}
public void msg(int i) {
String m = i+"t"+this.getName()+"t"+this.getPrice()+"元/天"+"tt"+"载货"+this.getCargo()+"kg";
System.out.println(m);
}
}
package test;
public class Cargo extends Cars{
public Cargo(String name, int price, int peopleTotal, int cargo) {
this.setName(name);
this.setPeopleTotal(peopleTotal);
this.setPrice(price);
this.setCargo(cargo);
this.setType("cargo");
}
public void msg(int i) {
String m = i+"t"+this.getName()+"t"+this.getPrice()+"元/天"+"tt"+"载人"+this.getPeopleTotal()+"个"+"t"+"载货"+this.getCargo()+"kg";
System.out.println(m);
}
}
package test;
import java.util.Scanner;
/**
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1070/viewspace-2798027/ ,如需转载,请注明出处,否则将追究法律责任。