package ddrentcar;
public class Car {
private String carName;//车辆的名称
private double price;//租用价格
private int busLoad;//载客量
private double cargo;//载货量
public String getCarName(){
return carName;
}
public void setCarName(String carName){
this.carName=carName;
}
public double getPrice(){
return price;
}
public void setPrice(double price){
this.price=price;
}
public int getBusLoad(){
return busLoad;
}
public void setBusLoad(int busLoad){
this.busLoad=busLoad;
}
public double getCargo(){
return cargo;
}
public void setCargo(double cargo){
this.cargo=cargo;
}
}
package ddrentcar;
public class Passengercar extends Car {
public Passengercar(String carName,double price,int busLoad,double cargo){
this.setCarName(carName);
this.setPrice(price);
this.setBusLoad(busLoad);
this.setCargo(cargo);
}
}
package ddrentcar;
public class Trunk extends Car {
public Trunk(String carName,double price,int busLoad,double cargo){
this.setCarName(carName);
this.setPrice(price);
this.setBusLoad(busLoad);
this.setCargo(cargo);
}
}
package ddrentcar;
public class Pickup extends Car {
public Pickup(String carName,double price,int busLoad,double cargo){
this.setCarName(carName);
this.setPrice(price);
this.setBusLoad(busLoad);
this.setCargo(cargo);
}
}
package ddrentcar;
import java.util.Scanner;
public class Initial {
private static Scanner input=new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method stub
Car[] carForRent={new Passengercar("奥迪A4",500,4,0),new Passengercar("马自达6",400,4,0),new Pickup("皮卡雪6",450,4,2),new Passengercar("金龙",800,20,0),new Trunk("依维柯",1000,0,20),new Trunk("松花江",400,0,4)};
while(true){
System.out.println("欢迎使用答答租车系统:您是否需要租车:1是 0否");
try{
int choose=inputCommand();
switch(choose){
case 1:
System.out.println("您可租车类型及价目表");
System.out.println("序号"+"\t"+"汽车名称"+"\t"+"租金"+"\t"+"载客量"+"\t"+"载货量");
for(int i=0;i<carForRent.length;i++){
System.out.println((i+1)+"\t"+carForRent[i].getCarName()+"\t"+carForRent[i].getPrice()+"\t"+carForRent[i].getBusLoad()+"\t"+carForRent[i].getCargo());
}
System.out.println("请输入您需要租车的数量:");
//Scanner input2=new Scanner(System.in);
int carNum=input.nextInt();//租车数量
double[] eachKindPrice=new double[6];//所租用的每种类型车的单日总租金
for(int i=0;i<carForRent.length;i++){
System.out.println("请依次输入您所需的第"+(i+1)+"号车数量");
//Scanner input3=new Scanner(System.in);
int num=input.nextInt();
eachKindPrice[i]=num*carForRent[i].getPrice();
}
System.out.println("请输入租车天数:");
//Scanner input4=new Scanner(System.in);
int days=input.nextInt();
double[] dailyPrice=new double[6];//单日总租金
double totalPrice=0;//总租金
System.out.println("您的账单为:");
for(int i=0;i<6;i++){
dailyPrice[i]=days*eachKindPrice[i];
System.out.println("租第"+(i+1)+"号车的费用为:"+dailyPrice[i]+"元");
totalPrice+=dailyPrice[i];
}
System.out.println("总租金为:"+totalPrice+"元");
break;
case 0:
System.out.println("感谢你的访问");
break;
case -1:
System.out.println("输入错误,请按照提示输入");
continue;
default:
System.out.println("输入错误,请按照提示输入");
continue;
}break;
}catch(Exception ss){
System.out.println(ss.getMessage());
continue;
}
}
}
private static int inputCommand(){
try{
int command=input.nextInt();
return command;
}catch(Exception e){
input=new Scanner(System.in);
return -1;
}
}
}
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦