//抽象类
public abstract class car {
private String name;//类型
private int manned;//载客量
private int cargo;//载货量
private int price;//价格
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public int getManned(){
return manned;
}
public void setManned(int manned){
this.manned=manned;
}
public int getCargo(){
return cargo;
}
public void setCargo(int cargo){
this.cargo=cargo;
}
public int getPrice(){
return price;
}
public void setPrice(int price){
this.price=price;
}
public abstract void getic();
}
//货车类
public class carhc extends car {
@Override
public void getic() {
// TODO Auto-generated method stub
System.out.println(getName()+"\t"+getPrice()+"元/天"+"\t"+getCargo()+"吨"+"\t");
}
public carhc(String carName,int carCargo,int carPrice){
this.setName(carName);
this.setCargo(carCargo);
this.setPrice(carPrice);
}
}
//客车类
public class carkc extends car {
@Override
public void getic() {
// TODO Auto-generated method stub
System.out.println(getName()+"\t"+getPrice()+"元/天"+"\t"+getManned()+"人"+"\t");
}
public carkc(String carName,int carManned,int carPrice){
this.setName(carName);
this.setManned(carManned);
this.setPrice(carPrice);
}
}
皮卡车类
public class carpk extends car {
@Override
public void getic() {
// TODO Auto-generated method stub
System.out.println(getName()+"\t"+getPrice()+"元/天"+"\t"+getManned()+"人"+"\t"+getCargo()+"吨"+"\t");
}
public carpk(String carName,int carManned,int carCargo,int carPrice){
this.setName(carName);
this.setManned(carManned);
this.setCargo(carCargo);
this.setPrice(carPrice);
}
}
import java.util.Scanner;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
car[] cars={
new carhc("东风天锦",20,1200),
new carhc("松花江",6,600),
new carkc("奥迪A8",4,800),
new carkc("E7团体",23,900),
new carpk("丰田皮卡",4,1,400),
new carpk("长城皮卡",4,3,600)
};
System.out.println("欢迎使用哒哒租车系统\n您是否租车:1是 0否");
Scanner input=new Scanner(System.in);
if(input.nextInt()==1){
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号"+"\t"+"汽车名称"+"\t"+"租金"+"\t"+"载人/载货");
for(int i=0;i<cars.length;i++){
System.out.print(i+"\t");
cars[i].getic();
}
System.out.println("请选择租车数量");
int score =input.nextInt();
car[] cars2=new car[score];
int[] days=new int[score];
int sum=0;
int rs=0;
int t=0;
for(int i=0;i<score;i++){
System.out.println("请输入第"+(i+1)+"辆车序号");
cars2[i]=cars[input.nextInt()];
System.out.println("请输入租借天数");
days[i]=input.nextInt();
}
System.out.println("------清单------");
System.out.println("可载人的车有:");
for(int i=0;i<score;i++){
if(cars2[i].getManned()>0){
System.out.print(cars2[i].getName()+"/"+days[i]+"天 ");
}
rs+=cars2[i].getManned();
}
System.out.println("共载人:"+rs+"人");
System.out.println("可载货的车有");
for(int i=0;i<score;i++){
if(cars2[i].getCargo()>0){
System.out.print(cars2[i].getName()+"/"+days[i]+"天 ");
}
t+=cars2[i].getCargo();
sum+=cars2[i].getPrice()*days[i];
}
System.out.println("共载货:"+t+"吨");
System.out.println("总价格:"+sum);
}else{
System.exit(0);
}
}
}