最后项目的代码
最后那个租车系统的项目代码 有没有标准的 请大神给我一份比较好的,注释写清楚的 谢谢
最后那个租车系统的项目代码 有没有标准的 请大神给我一份比较好的,注释写清楚的 谢谢
2017-05-21
package NewCar; import java.util.Scanner; public abstract class NewCar { public int number= 0; public int weight = 0; public int cost = 0; public String name; } ************************** package NewCar; public class PassengerCar1 extends NewCar { public PassengerCar1(String name,int number,int cost){ super.cost = cost; super.name = name; super.number = number; } } ***************************************** package NewCar; public class PickUp1 extends NewCar { public PickUp1(String name,int number,int cost,int weight){ super.cost = cost; super.name = name; super.number = number; super.weight = weight; } } ********************************* package NewCar; public class Truck1 extends NewCar { public Truck1(String name,int weight,int cost){ this.name = name; this.cost = cost; this.weight = weight; } } *************************************** package NewCar; import java.util.Scanner; public class Main1 { public static void main(String[]args){ int Cost = 0; int Weight = 0; int Number = 0; NewCar[] n = new NewCar[5]; n[0] = new PassengerCar1("小轿车 ",4,300); n[1] = new PassengerCar1("大客车 ",30,800); n[2] = new Truck1("轻型货车 ",8,500); n[3] = new Truck1("重型货车 ",15,800); n[4] = new PickUp1("皮卡车 ",4,600,4); System.out.println("您是否需要租车:1.是,0.否"); Scanner scr = new Scanner(System.in); int t= scr.nextInt(); while(t==1){ System.out.println("欢迎来到租车系统!"); System.out.println("********************************************************"); System.out.println(" 车型: 载客量(人): 载重量(吨): 费用(元/天): 序号:"); for(int j =0;j<n.length;j++){ System.out.println(n[j].name+" "+n[j].number+" " +n[j].weight+" "+n[j].cost+" "+(j+1)); } System.out.println("*********************************************************"); System.out.println("选择想要租用的天数:"); int t2 = scr.nextInt(); System.out.println("选择想要租用的车辆数:"); int t3 = scr.nextInt(); System.out.println("选择相应序号选择车型:"); for(int k=1;k<=t3;k++){ int t1 = scr.nextInt(); if(t1>5){ System.out.println("目前只有五辆车,请输入1到5的数!再见!"); System.exit(0); } System.out.println("这是您租用的第"+k+"辆车"); System.out.println("车型:"+n[t1-1].name+" 载客量:"+n[t1-1].number+"人,载重量:"+ n[t1-1].weight+"吨,费用:"+n[t1-1].cost+"元/天,序号:"+(t1)); Cost = Cost + n[t1-1].cost; Weight = Weight + n[t1-1].weight; Number = Number + n[t1-1].number; } System.out.println("谢谢您的使用!"); System.out.println("您本次总租用车辆:"+t3+"辆,总租用天数:"+t2+"天,总载客量:"+Number +"人,总载重量:"+Weight+"吨,总费用:"+(Cost*t2)+"元"); } System.out.println("再见"); System.exit(0); } }
package com.imooc;
public abstract class Car {
public String name;
public int zj;
public int zr;
public int zh;
}
/////////////////////////////////////////
package com.imooc;
public class Zr extends Car {
public Zr(String name,int zj,int zr){
this.name=name;
this.zj=zj;
this.zr=zr;
}
public String toString(){
return(name+"\t"+zj+"\t\t\t"+zr+"人");
}
}
////////////////////////////////////////////////
package com.imooc;
public class Zh extends Car {
public Zh(String name,int zj,int zh){
this.name=name;
this.zj=zj;
this.zh=zh;
}
public String toString(){
return(name+"\t"+zj+"\t\t\t"+zh+"吨");
}
}
////////////////////////////////////////////////
package com.imooc;
public class Zrh extends Car {
public Zrh(String name,int zj,int zr,int zh){
this.name=name;
this.zj=zj;
this.zr=zr;
this.zh=zh;
}
public String toString(){
return(name+"\t"+zj+"\t\t\t"+zr+"人"+zh+"吨");
}
}
///////////////////////////////////////////////////////
package com.imooc;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Car car[] = new Car [6];
car [0]=new Zr("奥迪A4",500,4);
car [1]=new Zr("马自达6",400,4);
car [3]=new Zr("金龙",800,20);
car [4]=new Zh("松花江",400,4);
car [5]=new Zh("依维柯",1000,20);
car [2]=new Zrh("皮卡雪6",450,4,2);
System.out.println("欢迎使用答答租车系统\n请问是否需要租车:1是,0否");
Scanner input = new Scanner(System.in);
int i = input.nextInt();
if (i==1){
System.out.println("您可租车的类型和价目表");
System.out.println("序号\t汽车名称\t租金\t容量\n"
+ "1.\t奥迪A4\t500元/天\t载人:4人\n"
+ "2.\t马自达6\t400元/天\t载人:4人\n"
+ "3.\t皮卡雪6\t120元/天\t载人:4人 载货:2吨\n"
+ "4.\t金龙\t800元/天\t载人:20人\n"
+ "5.\t松花江\t400/天\t载货:4吨\n"
+ "6.\t依维柯\t1000元/天\t载货:20吨\t");
System.out.println("请输入您要租车的数量:");
int x=input.nextInt();
int zzj=0;
int zzr=0;
int zzh=0;
String kzr=" ";
String kzh=" ";
for (int j=1;j<=x;j++){
System.out.println("请输入第"+j+"辆车的序号:");
int y = input.nextInt();
zzj = zzj+car[y-1].zj;
zzr = zzr+car[y-1].zr;
zzh = zzh+car[y-1].zh;
if (car[y-1].zr!=0) kzr = kzr+car[y-1].name+" ";
if (car[y-1].zh!=0) kzh = kzh+car[y-1].name+" ";
}
System.out.println("请输入您要租车的天数:");
int ts = input.nextInt();
zzj=zzj*ts;
System.out.println("您的账单:\n"
+ "***可载人的车有:\n"+ kzr
+"\n***可载货的车有:\n"+kzh);
System.out.println("***租车总价格:\n "+zzj);
}
}
}
举报