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

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

我的答答租車系統(tǒng)

標(biāo)簽:
Java

package 答答租车系统;
//父类
public class Car{
String name="sdfs";//名字
int price;//租金
int capPerson;//载人量
int capGoods;//载货量
public void show(){
System.out.println(this.name+"\t"+this.price+"元/天\t\t"+this.capGoods+"吨\t\t"+this.capPerson+"人");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getCapPerson() {
return capPerson;
}
public void setCapPerson(int capPerson) {
this.capPerson = capPerson;
}
public int getCapGoods() {
return capGoods;
}
public void setCapGoods(int capGoods) {
this.capGoods = capGoods;
}
}

package 答答租车系统;

public class Auto extends Car {//只能载人的车
public Auto(String name,int price,int capPerson){
this.setName(name);
this.setPrice(price);
this.setCapPerson(capPerson);
this.setCapGoods(0);
}
public void setCapGoods(int capGoods) {
if(capGoods!=0)System.out.println("该值默认为0,不允许修改");
else this.capGoods = capGoods;
}
}

package 答答租车系统;

public class Truck extends Car {//只能载货的车
public Truck(String name,int price,int capGoods){
this.setName(name);
this.setPrice(price);
this.setCapGoods(capGoods);
this.setCapPerson(0);
}
public void setCapPerson(int capPerson) {
if(capPerson!=0)System.out.println("该值默认为0,不允许修改");
else this.capPerson = capPerson;
}
}

package 答答租车系统;

public class Pickup extends Car {//既能载人又能载货
public Pickup(String name,int price,int capPerson,int capGoods){
this.setName(name);
this.setPrice(price);
this.setCapPerson(capPerson);
this.setCapGoods(capGoods);
}
}

package 答答租车系统;

import java.util.Scanner;
//测试类
public class Test {
public static void main(String args[]){
int IF=2;//控制用户是否租车的变量
//初始化车辆信息
Car[] allRent = {new Auto("奥迪A4",500,4),new Auto("马自达6",400,4),new Pickup("皮卡雪6",450,4,2),
new Auto("金龙 ",800,20),new Truck("松花江",400,4),new Truck("依维河",1000,20)};
System.out.println("欢迎来到嗒嗒租车系统!");
System.out.println("输入1进入租车系统,输入0退出系统!");
while(IF==2){
System.out.println("请输入:");
Scanner input=new Scanner(System.in);
IF=input.nextInt();
if(IF==1){
int i,id,sum;
int priceSum=0,personSum=0,goodsSum=0;//租车总价格,载人/货量
//输出可供租借的车辆信息
System.out.println("\n"+"您可以租用的车辆信息如下:");
System.out.println("序号\t"+"款式\t\t"+"价格 \t\t\t"+"载货量\t"+"载人量\t ");
for( i=0;i<allRent.length;i++){
System.out.print((i+1)+".\t");
allRent[i].show();
}
//获得租车的数量,并放入chooseCar[]数字
System.out.println("请输入您要租车的数量:");
sum=input.nextInt();
Car[] chooseCar=new Car[sum];
int[] day=new int[sum];
//租车序号及各自天数
for(i=0;i<sum;i++){
System.out.print("请输入您要租的第"+(i+1)+"辆车的序号:");
id=input.nextInt()-1;
chooseCar[i]=allRent[id];
System.out.print("请输入您要租用该车的天数:");
day[i]=input.nextInt();
}
//最终租车信息列表
System.out.println("您共租用了以下车辆");
for(i=0;i<sum;i++){
priceSum+=chooseCar[i].getPrice()*day[i];
personSum+=chooseCar[i].getCapPerson();
goodsSum+=chooseCar[i].getCapGoods();
System.out.print((i+1)+".\t"+day[i]+"天"+"\t");
chooseCar[i].show();
}

            System.out.println("您所租的车辆租金共计:"+priceSum);
            System.out.println("您所租的车辆载人量共计:"+personSum);
            System.out.println("您所租的车辆载货量共计:"+goodsSum);
        }
        else if(IF==0) System.out.println("您已经退出租车系统,欢迎再次使用!");
        else {
            System.out.println("您输入的为无效信息,请重新输入!");
            IF=2;
        }
        input.close();
    }
}

}

點(diǎn)擊查看更多內(nèi)容
14人點(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
提交
取消