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

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

答答租車系統(tǒng),使用interface的簡單版本~(java第二季綜合練習(xí))

標(biāo)簽:
Java

Car类

public abstract class Car {
    int carNum;
    String carName;
    int carRent;
    int carDays;
    public int price(){
        return carRent*carDays;
    }   
}

passengerCar类

public  class passengerCar extends Car implements carryPeople{

    public passengerCar(int carNum,String carName,int carRent){
        this.carNum = carNum;
        this.carName = carName;
        this.carRent = carRent;

    }

    @Override
    public int carryPeople(int peopleNum) {
        // TODO Auto-generated method stub
        return peopleNum;
    }
}

goodsVan类

public class goodsVan extends Car implements carryGoods{
    public goodsVan(int carNum,String carName,int carRent){
        this.carNum = carNum;
        this.carName = carName;
        this.carRent = carRent;

    }

    @Override
    public int carryGoods(int goodsNum) {
        // TODO Auto-generated method stub
        return  goodsNum;
    }
}

peopleAndGoodsCar类

public class peopleAndGoodsCar extends Car implements carryPeople,carryGoods{

    public peopleAndGoodsCar(int carNum,String carName,int carRent){
        this.carNum = carNum;
        this.carName = carName;
        this.carRent = carRent;

    }
    @Override
    public int carryGoods(int goodsNum) {
        // TODO Auto-generated method stub
        return goodsNum;
    }

    @Override
    public int carryPeople(int peopleNum) {
        // TODO Auto-generated method stub
        return peopleNum;
    }

}

carryPeople接口

public interface carryPeople {
    public abstract int carryPeople(int peopleNum);
}

carryGoods接口

public interface carryGoods {
    public int carryGoods(int goodsNum);
}

Test类

import java.util.Scanner;
public class Test 
{

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        passengerCar p1 = new passengerCar(1,"奥迪A4",500);       
        passengerCar p2 = new passengerCar(2,"马自达6",400);       
        passengerCar p4 = new passengerCar(4,"金龙",800);     
        goodsVan p5 = new goodsVan(5,"松花江",400);        
        goodsVan p6 = new goodsVan(6,"依维柯",1000);       
        peopleAndGoodsCar p3 = new peopleAndGoodsCar(3,"皮卡雪6",450);     
        System.out.println("欢迎使用答答租车系统!\n"+"请问您是否需要租车:1是0否");

        Scanner input = new Scanner(System.in);
        int receive = input.nextInt();          
        if(receive == 1){
                System.out.println("你可租车的类型及其价目表:"+"\n"+"序号 汽车名称    租金      容量"+"\n"+
            "1.  奥迪A4    500元/天     载人:4人"+"\n"+"2.  马自达6    400元/天     载人:4人"+
            "\n"+"3.     皮卡雪6    450元/天     载人:4人 载货:2吨"+"\n"+"4.    金龙      800元/天     载人:20人"
            +"\n"+"5.    松花江     400元/天     载货:4吨"+"\n"+"6.  依维柯     1000元/天        载货:20吨");
                System.out.println("请输入您要租车的数量:");          
                int needCarNum = input.nextInt();
                int sumPeople = 0 ;
                int sumGoods = 0 ;
                int sumPrice = 0 ;
                int[] num = new int[needCarNum];
                for(int i = 1 ;i<=needCarNum;i++){
                    System.out.println("请输入第"+i+"辆车的序号:");
                    num[i-1]=input.nextInt();
                }
                System.out.println("请输入租车的天数:");
                int needDays = input.nextInt(); 
                System.out.println("您的账单:\n"+"***可载人的车有:");     
                for(int i = 0;i<num.length;i++){
                    switch(num[i]){
                    case 1:
                        System.out.print("奥迪A4  ");
                        sumPeople +=p1.carryPeople(4); 
                        sumPrice +=p1.carRent;
                        break;
                    case 2:
                        System.out.print("马自达6  ");
                        sumPeople +=p2.carryPeople(4);
                        sumPrice +=p2.carRent;
                        break;
                    case 3: 
                        System.out.print("皮卡雪6  ");
                        sumPeople +=p3.carryPeople(4);
                        sumPrice +=p3.carRent;
                        break;
                    case 4:
                        System.out.print("金龙    ");
                        sumPeople +=p4.carryPeople(20);
                        sumPrice +=p4.carRent;
                        break;
                    case 5:             
                    case 6:

                        break;//不是载客的两种情况           
                    }           
                }
                System.out.println("共载客"+sumPeople+"人\n***可载货的车有:");
                for(int i = 0;i<num.length;i++){
                    switch(num[i]){
                    case 1:             
                    case 2:                                             
                    case 4:             
                        break;
                    case 3: 
                        System.out.print("皮卡雪6  ");
                        sumGoods +=p3.carryGoods(2);
                        //sumPrice +=p3.carRent;//计算钱数加一遍就够了
                        break;
                    case 5:
                        System.out.print("松花江   ");
                        sumGoods+=p5.carryGoods(4);
                        sumPrice +=p5.carRent;
                        break;

                    case 6:
                        System.out.print("依维柯   ");
                        sumGoods+=p6.carryGoods(20);
                        sumPrice +=p6.carRent;
                        break;//不是载客的两种情况
                    default:
                        System.out.println("序号"+(i+1)+"的汽车并不具有载货的功能");
                    }           
                }
                System.out.println("共载货"+sumGoods+"吨\n***租车的总价格为:"+sumPrice*needDays+"元");
        }   else {
                if(receive<0||receive>1){
                    System.out.println("输入有误!");
                }
                else{
                    System.out.println("感谢您的使用");

                }
            }
    }

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

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

評論

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

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

100積分直接送

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

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

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

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

幫助反饋 APP下載

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

公眾號

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

舉報

0/150
提交
取消