package javahhh;
public class Car {
public String name;
public int money;
public int people;
public int huowu;
}
package javahhh;
public class Dache extends Car {
public Dache(String name,int money,int huowu){
this.name = name;
this.money = money;
this.huowu = huowu;
}
@Override
public String toString() {
return "大挂车 [名称=" + name + ", 金钱=" + money +"/天"+ ", 载货=" + huowu+"吨"
+ "]";
}
}
package javahhh;
public class Pika extends Car {
public Pika(String name,int money,int people,int huowu){
this.name = name;
this.money = money;
this.people = people;
this.huowu = huowu;
}
@Override
public String toString() {
return "皮卡 [名称=" + name + ", 金钱=" + money +"/天"+ ", 载人=" + people +",载货="+huowu+"吨"
+ "]";
}
}
package javahhh;
public class Xiaoche extends Car {
public Xiaoche(String name,int money,int people){
this.name = name;
this.money = money;
this.people = people;
}
@Override
public String toString() {
return "小车 [名称=" + name + ", 金钱=" + money +"/天"+ ", 载人=" + people
+ "]";
}
}
package javahhh;
import java.util.Scanner;
public class ceshi {
static Scanner scanner = new Scanner(System.in);
static Car car[] = {new Xiaoche("奥迪", 500, 5),new Xiaoche("马自达", 400, 5),
new Pika("皮卡", 450, 2, 2),new Dache("五十铃", 600, 6),new Dache("大挂车", 100, 20)};
public static void main(String[] args) {
// TODO Auto-generated method stub
ceshi cs = new ceshi();
System.out.println("你是否需要租车?1.是,2否");
int select = scanner.nextInt();
if (select == 2) {
scanner.close();
System.out.println("谢谢你的光临");
System.exit(-1);
}
System.out.println("你可租车的类型如下");
System.out.println("序号 汽车名称 租金 容量");
System.out.println(" 1 奥迪 500/天 5人");
System.out.println(" 2 马自达 400/天 5人");
System.out.println(" 3 皮卡 450/天 5人");
System.out.println(" 4 五十铃 600/天 5人");
System.out.println(" 5 大挂车 1000/天 5人");
int xz = scanner.nextInt();
if (xz>0&&xz<car.length) {
System.out.println("你要租用的车是"+xz+car[xz-1]);
}else {
System.err.println("你输入有误");
}
System.out.println("你需要租用几天");
int tianshu = scanner.nextInt();
System.out.println("你租用的车"+car[xz-1]+"租用的天数是"+tianshu+"总金额"+car[xz-1].money*tianshu);
}
}