亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

20170703答答用車系統

標簽:
Java

创建Car类
public class Car {
public String carName; //车名
public int ID, personLoad; //序号、载客量
public double carRental, meterLoad; //租金、载货量

@Override
public String toString() {
    return "ID:" + ID + ", 名称:" + carName 
            + ", 载客量:" + personLoad + ", 载货量:" 
            + meterLoad + ", 租金:" + carRental;
}

}

创建Bus类,继承Car类
public class Bus extends Car {

public Bus() {
    super();
    // TODO Auto-generated constructor stub
}
public Bus(int ID, String carName, int personLoad, double meterLoad, double carRental){
    this.ID = ID;
    this.carName = carName;
    this.personLoad = personLoad;
    this.meterLoad = meterLoad;
    this.carRental = carRental;
}

}

创建皮卡类,继承Car类
public class PickUp extends Car {

public PickUp() {
    super();
    // TODO Auto-generated constructor stub
}
public PickUp(int ID, String carName, int personLoad, double meterLoad, double carRental){
    this.ID = ID;
    this.carName = carName;
    this.personLoad = personLoad;
    this.meterLoad = meterLoad;
    this.carRental = carRental;
}       

}

创建卡车类,继承Car类
public class Truck extends Car {

public Truck() {
    super();
    // TODO Auto-generated constructor stub
}

public Truck(int ID, String carName, int personLoad, double meterLoad, double carRental){
    this.ID = ID;
    this.carName = carName;
    this.personLoad = personLoad;
    this.meterLoad = meterLoad;
    this.carRental = carRental;
}   

}

创建展示类,答答用车系统界面
import java.util.Scanner;

public class Show {
public static void main (String[] args){
System.out.println("欢迎使用答答租车系统");
System.out.println("您是否要租车呢?1是;0否");
Scanner sn = new Scanner(System.in);

    int isGet = sn.nextInt(); //判断是否需要租车
    if (isGet == 1){
        //显示车的信息
        System.out.println("在库车的信息如下:序号、名称、载客数、载货量、租金"); //显示车的信息
        Car[] car = new Car[]{new Bus(1, "奥迪A4", 500, 0, 4),
                new Bus(2, "马自达6", 400, 0, 4),
                new PickUp(3, "皮卡雪", 450, 4, 2),
                new Bus(4, "金龙", 800, 0, 20),
                new Truck(5, "松花江", 0, 400, 4),
                new Truck(6, "依维柯", 0, 1000, 20)};
        for(int i = 0; i <= car.length - 1; i ++){
            System.out.println(car[i]);
        }

        //需要使用几辆车
        System.out.println("您需要使用几辆车呢");
        int useCarNum = sn.nextInt(); //获取想要使用的车辆
        //当需要用车的时间大于0时
        if (useCarNum > 0){
            //创建数组,用于存储员工输入的车序号
            int[] CarNum = new int[useCarNum];

            //将序号写入到数组中中
            for (int i = 1; i <= useCarNum; i++){
                System.out.println("请输入第" + i + "辆车的序号");
                int Order = sn.nextInt();
                CarNum[i - 1] = Order; //将车的序号写入数组中
            }

            //获取租车天数
            System.out.println("请输入租车的天数");
            int CarDay = sn.nextInt();

            //当数组里面有数据的时候
            if (CarNum.length > 0){
                double Totalmoney = 0;

                //打印用车信息
                System.out.println("您使用的车如下:");
                for(int i = 0; i < CarNum.length; i++){
                    System.out.println(car[CarNum[i] - 1]);
                    Totalmoney = Totalmoney + CarDay * car[CarNum[i] - 1].carRental;
                }
                System.out.println("租期为:" + CarDay + "天,总租金为:" + Totalmoney + "元");
            }
        }else{
            System.out.println("输入有误");
        }
    }else{
        System.out.println("欢迎下次使用,再见");
    }

    sn.close();
}

}

显示结果
图片描述

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消