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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

達(dá)達(dá)租車系統(tǒng)代碼分享

標(biāo)簽:
Java

父类
public class Car {
private String name;
private int passengers;
private int goods;
private int price;
public Car(){
}
public Car(String name,int passengers,int goods,int price){
this.setName(name);
this.setPassengers(passengers);
this.setGoods(goods);
this.setPrice(price);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPassengers() {
return passengers;
}
public void setPassengers(int passengers) {
this.passengers = passengers;
}
public int getGoods() {
return goods;
}
public void setGoods(int goods) {
this.goods = goods;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public void Display(){
System.out.println(name+"\t "+passengers+"\t "+goods+"\t "+price);
}
}

子类:Auto, PickUp,Limo,Trunk,Hammer
public class Auto extends Car {
public Auto(String name,int passengers,int goods,int price){
super(name,passengers,goods,price);
}
public void Display(){
System.out.println("I am Auto Car!");
}
}

主程序
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;

public class dadaRent {

private static Scanner input;
public static List<Car> allCar;
public static List<Car> rentCar;
public dadaRent(){
    dadaRent.allCar = new ArrayList<Car>();
    dadaRent.rentCar = new ArrayList<Car>();
}

public static void main(String[] args) {
    // TODO Auto-generated method stub
    dadaRent ddr = new dadaRent();
    boolean flag = true;
    System.out.println("Welcome to DaDaRent !");        
    while(flag)
    {           
        System.out.println("Do you want to Rent Cars or Leave? Yes OR No ?");
        input = new Scanner(System.in);
        String choose = input.next();
        if(choose.equals("no"))     
        {   
            System.out.println("谢谢光临!");
            flag = false;
            break;
        }
        if(choose.equals("yes"))
        {
            try{                
                 System.out.println("Here are the Car List:");
                 ddr.AddCars();
                 ddr.DisplayCars(allCar);
                 System.out.println("How many cars do you want to rent?");
                 int num =input.nextInt();
                 int [] rentNum = new int[num];
                 for(int i=0;i<num;i++)
                 {
                    System.out.println("请输入第"+(i+1)+"辆车编号:");
                    int j = input.nextInt();
                    rentNum[i] =j-1;                
                 }
                 System.out.println("下面是你选择的车辆:");
                 ddr.AddRent(rentNum);
                 ddr.DisplayCars(rentCar);
                 for(Car obj:rentCar)
                 {  
                        obj.Display();
                 }
                 System.out.println("Please input rent days:");
                 int rentDay  =input.nextInt();
                 System.out.println("Your tocal Price is: "+ddr.TotoalPrice(rentDay));                   
              }
                catch(InputMismatchException e)
                {
                   e.printStackTrace(); 
                }
        }
        else
            System.out.println("Input Error! Try Again!");              
    }

}

public void AddCars(){
    Car [] carArray= {new PickUp("皮卡",4,20,450),new Auto("奥迪",4,19,500),new Limo("劳斯莱斯",6,25,2000),
            new Trunk("卡车",2,30,200),new Hammer("悍马",2,40,1000)};
    allCar.addAll(Arrays.asList(carArray));
}

public void AddRent(int []rentNum){     
    for(int i=0;i<rentNum.length;i++){  
        rentCar.add(allCar.get(rentNum[i]));
    }
}

public static void DisplayCars(List<Car> cars){
    System.out.println("编号\t车型\t    载客\t    载货/tons\t租金RMB/day\t");
    for(int i=0;i<cars.size();i++)
    {
        System.out.println(" "+(i+1)+"\t"+cars.get(i).getName()+"\t     "+cars.get(i).getPassengers()+
                "\t       "+cars.get(i).getGoods()+"\t     "+cars.get(i).getPrice());
    }
}

public int TotoalPrice(int rentDay){
    int priceSum =0;
    for(int i=0;i<rentCar.size();i++){
        priceSum = priceSum+rentCar.get(i).getPrice();
    }
    return priceSum*rentDay;
}

}

點(diǎn)擊查看更多內(nèi)容
4人點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

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

正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消