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

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

Java入門第二季6-1租車項目

標簽:
C

1.Car类
package imooc;

public class Car {
public int ID;
public String nameString;
public int rent;
public int personCapacity;
public int goodCapacity;
}

2.可载人汽车类
package imooc;

public class peopleCar extends Car{
public peopleCar(int newID, String newName, int newRent,
int newPersonCapacity) {
this.ID = newID;
this.nameString = newName;
this.rent = newRent;
this.personCapacity = newPersonCapacity;
}

}

3.可载物汽车类
package imooc;

public class Trunk extends Car{
public Trunk(int newID, String newName, int newRent,
int newGoodCapacity) {
this.ID = newID;
this.nameString = newName;
this.rent = newRent;
this.goodCapacity = newGoodCapacity;
}

}

4.皮卡,既可载人又可载物类
package imooc;

public class PikaCar extends Car {
public PikaCar(int newID,String newName,int newRent,int newPoepleCapacity,int newGoodCapacity){
this.ID=newID;
this.nameString=newName;
this.personCapacity=newPoepleCapacity;
this.rent=newRent;
this.goodCapacity=newGoodCapacity;
}
}

5.Main函数
package imooc;

import java.security.PrivateKey;
import java.util.*;

public class Main {
public static void main(String[] args) {
Car[] allCars = { new peopleCar(1, "奥迪A4", 500, 4),
new peopleCar(2, "马自达6", 400, 4),
new PikaCar(3, "皮卡雪6", 450, 4, 2),
new peopleCar(4, "金龙", 800, 20), new Trunk(5, "松花江", 400, 4),
new Trunk(6, "依维柯", 1000, 20) };
System.out.println("欢迎使用达达租车系统");
System.out.println("您是否要租车“1是0否");
Scanner inputScanner = new Scanner(System.in);// 指定输入设备为System.in
int Acess = inputScanner.nextInt();// 接收用户输入的信息并保存
System.out.println("您输入的是:" + inputScanner + "和" + Acess);
if (Acess == 1) {
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号 汽车名称 租金 容量");
for (int i = 0; i < allCars.length; i++) {
if (allCars[i] instanceof peopleCar) {
System.out.println(allCars[i].ID + " "

  • allCars[i].nameString + " " + allCars[i].rent
  • " " + allCars[i].personCapacity);
    } else if (allCars[i] instanceof Trunk) {
    System.out.println(allCars[i].ID + " "
  • allCars[i].nameString + " " + allCars[i].rent
  • " " + allCars[i].goodCapacity);
    } else if (allCars[i] instanceof PikaCar) {
    System.out.println(allCars[i].ID + " "
  • allCars[i].nameString + " " + allCars[i].rent
  • " " + allCars[i].personCapacity + " "
  • allCars[i].goodCapacity);
    }

        }
    }
    System.out.println("请输入您要租汽车的数量:");
    Scanner input = new Scanner(System.in);// 指定输入设备为System.in
    int num = input.nextInt();// 接收用户输入的信息并保存
    int sum = 0;
     Car[] newlistCars=new Car[6];
    for (int i = 0; i < num; i++) {
        System.out.println("请输入第" + (i + 1) + "辆车的序号:");
        Scanner inputID = new Scanner(System.in);
        int CarID = inputID.nextInt();
        for(int a=0;a<allCars.length;a++){
            if(CarID==allCars[a].ID){
                newlistCars[i]=new Car();
                newlistCars[i]=allCars[a];

    // newlistCars[i].ID=allCars[a].ID;
    // newlistCars[i].nameString=allCars[a].nameString;
    // newlistCars[i].rent=allCars[a].rent;
    // newlistCars[i].personCapacity=allCars[a].personCapacity;
    // newlistCars[i].goodCapacity=allCars[a].goodCapacity;
    sum=sum+newlistCars[i].rent;
    }
    }
    }
    System.out.println("请输入租车天数:");
    Scanner inputRent = new Scanner(System.in);
    int rentDay = inputRent.nextInt();
    System.out.println("您的账单:");
    System.out.println("可载人的车:");
    String[] peoplecarname=new String[6];
    int personNum=0;
    int capacity=0;
    int a=0;int b=0;
    String[] goodcarname=new String[6];
    for(int i=0;i<newlistCars.length;i++){
    if(newlistCars[i] instanceof peopleCar||newlistCars[i] instanceof PikaCar){
    peoplecarname[a]=newlistCars[i].nameString;
    personNum=personNum+newlistCars[i].personCapacity;

            if(peoplecarname[a]!=null){
                System.out.print(peoplecarname[a]+"  ");
            }
            a=a+1;
        }
    
    }
    System.out.println("共可载人:"+personNum+"人");
    System.out.println("可载物的车:");
    for(int i=0;i<newlistCars.length;i++){
    
        if(newlistCars[i] instanceof Trunk||newlistCars[i] instanceof PikaCar){
            goodcarname[b]=newlistCars[i].nameString;
            capacity=personNum+newlistCars[i].goodCapacity;
            if(goodcarname[b]!=null){
                System.out.print(goodcarname[b]+"  ");
            }
            b=b+1;
        }
    }
    System.out.println("共可载物:"+capacity+"吨");
    
    System.out.println("租车总价格:" + (sum * rentDay) + "元");

    }
    }

點擊查看更多內(nèi)容
14人點贊

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

評論

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

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

100積分直接送

付費專欄免費學

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

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

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

幫助反饋 APP下載

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

公眾號

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

舉報

0/150
提交
取消