//main入口
import java.util.Scanner;
public class Rukou {
static Che c[]= {new Zairen("大众",300,4),new Zairen("雪铁龙",300,4),new Zairen("蝙蝠车",90000,1),new Zairen("高达",8000000,2),
new Zaihuo("小型卡车",3000,60),new Zaihuo("中型卡车",5000,100),new Zaihuo("重型卡车",9000,300),
new Zairh("皮卡",400,4,0.5),new Zairh("轮船",600000,200,1000),new Zairh("飞机",700000,300,6000),new Zairh("火车",800000,6000,80000)
};
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
System.out.println("欢迎登陆租车程序"+"\n"+"确定租车(1)还是不足租车(2)");
int k=in.nextInt();
if(k==1) {
System.out.println("以下为租车列表");
System.out.println("序号"+"\t"+"车名"+"\t"+"租金"+"\t"+"\t"+"作用");
for (int i=0,q=1;i<=c.length-1;++i,++q) {
System.out.println(q+c[i].sd()+c[i].toString());
}
System.out.println("请问你要租几辆车");
int qa=in.nextInt();
int b=0;
int zx[]=new int[qa];
while(b<qa) {
try {
System.out.println("请输入第"+(b+1)+"辆车的序号");
zx[b]=in.nextInt();
++b;
}catch(Exception e) {
System.out.println("输入错误请重新输入");
}
}
int zc[]=new int[zx.length];
int h=0;
int j=1;
for(int g:zx) {
System.out.println("第"+j+"辆车:"+c[g-1].getK()+"需要租几天");
zc[h]=in.nextInt();
++h;
++j;
}
System.out.println("------"+"以下是您的账单"+"------");
System.out.println("序号"+"\t"+"车名"+"\t"+"已租天数"+"\t"+"单价/1天"+"\t"+"\t"+"总金额"+"\t"+"作用");
double y=0;
for(int g=0;g<zx.length;++g) {
System.out.println((g+1)+"\t"+c[(zx[g]-1)].getK()+"\t"+zc[g]+"天"+"\t"+c[(zx[g]-1)].getJg()+"/1天"+"\t"+"\t"+(c[(zx[g])-1].getJg()*zc[g])+c[(zx[g]-1)].toString());
y=y+(c[(zx[g]-1)].getJg()*zc[g]);
}
System.out.println("\t"+("\t")+"\t"+"\t"+"\t"+"\t"+"需付款总计:"+y+"元");
}else if(k==2||k>2){
System.out.println("不租车你点个鸡儿");
}
}
}
//父 类
public abstract class Che {
private String k;
private int sl;
private double zl;
public int getSl() {
return sl;
}
public double getZl() {
return zl;
}
public void setSl(int sl) {
this.sl = sl;
}
public void setZl(double zl) {
this.zl = zl;
}
public String getK() {
return k;
}
public int getJg() {
return jg;
}
private int jg;
public Che(String k,int jg) {
this.k=k;
this.jg=jg;
}
/*
public String hzh() {
return k+kg+ jg+"/1天" + kg +"载货:"+zl+"吨" ;
}
public void seth(String k,int jg,double zl) {
this.k = k;
this.jg=jg;
this.zl=zl;
}
public String getK() {
return k+kg+ jg+"/1天" + kg +"载人:"+sl+"人" ;
}
public void setr(String k,int jg,int sl) {
this.k = k;
this.jg=jg;
this.sl=sl;
}
*/
public void setK(String k) {
this.k = k;
}
public String sd() {
return "\t"+k+"\t"+ jg+"/1天" ;
}
public abstract String toString();
public void setJg(int jg) {
this.jg = jg;
}
}
//子类Zaihuo
public class Zaihuo extends Che implements Zaizhong{
private double zl;
Zaihuo(String k,int jg,double zl){
super(k,jg);
this.zl=zl;
}
@Override
public String toString() {
return "\t" +"载货:"+zl+"吨" ;
}
@Override
public void zl(double zl) {
// TODO Auto-generated method stub
this.zl=zl;
}
@Override
public double zhfh() {
// TODO Auto-generated method stub
return zl ;
}
}
//子类Zairen
public class Zairen extends Che implements JIekou {
private int sl;
Zairen(String k,int jg,int sl){
super(k,jg);
this.sl=sl;
}
@Override
public String toString() {
return "\t"+"载人:"+sl+"人" ;
}
@Override
public void sl(int sl) {
// TODO Auto-generated method stub
this.sl=sl;
}
@Override
public int zrfh() {
// TODO Auto-generated method stub
return sl;
}
}
//子类Zairh
public class Zairh extends Che implements JIekou,Zaizhong{
private int sl;
private double zl;
Zairh(String k,int jg,int sl,double zl){
super(k,jg);
this.sl=sl;
this.zl=zl;
}
@Override
public String toString() {
return "\t"+"载人:"+sl+"人" +"载重:"+zl+"吨";
}
@Override
public void zl(double zl) {
// TODO Auto-generated method stub
this.zl=zl;
}
@Override
public double zhfh() {
// TODO Auto-generated method stub
return zl;
}
@Override
public void sl(int sl) {
// TODO Auto-generated method stub
this.sl=sl;
}
@Override
public int zrfh() {
// TODO Auto-generated method stub
return sl;
}
}
//接口 JIekou
public interface JIekou {
void sl(int sl);
int zrfh();
}
//接口Zaizhong
public interface Zaizhong {
public void zl(double zl);
public double zhfh();
}
膜拜大神