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

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

Java入門第二季 6-2 答答租車系統(tǒng)

標簽:
Java

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

public class Car {

public String Name = "";

public int Rent = 0;

public int FreightVolume = 0;//载物

public int CarryinCapacity = 0;//载人

}

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

public class PassengerCar extends Car{  

public PassengerCar(String name,int rent,int ca) {

Name = name;

Rent = rent;

CarryinCapacity = ca;

}

}

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

public class Truck extends Car{

public Truck(String name,int rent,int fr) {

Name = name;

Rent = rent;

FreightVolume = fr;

}

}

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

public class PickUp extends Car {

public PickUp(String name,int rent,int ca,int fr) {

Name = name;

Rent = rent;

CarryinCapacity = ca;

FreightVolume = fr;

}

}

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

import java.util.Scanner;

public class Initail {


public static void main(String[] args) {


Car[] cars = {new PassengerCar("奥迪A4",500,4),

new PassengerCar("马自达6",400,4),

new PickUp("皮卡雪6",450,4,2),

new PassengerCar("金龙",800,20),

new Truck("松花江",400,4),

new Truck("伊维科",1000,20)};

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

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

Scanner scan = new Scanner(System.in);

String input = scan.next();

if(input.equals("1")) {

System.out.println("您可以租车的类型及价目表:");

System.out.println("序号\t汽车\t租金\t容量");

int a = 1;//汽车的序号

for(Car car : cars) {

if(car instanceof PassengerCar) {

System.out.println("" + a + "\t" + car.Name + "\t" + car.Rent + "元/天" + "\t" + "载人:" + car.CarryinCapacity + "人");

}

if(car instanceof Truck) {

System.out.println("" + a + "\t" + car.Name + "\t" + car.Rent + "元/天" + "\t" + "载货:" + car.FreightVolume + "吨");

}

if(car instanceof PickUp) {

System.out.println("" + a + "\t" + car.Name + "\t" + car.Rent + "元/天" + "\t" + "载人:" + car.CarryinCapacity + "人" + " " + "载货:" + car.FreightVolume + "吨");

}

a++;

}

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

int num = scan.nextInt();

int[] count = new int[10];

for(int i = 0;i < num;i++) {

int b = i + 1;

System.out.println("请输入第" + b + "辆车的序号");

count[i] = scan.nextInt() - 1;//序号是从1开始,而数组是从0开始

}

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

int day = scan.nextInt();

System.out.println("您的账单:");

System.out.println("***可载人的车有:");

int allcc = 0;//共载人

int allfv = 0;//共载货

int price = 0;//总价格

for(int i = 0;i < num;i++) {

if(cars[count[i]] instanceof PassengerCar || cars[count[i]] instanceof PickUp) {

//count[i]保存的是车的序号,cars[count[i]]就是第i+1辆车

System.out.print("\t" + cars[count[i]].Name);

allcc = cars[count[i]].CarryinCapacity + allcc;

price = cars[count[i]].Rent + price;

}

}

System.out.println("\t" + "共载人:" + allcc + "人");

System.out.println("***载货的车有:");

for(int i = 0;i < num;i++) {

if(cars[count[i]] instanceof Truck || cars[count[i]] instanceof PickUp) {

System.out.print("\t" + cars[count[i]].Name);

allfv = cars[count[i]].FreightVolume + allfv;

if(cars[count[i]] instanceof Truck) {//如果是皮卡,则价格已经在前面统计了

price = cars[count[i]].Rent + price;

}

}

}

System.out.println("\t" + "共载货:" + allfv + "吨");

price = price * day;

System.out.println("***租车总价格为:" + price + "元");

}

else {

System.exit(0);

}

scan.close();

}

}


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

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

評論

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

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

100積分直接送

付費專欄免費學

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

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

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

幫助反饋 APP下載

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

公眾號

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

舉報

0/150
提交
取消