//一个父类 Car
package com.imooc6;
public abstract class Car {
public abstract void setInforation(String name,int monry,int ren,int wu);
public abstract String getName();
public abstract int getMonry();
public abstract int getRan();
public abstract int getWu();
// TODO Auto-generated method stub
}
//六个子类 ,分别是六种车
public class Aodi extends Car {
private int monry;
private String name;
private int ren;
private int wu;
@Override
public void setInforation( String name,int monry, int ren,int wu) {
// TODO Auto-generated method stub
this.monry=monry;
this.name=name;
this.ren=ren;
this.wu=wu;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return name;
}
@Override
public int getMonry() {
// TODO Auto-generated method stub
return monry;
}
@Override
public int getRan() {
// TODO Auto-generated method stub
return ren;
}
@Override
public int getWu() {
// TODO Auto-generated method stub
return wu;
}
}
//////////////////////////////////////
public class Jinglong extends Car {
private int monry;
private String name;
private int ren;
private int wu;
@Override
public void setInforation(String name,int monry, int ren,int wu){
// TODO Auto-generated method stub
this.monry=monry;
this.name=name;
this.ren=ren;
this.wu=wu;
}
public String getName() {
// TODO Auto-generated method stub
return name;
}
@Override
public int getMonry() {
// TODO Auto-generated method stub
return monry;
}
@Override
public int getRan() {
// TODO Auto-generated method stub
return ren;
}
@Override
public int getWu() {
// TODO Auto-generated method stub
return wu;
}
}
///////////////////////////
public class Mazida extends Car {
private int monry;
private String name;
private int ren;
private int wu;
@Override
public void setInforation(String name, int monry,int ren,int wu) {
// TODO Auto-generated method stub
this.monry=monry;
this.name=name;
this.ren=ren;
this.wu=wu;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return name;
}
@Override
public int getMonry() {
// TODO Auto-generated method stub
return monry;
}
@Override
public int getRan() {
// TODO Auto-generated method stub
return ren;
}
@Override
public int getWu() {
// TODO Auto-generated method stub
return wu;
}
}
////////////////////////////
public class Pika extends Car {
private int monry;
private String name;
private int ren;
private int wu;
@Override
public void setInforation(String name, int monry,int ren,int wu) {
// TODO Auto-generated method stub
this.monry=monry;
this.name=name;
this.ren=ren;
this.wu=wu;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return name;
}
@Override
public int getMonry() {
// TODO Auto-generated method stub
return monry;
}
@Override
public int getRan() {
// TODO Auto-generated method stub
return ren;
}
@Override
public int getWu() {
// TODO Auto-generated method stub
return wu;
}
}
//////////////////////////////
public class Songhuajiang extends Car {
private int monry;
private String name;
private int ren;
private int wu;
@Override
public void setInforation(String name,int monry, int ren,int wu) {
// TODO Auto-generated method stub
this.monry=monry;
this.name=name;
this.ren=ren;
this.wu=wu;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return name;
}
@Override
public int getMonry() {
// TODO Auto-generated method stub
return monry;
}
@Override
public int getRan() {
// TODO Auto-generated method stub
return ren;
}
@Override
public int getWu() {
// TODO Auto-generated method stub
return wu;
}
}
//////////////////////
public class Yiweike extends Car {
private int monry;
private String name;
private int ren;
private int wu;
@Override
public void setInforation(String name, int monry,int ren,int wu) {
// TODO Auto-generated method stub
this.monry=monry;
this.name=name;
this.ren=ren;
this.wu=wu;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return name;
}
@Override
public int getMonry() {
// TODO Auto-generated method stub
return monry;
}
@Override
public int getRan() {
// TODO Auto-generated method stub
return ren;
}
@Override
public int getWu() {
// TODO Auto-generated method stub
return wu;
}
}
//一个测试类
public class test {
public static void main(String[] args) {
// TODO Auto-generated method
Car obj1=new Aodi();
obj1.setInforation("奥迪A4", 500, 4,0);
Car obj2=new Jinglong();
obj2.setInforation("金龙", 800, 20,0);
Car obj3=new Mazida();
obj3.setInforation("马自达6", 400, 4,0);
Car obj4=new Pika();
obj4.setInforation("皮卡雪6", 450, 4,2);
Car obj5=new Songhuajiang();
obj5.setInforation("松花江", 400, 0,4);
Car obj6=new Yiweike();
obj6.setInforation("依维柯", 1000, 0,20);
Car[]car={obj1,obj2,obj3,obj4,obj5,obj6};
Scanner input=new Scanner(System.in);
System.out.println("欢迎使用答答租车系统");
System.out.print("您是否要租车:1是0否");
int a=input.nextInt();
if(a==1){
System.out.println("序号\t汽车名称\t租金\t\t容量");
for(int i=0;i<2;i++){
System.out.println(i+1+"\t"+car[i].getName()+"\t"+car[i].getMonry()+"/天"+"\t\t"+car[i].getRan()+"人");
}
for(int j=3;j<4;j++){
System.out.println(j+1+"\t"+car[j].getName()+"\t"+car[j].getMonry()+"/天"+"\t\t"+car[j].getRan()+"人"+car[j].getWu()+"吨");
}
for(int k=4;k<6;k++){
System.out.println(k+1+"\t"+car[k].getName()+"\t"+car[k].getMonry()+"/天"+"\t\t"+car[k].getWu()+"吨");
}
System.out.print("请输入你要租车的数量");
int b=input.nextInt();
Car [] carChiose=new Car[b];//定义一个数组
for(int l=1;l<=b;l++){
System.out.println("请输入第"+l+"辆车的序号");
int c=input.nextInt();
carChiose[l-1]=car[c-1];
}
System.out.println("请输入租车天数");
int d=input.nextInt();
System.out.println("您的账单;");
int sum=0;
int sum1=0;
int sum3=0;
for(int i=0;i<carChiose.length;i++){
if(carChiose[i].equals(obj1)||carChiose.equals(obj2)||carChiose[i].equals(obj3)||carChiose[i].equals(obj4)){
sum+=carChiose[i].getRan();
sum3+=carChiose[i].getMonry()*d;
}
if(carChiose[i].equals(obj4)||carChiose[i].equals(obj5)||carChiose[i].equals(obj6)){
sum1+=carChiose[i].getWu();
sum3+=carChiose[i].getMonry()*d;
}
}
System.out.println("可以载人的车有");
for(int i=0;i<carChiose.length;i++){
if(carChiose[i].equals(obj1)||carChiose[i].equals(obj2)||carChiose.equals(obj3)||carChiose.equals(obj4)){
System.out.println(carChiose[i].getName());
}
}
System.out.println("总载客人数为"+sum+"/人");
System.out.println("可载物的车有");
for(int i=0;i<carChiose.length;i++){
if(carChiose[i].equals(obj4)||carChiose[i].equals(obj5)||carChiose.equals(obj6)){
System.out.println(carChiose[i].getName());
}
}
System.out.println("总载物吨数为"+sum1+"/吨");
System.out.println("需要支付的金钱为"+sum3+"元");
}else if(a==0){
System.out.println("谢谢使用");
}else{
System.out.println("输入错误你个傻逼");
}
}
新人 求大神们清点打脸
vone
相关分类