亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

Java入門第二季,鄙人解答,獻丑了

標簽:
Java

主程序

import java.util.Scanner;
/**
 * Created by romanten on 2017/11/4.
 */
public class Login {
    public static void main(String[] args) {
        System.out.println("欢迎使用哒哒租车系统!");
        System.out.println("请问您是否要租车:1是 0否");
        Scanner input = new Scanner(System.in);
        int isHire = input.nextInt();
        if (isHire==0) {
            System.out.println("好吧,欢迎再来!");
            System.exit(0);
        }else{
            System.out.println("您可租车的类型及其价目表:");
            System.out.println("序号\t汽车名称\t租金\t容量");
            Car[] forHire={new Bus("奥迪A4",500,4),
                    new Bus("马自达",400,4),
                    new PickUp("皮卡雪",450,4,2),
                    new Bus("金龙",800,20),
                    new Truck("松花江",400,4),
                    new Truck("依维柯",1000,20)};
            int i=1;
            for(Car current:forHire){ //foreach
                if(current instanceof Bus){
                    System.out.print(i++);
                    current.print_name();
                    current.print_rent();
                    System.out.println("载人量(人):"+((Bus)current).getManCapacity());
                }
                else if(current instanceof Truck){
                    System.out.print(i++);
                    current.print_name();
                    current.print_rent();
                    System.out.println("载货量(吨):"+((Truck)current).getLoadCapacity());
                }else{
                    System.out.print(i++);
                    current.print_name();
                    current.print_rent();
                    System.out.println("载人(人)"+((PickUp)current).getManCapacity()+
                            " 载货(吨):"+((PickUp)current).getLoadCapacity());
                }
            }
            System.out.print("请输入您要租车的数量:");
            int count=input.nextInt();
            int[] rentCar=new int[count];
            double sum_rent=0;
            double sum_man=0;
            double sum_load=0;
            for(i=count;i>0;i--){
                System.out.println("请输入第"+(count-i+1)+"辆车的序号:");
                rentCar[count-i]=input.nextInt();
            }
            System.out.println("请输入租车天数:");
            int rentDay=input.nextInt();
            System.out.println("您的账单:\n***可载人的车有:");
            for(i=0;i<count;i++){
                if((forHire[(rentCar[i]-1)] instanceof Bus)) {
                    forHire[(rentCar[i]-1)].print_name();
                    sum_man+=((Bus)forHire[(rentCar[i]-1)]).getManCapacity();
                    sum_rent+=((Bus)forHire[(rentCar[i]-1)]).rent;
                }
                if((forHire[(rentCar[i]-1)] instanceof PickUp)) {
                    forHire[(rentCar[i]-1)].print_name();
                    sum_man+=((PickUp)forHire[(rentCar[i]-1)]).getManCapacity();
                    sum_rent+=((PickUp)forHire[(rentCar[i]-1)]).rent;
                }
            }
            System.out.println("共载人:"+sum_man+"人");
            System.out.println("***可载货的车有:");
            for(i=0;i<count;i++){
                if((forHire[(rentCar[i]-1)] instanceof Truck)) {
                    forHire[(rentCar[i]-1)].print_name();
                    sum_load+=((Truck)forHire[(rentCar[i]-1)]).getLoadCapacity();
                    sum_rent+=((Truck)forHire[(rentCar[i]-1)]).rent;
                }
                if((forHire[(rentCar[i]-1)] instanceof PickUp)) {
                    forHire[(rentCar[i]-1)].print_name();
                    sum_load+=((PickUp)forHire[(rentCar[i]-1)]).getLoadCapacity();
                    //sum_rent+=((PickUp)forHire[(rentCar[i]-1)]).rent;
                    //皮卡即载货又载人。但是价格只算一次
                }
            }
            System.out.println("共载货:"+sum_load+"吨");
            System.out.println("***总价格:"+(sum_rent*rentDay)+"元");
        }
    }
}
點擊查看更多內容
4人點贊

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

評論

作者其他優質文章

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

100積分直接送

付費專欄免費學

大額優惠券免費領

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

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消