抽象类Che
package car;
public abstract class Che {
/**车ID*/
public int ceid;
/**车名*/
public String cem;
/**租金*/
public int qiang;
/**载客数*/
public int ren;
/**载货量*/
public int huo;
public int getCeid() {
return ceid;
}
public void setCeid(int ceid) {
this.ceid = ceid;
}
public String getCem() {
return cem;
}
public void setCem(String cem) {
this.cem = cem;
}
public int getQiang() {
return qiang;
}
public void setQiang(int qiang) {
this.qiang = qiang;
}
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 void Che(int ceid,String cem,int qiang,int ren,int huo){
this.ceid=ceid;
this.cem=cem;
this.qiang=qiang;
this.huo=huo;
this.ren=ren;
}
}
子类Renche
package car;
public class Renche extends Che {
public Renche(int ceid,String cem,int qiang,int ren){
this.ceid=ceid;
this.cem=cem;
this.qiang=qiang;
this.ren=ren;
}
@Override
public String toString() {
return ceid+"\t"+cem+"\t"+qiang+"/天\t载人:"+ren+"人";
}
}
子类Huoche
package car;
public class Huoche extends Che {
public Huoche(int ceid,String cem,int qiang,int huo){
this.ceid=ceid;
this.cem=cem;
this.qiang=qiang;
this.huo=huo;
}
@Override
public String toString() {
return ceid+"\t"+cem+"\t"+qiang+"/天\t载货:"+huo+"吨";
}
}
子类Pikache
package car;
public class Pikache extends Che {
public Pikache(int ceid,String cem,int qiang,int ren,int huo){
this.ceid=ceid;
this.cem=cem;
this.qiang=qiang;
this.huo=huo;
this.ren=ren;
}
@Override
public String toString() {
return ceid+"\t"+cem+"\t"+qiang+"/天\t载人:"+ren+"人\t载货:"+huo+"吨";
}
}
主方法
package car;
import java.util.Scanner;
public class Ceshi {
static int R=3;//小轿车数量-1
static int H=2;//货车数量-1
static int RH=1;//皮卡数量-1
public static void main(String[] args) {
Scanner suru=new Scanner(System.in);
String pd="n";//判断是否进入系统
//建立车辆信息
Che []r=new Renche[R];
Che []h=new Huoche[H];
Che []rh=new Pikache[RH];
//小轿车
r[0]=new Renche(1, "迪奥A4", 500, 4);
r[1]=new Renche(2, "马自达6", 400, 4);
r[2]=new Renche(3, "金龙", 800, 4);
//货车(+2)
h[0]=new Huoche(R+2,"松花江", 400, 4);
h[1]=new Huoche(R+3,"依维柯", 1000, 20);
//皮卡(+3)
rh[0]=new Pikache(R+H+3, "皮卡西6", 4500, 4, 2);
//系统大循环
for (;;) {
int sl=-1;//要选择车辆的数量
int zren=0;//总人数
int zhuo=0;//总载货量
int zjg=0;//总价格
String zce="";//选择的车辆
System.out.println("是否进入租车系统?(y/n)");
pd=suru.next();
//是否进入系统判断
if ("n".equalsIgnoreCase(pd)) {
break;
}
if ("y".equalsIgnoreCase(pd)) {
System.out.println("*****欢迎进入租车系统********");
System.out.println("******以下为车辆信息*******");
System.out.println("编号\t车辆名称\t价格\t功能");
//输出车辆信息
for (int i = 0; i < r.length; i++) {
System.out.println(r[i]);
}
for (int i = 0; i < h.length; i++) {
System.out.println(h[i]);
}
for (int i = 0; i < rh.length; i++) {
System.out.println(rh[i]);
}
System.out.println("请输入您要租车的数量:");
sl=suru.nextInt();
//选车循环
for (int i = 0; i <= sl-1; i++) {
int xz=-1;//选择的车辆
System.out.println("请输入第"+(i+1)+"辆车的序号:");
xz=suru.nextInt();
for (int a = 0; a < r.length; a++) {
if(r[a].ceid==xz){
zren+=r[a].ren;
zjg+=r[a].qiang;
zce+=r[a].cem;
}
}
for (int b = 0; b < h.length; b++) {
if(h[b].ceid==xz){
zjg+=h[b].qiang;
zhuo+=h[b].huo;
zce+=h[b].cem;
}
}
for (int c = 0; c < rh.length; c++) {
if(rh[c].ceid==xz){
zren+=rh[c].ren;
zjg+=rh[c].qiang;
zhuo+=rh[c].huo;
zce+=rh[c].cem;
}
}
}
System.out.println("请输入租车天数");
int zuce=suru.nextInt();
System.out.println("********您的账单********");
System.out.println("选择车辆:"+zce);
System.out.println("价格:"+zjg*zuce+"\t载人:"+zren+"人\t"+"载货量:"+zhuo+"吨");
System.out.println("是否继续租车?(y/n)");
pd=suru.next();
if ("n".equalsIgnoreCase(pd)) {
System.out.println("感谢您的使用");
break;
}
}
}
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章