为了账号安全,请及时绑定邮箱和手机立即绑定

大神帮忙看看还有什么需要改进,thanks

package com.dadazuche2;

public class Car {
	int id;
	String carName;
	float pay;
    int setNum;
    int loadNum;
    static String lieXing;
	public Car(int id,String carName,String lieXing,int setNum,int loadNum,float pay){
		this.id=id;
		this.carName=carName;
		this.pay=pay;
		this.setNum=setNum;
		this.loadNum=loadNum;
}
	public Car(int id2, String carName2, int setNum2, int loadNum2, float pay2) {
		// TODO Auto-generated constructor stub
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getCarName() {
		return carName;
	}
	public void setCarName(String carName) {
		this.carName = carName;
	}
	public float getPay() {
		return pay;
	}
	public void setPay(float pay) {
		this.pay = pay;
	}
	public int getSetNum() {
		return setNum;
	}
	public void setSetNum(int setNum) {
		this.setNum = setNum;
	}
	public int getLoadNum() {
		return loadNum;
	}
	public void setLoadNum(int loadNum) {
		this.loadNum = loadNum;
	}
	public void infoshow() {
	}
}

package com.dadazuche2;


public class KeChe extends Car {

public final String leiXing="客车";

public KeChe(int id, String carName, String lieXing,int setNum,int loadNum, float pay) {

super(id, carName, lieXing,setNum,loadNum, pay);

}

public void infoshow() {

System.out.println(id+"\t\t"+carName+"\t\t"+leiXing+"\t\t"+setNum+"人"+"\t\t\t\t"+pay+"元/天");

}

}

package com.dadazuche2;


public class HuoChe extends Car {

public final String leiXing="货车";

public HuoChe(int id, String carName, String lieXing,int setNum, int loadNum, float pay) {

super(id, carName,lieXing,setNum, loadNum, pay);

}

public void infoshow() {

System.out.println(id+"\t\t"+carName+"\t\t"+leiXing+"\t\t"+loadNum+"吨"+"\t\t\t\t"+pay+"元/天");

}

}

package com.dadazuche2;


public class PkChe extends Car {

public final String leiXing="皮卡";

public PkChe(int id, String carName, String lieXing, int setNum, int loadNum, float pay) {

super(id, carName,lieXing, setNum, loadNum, pay);

}

public void infoshow() {

System.out.println(id+"\t\t"+carName+"\t\t"+leiXing+"\t\t"+loadNum+"吨"+"\t\t"+setNum+"人"+"\t\t"+pay+"元/天");

}

}

package com.dadazuche2;

import java.util.Scanner;



public class Inner {


private static Scanner input;


public static void main(String[] args) {

float sum=0;

Car[] car={new KeChe(1,"奥迪A6","客车",5,0,200),new KeChe(2,"保时捷A6L","客车",5,0,200),

new HuoChe(3,"依维柯","货车",0,10,400),new PkChe(4,"金龙","皮卡",8,3,400)};

input = new Scanner(System.in);

System.out.println("***************欢迎来到dada租车系统***************");

System.out.println("是否真的租车?是1否0 请输入:");

int userIn=input.nextInt();

if(userIn==1){

System.out.println("租车信息列表如下:");

System.out.println("车牌号:"+"\t\t"+"车名字:"+"\t\t"+"车型:"+"\t\t"+"载货量(座位数):"+"\t\t\t"+"价钱:");

for(int i=0;i<car.length;i++){

car[i].infoshow();

}

System.out.println("请输入车辆数");

        int carNum=input.nextInt();

int[] carId=new int[100];

        System.out.println("请输入车号");

        for(int i=0;i<car.length;i++){

        carId[i]=input.nextInt();

        }

        System.out.println("请输入使用天数");

        int day=input.nextInt();

        System.out.println("您的订单信息如下:");

        System.out.println("车牌号:"+"\t\t"+"车名字:"+"\t\t"+"车型:"+"\t\t"+"载货量(座位数):"+"\t\t\t"+"价钱:");

        for(int i=0;i<car.length;i++){

        for(int j=0;j<car.length;j++){

        if(car[j].getId()==carId[i]){

        car[j].infoshow();

        sum= sum+car[j].getPay();

        }

       

       

        }

        }

        System.out.println(sum);

        System.out.println("用车辆数"+carNum+"用车天数"+day);

        System.out.println("总费用:"+sum*day);

  }else{

    System.out.println("欢迎下次光临dada租车系统!");

 

}

}

}


正在回答

1 回答

System.out.println("请输入车号");

        for(int i=0;i<car.length;i++)

这里的i<car.length,是不是应该改为i<carNum更好些呢?

用户输入车辆数之后,选择车号的数量应该和车辆数一致吧

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

大神帮忙看看还有什么需要改进,thanks

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信