//Car父类
package com.imooc;
public class Car {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private int pmoney;
private int pman;
private int phei;
public int getPmoney() {
return pmoney;
}
public void setPmoney(int pmoney) {
this.pmoney = pmoney;
}
public int getPman() {
return pman;
}
public void setPman(int pman) {
this.pman = pman;
}
public int getPhei() {
return phei;
}
public void setPhei(int phei) {
this.phei = phei;
}
public Car(String name,int pmoney,int Pman,int Phei){
this.name=name;
this.pmoney=pmoney;
this.pman=Pman;
this.phei=Phei;
}
}
//Aodi子类
package com.imooc;
public class Aodi extends Car {
public Aodi(String name,int pmoney, int Pman, int Phei) {
super(name,pmoney, Pman, Phei);
// TODO Auto-generated constructor stub
}
}
//Kinglong子类
package com.imooc;
public class Kinglong extends Car {
public Kinglong(String name,int pmoney, int Pman, int Phei) {
super(name,pmoney, Pman, Phei);
// TODO Auto-generated constructor stub
}
}
//Pick子类
package com.imooc;
public class Pick extends Car {
public Pick(String name,int pmoney, int Pman, int Phei) {
super(name,pmoney, Pman, Phei);
// TODO Auto-generated constructor stub
}
}
//Yiwei子类
package com.imooc;
public class Yiwei extends Car {
public Yiwei(String name,int pmoney, int Pman, int Phei) {
super(name,pmoney, Pman, Phei);
// TODO Auto-generated constructor stub
}
}
//test类
package com.imooc;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Car car1=new Aodi("奥迪",500,4,0);
Car car2=new Kinglong("金龙",800,20,0);
Car car3=new Pick(" 皮卡雪",450,4,2);
Car car4=new Yiwei(" 依维柯",1000,0,20);
@SuppressWarnings("resource")
Scanner input=new Scanner(System.in);
System.out.println("欢迎使用嗒嗒租车系统:"+ "\n"+"您是否要租车:1是 0否");
int write=input.nextInt();//获取用户输入信息并保存
if(write==1){
System.out.println("您可租车的类型及其价目表:"+"\n"+"序号 汽车名称 租金 载人量 载物量");
}
System.out.println("1 奥迪"+" "+car1.getPmoney()+"元/天 "+car1.getPman()+"人 ");
System.out.println("2 金龙"+" "+car2.getPmoney()+"元/天 "+car2.getPman()+"人 ");
System.out.println("3 皮卡雪"+" "+car3.getPmoney()+"元/天 "+car3.getPman()+"人 "+car3.getPhei()+"吨");
System.out.println("4 依维柯"+" "+car4.getPmoney()+"元/天 "+car4.getPhei()+"吨");
System.out.println("请输入您要租汽车的数量:");
int num=input.nextInt();
int[] carnum=new int[num];
for(int i=0;i<carnum.length;i++){
System.out.println("请输入第"+(i+1)+"辆车的序号:");
carnum[i]=input.nextInt();}
System.out.println("请输入您要租的天数:");
int day=input.nextInt();
int money=0;
int man=0;
int hei=0;
for(int i=0;i<carnum.length;i++){
if(carnum[i]==1){
money+=car1.getPmoney();
man+=car1.getPman();
}
else if(carnum[i]==2){
money+=car2.getPmoney();
man+=car2.getPman();
}
else if(carnum[i]==3){
money+=car3.getPmoney();
man+=car3.getPman();
hei+=car3.getPhei();
}
else if(carnum[i]==4){
money+=car4.getPmoney();
hei+=car4.getPhei();
}
}
money=money*day;
System.out.println("***可载人的车有:");
for(int i=0;i<carnum.length;i++){
if(carnum[i]==1)
System.out.print(car1.getName()+" ");
else if(carnum[i]==2)
System.out.print(car2.getName()+" ");
else if(carnum[i]==3)
System.out.print(car3.getName()+" ");
}
System.out.println("总载人:"+man);
System.out.println("***可载货的车有:");
for(int i=0;i<carnum.length;i++){
if(carnum[i]==4)
System.out.print(car4.getName()+" ");
else if(carnum[i]==3)
System.out.print(car3.getName()+" ");
}
System.out.println("总载货:"+hei);
System.out.println("***租车总价格:"+money);
}
}
点击查看更多内容
3人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦