package com.dada;
//Vehicle父类
public abstract class Vehicle {
String name;
int pernum;
int weight;
int rent;
public abstract void method();
}
package com.dada;
//载货Truck类
public class Truck extends Vehicle{
public void method(){
System.out.println(name+'\t'+rent+"/天\t"+"载重:"+weight+"吨");
}
}
package com.dada;
//载客Car类
public class Car extends Vehicle {
public void method(){
System.out.println(name+'\t'+rent+"/天\t"+"载人:"+pernum+"人");
}
}
package com.dada;
//载货载客Other类
public class Other extends Vehicle{
public void method(){
System.out.println(name+'\t'+rent+"/天\t"+"载人:"+pernum+"人"+"载重:"+weight+"吨");
}
}
package com.dada;
import java.util.Scanner;
//Initial测试类
public class Initial {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Vehicle car1=new Car();
Vehicle car2=new Car();
Vehicle car3=new Car();
Vehicle truck1=new Truck();
Vehicle truck2=new Truck();
Vehicle other=new Other();
car1.name="奥迪A4";
car1.pernum=4;
car1.rent=500;
car2.name="马自达6";
car2.pernum=4;
car2.rent=400;
car3.name="金龙";
car3.pernum=20;
car3.rent=800;
truck1.name="松花江";
truck1.weight=4;
truck1.rent=400;
truck2.name="依维柯";
truck2.weight=20;
truck2.rent=1000;
other.name="皮卡雪6";
other.pernum=4;
other.weight=2;
other.rent=450;
System.out.println("欢迎使用租车系统:\n您是否要租车:1 是 0否");
Scanner input=new Scanner(System.in);
int p=input.nextInt();
if(p==1){
System.out.println("您可租车的类型及价目表:\n序号\t汽车名称\t租金 \t容量");
System.out.print("1\t");car1.method();
System.out.print("2\t");car2.method();
System.out.print("3\t");car3.method();
System.out.print("4\t");other.method();
System.out.print("5\t");truck1.method();
System.out.print("6\t");truck2.method();
}else{
System.exit(0);
}
System.out.println("请输入您要租车的数量:");
int carNum=input.nextInt();
int a=0,b=0,c=0,d=0,e=0,f=0;
for(int i=1;i<=carNum;i++){
System.out.println("请输入第"+i+"量车的序号:");
int N=input.nextInt();
if(N==1){
a=a+1;
}
if(N==2){
b=b+1;
}
if(N==3){
c=c+1;
}
if(N==4){
d=d+1;
}
if(N==5){
e=e+1;
}
if(N==6){
f=f+1;
}
}
int totalPerNum=car1.pernum*a+car2.pernum*b+car3.pernum*c+other.pernum*d;
int totalWeight=other.weight*d+truck1.weight*e+truck2.weight*f;
int totalRent=car1.rent*a+car2.rent*b+car3.rent*c+other.rent*d+truck1.rent*e+truck2.rent*f;
System.out.println("请输入您要租车的天数:");
int dayNum=input.nextInt();
System.out.println("您的账单:");
System.out.println("***可载人的车有:");
if(a!=0){
System.out.print(car1.name+'\t');
}
if(b!=0){
System.out.print(car2.name+'\t');
}
if(c!=0){
System.out.print(car3.name+'\t');
}
if(d!=0){
System.out.print(other.name+'\t');
}
System.out.println("共载人:"+totalPerNum+"人");
System.out.println("***可载货的车有:");
if(d!=0){
System.out.print(other.name+'\t');
}
if(e!=0){
System.out.print(truck1.name+'\t');
}
if(f!=0){
System.out.print(truck2.name+'\t');
}
System.out.println("共载货:"+totalWeight+"吨");
System.out.println("总租金:"+totalRent*dayNum+"元");
}
}
点击查看更多内容
15人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦