第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

java第二季綜合練習,答答租車系統(tǒng)

標簽:
Java

父类 Car

public class Car extends Object {
    private String carName;
    private int carPrice;
    private int carPeople;
    private int carGoods;
    public String getCarName() {
        return carName;
    }
    public void setCarName(String carName) {
        this.carName = carName;
    }
    public int getCarPrice() {
        return carPrice;
    }
    public void setCarPrice(int carPrice) {
        this.carPrice = carPrice;
    }
    public int getCarPeople() {
        return carPeople;
    }
    public void setCarPeople(int carPeople) {
        this.carPeople = carPeople;
    }
    public int getCarGoods() {
        return carGoods;
    }
    public void setCarGoods(int carGoods) {
        this.carGoods = carGoods;
    }

}

子类PassengerCar

public class PassengerCar extends Car {
    public PassengerCar (String name,int price,int people){
        super.setCarName(name);
        super.setCarPrice(price);
        super.setCarPeople(people);
    }

    @Override
    public String toString() {
        return  this.getCarName() + "\t"+this.getCarPrice() + "\t载人:"+this.getCarPeople() ;
    }

}

子类Truck

public class Truck extends Car {
    public Truck(String name,int price,int goods){
        super.setCarName(name);
        super.setCarPrice(price);
        super.setCarGoods(goods);
    }

    @Override
    public String toString() {
        return this.getCarName() + "\t"+ this.getCarPrice()+"\t载货:" + this.getCarGoods() +"吨";
    }

}

子类 Pickup

public class Pickup extends Car {
    public Pickup(String name,int price,int people,int goods){
        super.setCarName(name);
        super.setCarPrice(price);
        super.setCarPeople(people);
        super.setCarGoods(goods);
    }

    @Override
    public String toString() {
        return this.getCarName() + "\t" + this.getCarPrice() + "\t载人:"+ this.getCarPeople() + "载货:"+ this.getCarGoods()+"吨" ;
    }

}

main

import java.util.*;
public class Dada {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("欢迎使用答答租车系统\n您是否要租车:1是 0否");
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        if(x!=1){
            System.out.println("谢谢光临,期待您下次再来!");
            System.exit(0);
        }
        else{
            System.out.println("您可租的类型及其价目表:");
            System.out.println("序号\t汽车名称\t租金\t容量");
        }
        //到这为止,判定是否为真正租车的。

        PassengerCar car1 = new PassengerCar("奥迪A4",500,4);
        PassengerCar car2 = new PassengerCar("马自达6",400,4);
        Pickup car3 = new Pickup("皮卡雪6",450,4,2);
        PassengerCar car4 = new PassengerCar("金龙",800,20);
        Truck car5 = new Truck("松花江",400,4);
        Truck car6 = new Truck("依维柯",400,4);
        Car[] cars = {car1,car2,car3,car4,car5,car6};
        for(int i=0;i<cars.length;i++){
            System.out.println((i+1)+".\t"+cars[i].toString()); 
        }
        //  隔开一下,看的更清楚啦!

        System.out.println("请输入您要租汽车的数量:");
        int n = input.nextInt();       //记录租车数量
        Car [] carList = new Car[n];   //记录租车序号
        int totalPrice = 0;
        for(int j=0;j<n;j++){
            System.out.println("请输入第"+(j+1)+"辆车的序号(1——"+cars.length+"):");
            int num = input.nextInt();
            carList[j] = cars[num-1];
            totalPrice+=carList[j].getCarPrice();
        }       
        System.out.println("请输入租车天数:");
        int days = input.nextInt();
        totalPrice*=days;     //  租车总价格

        //下面开始计算载人的车辆以及载人数
        int totalPeople=0;
        System.out.println("您的账单:\n***可载人的车有:");
        for(int i=0;i<n;i++){
            if(carList[i] instanceof PassengerCarcarList[i] instanceof Pickup){
            System.out.print(carList[i].getCarName()+"\t");
            totalPeople+=carList[i].getCarPeople();
            }
        }
        System.out.print("共载人:"+totalPeople+"人\n***载货的车有:\n");

        //下面开始计算载货的车辆以及载货量
        int totalGoods=0;
        for(int o=0;o<n;o++){   
            if(carList[o] instanceof TruckcarList[o] instanceof Pickup){
            System.out.print(carList[o].getCarName()+"\t");
            totalGoods+=carList[o].getCarGoods();
            }
        }
        System.out.println("共载货:"+totalGoods+"吨");
        System.out.println("***租车总价格:"+totalPrice);

    }

}
點擊查看更多內(nèi)容
TA 點贊

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

評論

作者其他優(yōu)質文章

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

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

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

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消