package com.i;//父类,我这里的父类设置的不好
public class Didi {
private String name;//车名
private int ren;//车载人数
private int huo; //车载货物
private int rentn;//每辆车的租金
}
package com.i;
//为每个车型设置子类
public class Aodi extends Didi {
private String name;
private int rentn;
private int ren;
private int huo;
public Aodi(String name, int rentn, int ren) {
super();
this.name = name;
this.rentn = rentn;
this.ren = ren;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRen() {
return ren;
}
public void setRen(int ren) {
this.ren = ren;
}
public int getHuo() {
return huo;
}
public void setHuo(int huo) {
this.huo = huo;
}
public int getRentn() {
return rentn;
}
public void setRentn(int rentn) {
this.rentn = rentn;
}
}
package com.i;
public class Jinlong extends Didi {
private String name;
private int ren;
private int huo;
private int rentn;
public Jinlong(String name, int rentn, int ren) {
super();
this.name = name;
this.ren = ren;
this.rentn = rentn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRen() {
return ren;
}
public void setRen(int ren) {
this.ren = ren;
}
public int getHuo() {
return huo;
}
public void setHuo(int huo) {
this.huo = huo;
}
public int getRentn() {
return rentn;
}
public void setRentn(int rentn) {
this.rentn = rentn;
}
}
package com.i;
public class Mazida extends Didi {
private String name;
private int ren;
private int huo;
private int rentn;
public Mazida(String name, int rentn, int ren) {
super();
this.name = name;
this.rentn = rentn;
this.ren = ren;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRen() {
return ren;
}
public void setRen(int ren) {
this.ren = ren;
}
public int getHuo() {
return huo;
}
public void setHuo(int huo) {
this.huo = huo;
}
public int getRentn() {
return rentn;
}
public void setRentn(int rentn) {
this.rentn = rentn;
}
}
package com.i;
public class Pikaxue extends Didi {
private String name;
private int ren;
private int huo;
private int rentn;
public Pikaxue(String name, int rentn, int ren, int huo) {
super();
this.name = name;
this.ren = ren;
this.huo = huo;
this.rentn = rentn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRen() {
return ren;
}
public void setRen(int ren) {
this.ren = ren;
}
public int getHuo() {
return huo;
}
public void setHuo(int huo) {
this.huo = huo;
}
public int getRentn() {
return rentn;
}
public void setRentn(int rentn) {
this.rentn = rentn;
}
}
package com.i;
public class Songhuajiang extends Didi {
private String name;
private int ren;
private int huo;
private int rentn;
public Songhuajiang(String name, int rentn,int huo) {
super();
this.name = name;
this.huo = huo;
this.rentn = rentn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRen() {
return ren;
}
public void setRen(int ren) {
this.ren = ren;
}
public int getHuo() {
return huo;
}
public void setHuo(int huo) {
this.huo = huo;
}
public int getRentn() {
return rentn;
}
public void setRentn(int rentn) {
this.rentn = rentn;
}
}
package com.i;
public class Yiweike extends Didi {
private String name;
private int ren;
private int huo;
private int rentn;
public Yiweike(String name, int rentn,int huo) {
super();
this.name = name;
this.huo = huo;
this.rentn = rentn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRen() {
return ren;
}
public void setRen(int ren) {
this.ren = ren;
}
public int getHuo() {
return huo;
}
public void setHuo(int huo) {
this.huo = huo;
}
public int getRentn() {
return rentn;
}
public void setRentn(int rentn) {
this.rentn = rentn;
}
}
package com.i;//入口类。
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Go show=new Go();
System.out.println("请问您是否需要租车?"+"\n1是 0否");
do{
Scanner sc=new Scanner(System.in);
int sc1=sc.nextInt();
if(sc1==1){
show.Gohappy();
break;
}else if(sc1==0){
System.out.println("感谢您的使用,祝您生活愉快");
break;
}else{
System.out.println("输入错误,请重新输入");
continue;
}
}while(true);//这是借鉴幕友的,当输入错误的时候可以重新输入。
}
}
//Go功能实现类
package com.i;
import java.util.Arrays;
import java.util.Scanner;
public class Go {
public void Gohappy(){
Aodi a1=new Aodi(“奥迪A4”, 500,4);
Mazida a2=new Mazida(“马自达”,400,4);
Pikaxue a3=new Pikaxue(“皮雪卡”,450,4,2);
Jinlong a4=new Jinlong(“金龙”,800,20);
Songhuajiang a5=new Songhuajiang(“松花江”,400,4);
Yiweike a6=new Yiweike(“依维柯”,1000,20);
Didi car[]={a1,a2,a3,a4,a5,a6};
System.out.println("您可租车的类型及价目表:"+"\n序号 汽车名称 租金 容量");
System.out.println("1. "+a1.getName()+" "+a1.getRentn()+"元/天 "+"载人:"+a1.getRen()+"人");
System.out.println("2. "+a2.getName()+" "+a2.getRentn()+"元/天 "+"载人:"+a2.getRen()+"人");
System.out.println("3. "+a3.getName()+" "+a3.getRentn()+"元/天 "+"载人:"+a3.getRen()+"人"+"载货:"+a3.getHuo()+"吨");
System.out.println("4. "+a4.getName()+" "+a4.getRentn()+"元/天 "+"载人:"+a4.getRen()+"人");
System.out.println("5. "+a5.getName()+" "+a5.getRentn()+"元/天 "+"载货:"+a5.getHuo()+"吨");
System.out.println("6. "+a6.getName()+" "+a6.getRentn()+"元/天 "+"载货:"+a6.getHuo()+"吨");
System.out.println("请输入您要租汽车的数量:");
Scanner sc2=new Scanner(System.in);
int num=sc2.nextInt();
int sumMoney=0;//总价格
int dayMoney=0;//每天的价格
int sumHuo=0;//能载货的车的数量
int sumRen=0;//能载人的车的数量
int zairennum=0;//每辆车可以载人的数量
int zaihuonum=0;//每辆车可以载货的重量
String[] zairen=new String[num];//存放载人的车的车型名称
String[] zaihuo=new String[num];//存放可以载货的车的名称
for(int i=1;i<=num;i++){
System.out.println("请输入第"+i+"辆车的序号:");
Scanner sc3=new Scanner(System.in);
int n=sc3.nextInt();
if(n>=1&&n<=6){
switch(n){
case 1:
dayMoney+=a1.getRentn();
sumRen+=a1.getRen();
zairennum++;
zairen[zairennum-1]=a1.getName();
break;
case 2:
dayMoney+=a2.getRentn();
sumRen+=a2.getRen();
zairennum++;
zairen[zairennum-1]=a2.getName();
break;
case 3:
dayMoney+=a3.getRentn();
sumRen+=a3.getRen();
sumHuo+=a3.getHuo();
zairennum++;
zaihuonum++;
zairen[zairennum-1]=a3.getName();
zaihuo[zaihuonum-1]=a3.getName();
break;
case 4:
dayMoney+=a4.getRentn();
sumRen+=a4.getRen();
zairennum++;
zairen[zairennum-1]=a4.getName();
break;
case 5:
dayMoney+=a5.getRentn();
sumRen+=a5.getHuo();
zaihuonum++;
zaihuo[zaihuonum-1]=a5.getName();
break;
case 6:
dayMoney+=a6.getRentn();
sumRen+=a6.getHuo();
zaihuonum++;
zaihuo[zaihuonum-1]=a6.getName();
break;
}
}
}
System.out.println("请输入租车天数:");
Scanner sc4=new Scanner(System.in);
int daynum=sc4.nextInt();
sumMoney=dayMoney*daynum;
System.out.println("您的账单:");
System.out.println("***可载人的车有:");
for(String haha:zairen){
if(haha==null){continue;}else{
System.out.print(haha+" ");}
}
System.out.print(" 共载人:"+sumRen+"人");
System.out.println();
System.out.println("***载货的车有:");
for(String hana:zaihuo){
if(hana==null){continue;}else{
System.out.print(hana+" ");}
}
System.out.println(" 共载货:"+sumHuo+"吨");
System.out.println("总价格为:"+sumMoney+"元");
}
}