自己写的,求大神指点
父类
package com.java_9;
public abstract class ZongChe {
public String name;//名字
public int xulie;//序号
public double money;//钱数
public ZongChe(int xulie,String name,double money){
this.name=name;
this.money=money;
this.xulie=xulie;
}
public void xinxi(){
System.out.println(xulie+"\t"+name+"\t"+money+"元/天");
}
}
货车子类
package com.java_9;
public class HuoChe extends ZongChe{
public int zaihuo;//载货量
public HuoChe(int xulie,String name,double money,int zaihuo){
super(xulie,name,money);
this.zaihuo=zaihuo;
}
public void xinxi(){
System.out.println(xulie+"\t"+name+"\t"+money+"元/天\t载货"+zaihuo+"吨");
}
}
客车子类
package com.java_9;
public class KeChe extends ZongChe{
public int zaike;//载人数
public KeChe(int xulie,String name,double money,int zaike){
super(xulie,name,money);
this.zaike=zaike;
}
public void xinxi(){
System.out.println(xulie+"\t"+name+"\t"+money+"元/天\t载客"+zaike+"人");
}
}
皮卡子类
package com.java_9;
public class PiKa extends ZongChe{
public int pihuo;
public int pike;
public PiKa(int xulie,String name,double money,int pihuo,int pike){
super(xulie,name,money);
this.pihuo=pihuo;
this.pike=pike;
}
public void xinxi(){
System.out.println(xulie+"\t"+name+"\t"+money+"元/天\t 载客"+pike+"人\t载货"+pihuo+"吨");
}
}
管理类和测试类
package com.java_9;
import java.util.Scanner;
public class ZongLei {
public ZongChe z;
public void arr(ZongChe z){
this.z=z;
}
public void ass(){
z.xinxi();
}
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
ZongLei zong=new ZongLei();
ZongChe[] shu=new ZongChe[6];
shu[0]=(new HuoChe(1,"小货车",600,6));
shu[1]=(new HuoChe(2,"中货车",900,10));
shu[2]=(new KeChe(3,"小客车",500,5));
shu[3]=(new KeChe(4,"中客车",800,7));
shu[4]=(new KeChe(5,"大客车",1200,20));
shu[5]=(new PiKa(6,"福特皮卡",800,4,4));
System.out.println("欢迎使用滴滴租车系统:");
System.out.println("是否要租车:(1是 0否)");
int a=input.nextInt();
if(a==1){
System.out.println("您可租车价目表:");
System.out.println("序号\t汽车名称\t租金\t\t容量");
for(int i=0;i<shu.length;i++){
zong.arr(shu[i]);
zong.ass();
}
System.out.println("请输入你要租车的数量:");
int b=input.nextInt();
ZongChe[] shu2=new ZongChe[b];
for(int j=0;j<b;j++){
System.out.println("请输入第"+(j+1)+"辆车的序号:");
int c=input.nextInt();
shu2[j]=shu[c-1];
}
System.out.println("请输入租车天数:");
int d=input.nextInt();
System.out.println("您的账单有:");
System.out.println("**********载人车有:");
int ren=0;
for(ZongChe f:shu2){
if(f.xulie==3||f.xulie==4||f.xulie==5){
System.out.print(f.name+" ");
ren+=((KeChe)f).zaike;
}else if(f.xulie==6){
System.out.print(f.name+" ");
ren+=((PiKa)f).pike;
}
}
System.out.print("总载客数是:"+ren);
System.out.println("\n**********载货车有:");
int huo=0;
for(ZongChe s:shu2){
if(s.xulie==1||s.xulie==2){
System.out.print(s.name+" ");
huo+=((HuoChe)s).zaihuo;
}else if(s.xulie==6){
System.out.print(s.name+" ");
huo+=((PiKa)s).pihuo;
}
}
System.out.print("载货总重:"+huo+"吨");
double qian=0;
for(ZongChe a1:shu2){
qian+=a1.money;
}
qian=qian*d;
System.out.print("\n*****租车总金额:"+qian);
}else{
System.out.println("再见");
}
}
}