package com.demo;
import java.util.Scanner;
import java.util.Arrays;
public class Initial {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("******欢迎使用嗒嗒租车系统******");
System.out.println("您是否要租车:1是 非1否");
Scanner input=new Scanner(System.in);
int num=input.nextInt();
if(num==1){
System.out.println("您可租车的类型及价目表:");
System.out.println("序号 汽车名称 租金 容量");
System.out.println("1. 奥迪A4 500元/天 载人:4人");
System.out.println("2. 马自达6 400元/天 载人:4人");
System.out.println("3. 皮卡雪6 450元/天 载人:4人,载货:2吨");
System.out.println("4. 金龙 800元/天 载人:20人");
System.out.println("5. 松花江 400元/天 载货:4吨");
System.out.println("6. 依维柯 1000元/天 载人:20吨");
System.out.println("请输入要租车的数量:");
int cheshu=input.nextInt();
Manned aodi=new Aodi();
Manned mazida=new Mazida();
Manned jinlong=new Jinlong();
Manned pika=new Pika();
Carry songhua=new Songhua();
Carry yiwei=new Yiwei();
String[] allName=new String[cheshu];
int allRent=0;
int allManned=0;
int allCarry=0;
int xuhao;
for(int i=1;i<=cheshu;i++){
System.out.println("请输入第"+i+"辆车的序号");
xuhao=input.nextInt();
switch(xuhao){
case 1:
System.out.println("您选择的是"+aodi.getName());
System.out.println();
allName[i-1]=aodi.getName();
allRent+=aodi.getRent();
allManned+=aodi.getManned();
allCarry+=aodi.getCarry();
break;
case 2:
System.out.println("您选择的是"+mazida.getName());
System.out.println();
allName[i-1]=mazida.getName();
allRent+=mazida.getRent();
allManned+=mazida.getManned();
allCarry+=mazida.getCarry();
break;
case 3:
System.out.println("您选择的是"+pika.getName());
System.out.println();
allName[i-1]=pika.getName();
allRent+=pika.getRent();
allManned+=pika.getManned();
allCarry+=pika.getCarry();
break;
case 4:
System.out.println("您选择的是"+jinlong.getName());
System.out.println();
allName[i-1]=jinlong.getName();
allRent+=jinlong.getRent();
allManned+=jinlong.getManned();
allCarry+=jinlong.getCarry();
break;
case 5:
System.out.println("您选择的是"+songhua.getName());
System.out.println();
allName[i-1]=songhua.getName();
allRent+=songhua.getRent();
allManned+=songhua.getManned();
allCarry+=songhua.getCarry();
break;
case 6:
System.out.println("您选择的是"+yiwei.getName());
System.out.println();
allName[i-1]=yiwei.getName();
allRent+=yiwei.getRent();
allManned+=yiwei.getManned();
allCarry+=yiwei.getCarry();
break;
}
}
System.out.println("请输入租车天数");
int day=input.nextInt();
int cost=allRent*day;
System.out.println("******您的总账单******");
System.out.println("您所需要的车为:"+Arrays.toString(allName));
System.out.println("总车数为:"+cheshu);
System.out.println("租车天数为:"+day);
System.out.println("总金额为:"+cost+"元 载人总数:"+allManned+"人 载客总量:"+allCarry+"吨");
}else{
System.out.println("欢迎下次使用嗒嗒租车系统!");
System.exit(0);
}
}
}
package com.demo;
public abstract class Manned {
public abstract String getName();
public abstract int getRent();
public abstract int getManned();
public abstract int getCarry();
}
package com.demo;
public interface Carry {
public String getName();
public int getRent();
public int getManned();
public int getCarry();
}
package com.demo;
public class Aodi extends Manned {
private String name="奥迪A4";
private int rent=500;
private int manned=4;
private int carry=0;
public String getName() {
return name;
}
public int getRent() {
return rent;
}
public int getManned() {
return manned;
}
public int getCarry() {
return carry;
}
}
package com.demo;
public class Mazida extends Manned {
private String name="马自达6";
private int rent=400;
private int manned=4;
private int carry=0;
public String getName() {
return name;
}
public int getRent() {
return rent;
}
public int getManned() {
return manned;
}
public int getCarry() {
return carry;
}
}
package com.demo;
public class Pika extends Manned implements Carry{
private String name="皮卡雪6";
private int rent=450;
private int manned=4;
private int carry=2;
public String getName() {
return name;
}
public int getRent() {
return rent;
}
public int getManned() {
return manned;
}
public int getCarry() {
return carry;
}
}
package com.demo;
public class Songhua implements Carry {
private String name="松花江";
private int rent=400;
private int manned=0;
private int carry=4;
public String getName() {
return name;
}
public int getRent() {
return rent;
}
public int getManned() {
return manned;
}
public int getCarry() {
return carry;
}
}
package com.demo;
public class Yiwei implements Carry {
private String name="依维柯";
private int rent=1000;
private int manned=0;
private int carry=20;
public String getName() {
return name;
}
public int getRent() {
return rent;
}
public int getManned() {
return manned;
}
public int getCarry() {
return carry;
}
}
package com.demo;
public class Jinlong extends Manned {
private String name="金龙";
private int rent=800;
private int manned=20;
private int carry=0;
public String getName() {
return name;
}
public int getRent() {
return rent;
}
public int getManned() {
return manned;
}
public int getCarry() {
return carry;
}
}
显示结果如图:
热门评论
赞 虽然不是java小白能做出来的东西 但是让我看到前方