package com.chen1;
import java.util.Scanner;
public class Demo2 {
public static void main(String[] args) {
//创建可租车列表
Car[] carsForRent={new PassengerCar("奥迪A4",500,4),new PassengerCar("马自达6",400,4),
new PassengerCar("金龙",800,20),new Pickup("皮卡雪",450,2,4),
new Trunk("松花江",400,4),new Trunk("大阿肥",1000,20)};
System.out.println("欢迎使用达达租车系统");
System.out.println("您是否需要租车:1 是 \t其他任意键 否");
//获取并保存输入的值(一或者其他任意键)
Scanner scan=new Scanner(System.in);
String input=scan.next();
//判断是否进入租车系统
if(input.equals("1")){
System.out.println("你可租车类型及价目表");
System.out.println("序号\t汽车名称\t租金 \t 容量");
int i=0;
for(Car currentCar:carsForRent){
//用instancreof判断是否属于汽车子类
if(currentCar instanceof PassengerCar){
i++;
System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRent()+"元/天\t"+((PassengerCar)currentCar).getpeopleCapacity()+"人\t"
);}
if(currentCar instanceof Trunk){
i++;
System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRent()+"元/天\t"+((Trunk)currentCar).getcargoCapacity()+"吨\t");}
if(currentCar instanceof Pickup){
i++;
System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRent()+"元/天\t"+((Pickup)currentCar).getCargoCapacity()+"吨\t"
+((Pickup)currentCar).getPeopleCapacity()+"人\t");}
}
System.out.println("请输入您要租车的数量:");
//获取并保存输入的值(租车的数量)
Scanner inputnum=new Scanner(System.in);
int number=inputnum.nextInt();
// 输入每辆租车的序号
for(int j=1;j<=number;j++){
System.out.println("请输入第"+j+"台车的序号:");
Scanner inputnum1=new Scanner(System.in);
int number1=inputnum1.nextInt();
}
//输入租车天数
System.out.println("请输入租车天数:");
Scanner inputnum2=new Scanner(System.in);
int days=inputnum2.nextInt();
//租车账单
System.out.println("您的账单:");
double total=0;
Car car=new PassengerCar();
total=car.getRent()*days;
System.out.println("***租车总价格:"+total);
}
else {
System.out.println("您已退出达达租车系统!");
}
}
}
//汽车类
class Car{
//成员属性
String name;
double carCapacity;
double rent;
//获取名字
public String getName() {
return name;
}
//设定名字
public void setName(String name) {
this.name = name;
}
//获取汽车容量
public double getCarCapacity() {
return carCapacity;
}
//设定汽车容量
public void setCarCapacity(double carCapacity) {
this.carCapacity = carCapacity;
}
//获取租金
public double getRent() {
return rent;
}
//设定租金
public void setRent(double rent) {
this.rent = rent;
}
}
//子类卡车继承父类汽车
class Trunk extends Car{
//卡车容量属性封装
private double cargoCapacity;
// 构造方法 ,自动调用构造方法完成对新对象的初始化
public Trunk(String name,double rent,double cargoCapacity){
this.name=name;
this.rent=rent;
this.cargoCapacity=cargoCapacity;
}
//获取卡车载货容量
public double getcargoCapacity(){
return cargoCapacity;
}
}
//子类客车继承父类汽车
class PassengerCar extends Car{
//客车载入容量属性封装
private double peopleCapacity;
//构造方法,完成对新对象的属性初始化
public PassengerCar(String name,double rent,double peopleCapacity){
this.name=name;
this.rent=rent;
this.peopleCapacity=peopleCapacity;
}
//获取客车载入的容量
public double getpeopleCapacity(){
return peopleCapacity;
}
}
//子类
class Pickup extends Car{
private double cargoCapacity;
private double peopleCapacity;
public Pickup(String name,double rent,double cargoCapacity,double peopleCapacity){
this.name=name;
this.rent=rent;
this.cargoCapacity=cargoCapacity;
this.peopleCapacity=peopleCapacity;
}
public double getCargoCapacity() {
return cargoCapacity;
}
public double getPeopleCapacity() {
return peopleCapacity;
}
}
qq_82年的彬锅锅_03446807
qq_82年的彬锅锅_03446807
相关分类