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

菜鸟一枚,花了8个小时才编好。有很多不足,望大家畅所欲言、各抒己见。

package com.carsystem;

public class Car{

private int carMoney;    //汽车租金

    private String carName;   //汽车名字

    private int  carNumb;      //汽车序列号

    private int carryNum;    //载货量

    private int passengerNum;//载客人数

public int getCarMoney() {

return carMoney;

}

public void setCarMoney(int carMoney) {

this.carMoney = carMoney;

}

public String getCarName() {

return carName;

}

public void setCarName(String carName) {

this.carName = carName;

}

public int getCarNumb() {

return carNumb;

}

public void setCarNumb(int carNumb) {

this.carNumb = carNumb;

}

public int getCarryNum() {

return carryNum;

}

public void setCarryNum(int carryNum) {

this.carryNum = carryNum;

}

public int getPassengerNum() {

return passengerNum;

}

public void setPassengerNum(int passengerNum) {

this.passengerNum = passengerNum;

}

public void showInfo() {

// TODO Auto-generated method stub

}

}

------------------------------------------------------------------------------------------------------

package com.carsystem;

public class Pickup extends Car{

public Pickup(int carNumb,String carName,int carMoney,int passengerNum,int carryNum){

this.setCarNumb(carNumb);

this.setCarName(carName);

this.setCarMoney(carMoney);

this.setPassengerNum(passengerNum);

this.setCarryNum(carryNum);

}       

}

-----------------------------------------------------------------------------------------------------------

package com.carsystem;


public class Sedan extends Car {

public Sedan(int carNumb,String carName,int carMoney,int passengerNum,int carryNumb){

this.setCarNumb(carNumb);

this.setCarName(carName);

this.setCarMoney(carMoney);

this.setPassengerNum(passengerNum);

this.setCarryNum(carryNumb);

}

}

----------------------------------------------------------------------------------------------------------------

package com.carsystem;

import java.util.*;

public class Main{

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println("欢迎使用租车系统");

System.out.println("是否租车1是0否");

Scanner sc=new Scanner(System.in);

int input=sc.nextInt();

int totalmoney = 0;

//carlist用来存储所有车的资料

Car[] carlist={new Sedan(1,"宝马",1000,4,0),new Sedan(2,"真马",10000,2,0),new Pickup(3,"黄海皮卡",100,4,4),new Pickup(4,"依维柯",7000,12,20)};

if(input==0){

System.out.println("88!");

}else if(input==1){

System.out.println("欢迎您!以下是车源列表(0代表没有此功能)");

System.out.println("序号"+"\t"+"车名"+"\t"+"价钱/天"+"\t"+"载客量"+"\t"+"载货量");

//Car[] carlist={new Sedan(1,"宝马",1000,4,0),new Sedan(2,"真马",10000,2,0),new Pickup(3,"黄海皮卡",100,4,4),new Pickup(4,"依维柯",7000,12,20)};

for(Car ca:carlist){

if(ca instanceof Sedan){

System.out.println(ca.getCarNumb()+"\t"+ca.getCarName()+"\t"+ca.getCarMoney()+"/天"+"\t"+ca.getPassengerNum()+"人"+"\t"+ca.getCarryNum()+"吨");

}

if(ca instanceof Pickup){

System.out.println(ca.getCarNumb()+"\t"+ca.getCarName()+"\t"+ca.getCarMoney()+"/天"+"\t"+ca.getPassengerNum()+"人"+"\t"+ca.getCarryNum()+"吨");

}

}

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

System.out.println(car[i]);

car[i].showInfo();

}*/

}

System.out.println("请输入要租车的数量");

int totalNum=sc.nextInt();//存储租车总数//

//if(totalNum==0){

//System.out.println("输入错误重新输入");

while(true){

if(totalNum==0)

{System.out.println("输入有误 重新输入!"); 

totalNum=sc.nextInt();

//break;

}

else{ break;}

}

for(int j=1;j<=totalNum;j++){

System.out.println("请输入第"+j+"台车序号");

//choicecar用来存储所选择的车信息

Car[] choicecar=new Car[totalNum];

//yourcarnum是用户要租的车序号

int yourcarnum=sc.nextInt();

choicecar[j-1]=carlist[yourcarnum-1];

if(choicecar[j-1] instanceof Sedan){

totalmoney=totalmoney+choicecar[j-1].getCarMoney();

}

if(choicecar[j-1] instanceof Pickup){

totalmoney=totalmoney+choicecar[j-1].getCarMoney();

}

}

System.out.println("请输入想要租车的天数:");

        int rentDay = sc.nextInt();  //租车天数

        System.out.println("您需要支付总价为:"+totalmoney*rentDay+"元");


}

}


正在回答

4 回答

写得不错,一起加油

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

举报

0/150
提交
取消

菜鸟一枚,花了8个小时才编好。有很多不足,望大家畅所欲言、各抒己见。

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