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

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

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

標(biāo)簽:
Java

版本:V1.0.2018.2.22


答答租车系统:

  1. 数据模型分析:考虑了继承和多态的特性,创建了父类Vehicle,子类CarPeople(载人)、CarGoods(载货)、CarPeoGo(载人和载货)
  2. 业务模型分析:考虑不同选车、租车、统计数据等场景,在Initial类中创建了initialVehicle(初始化车辆信息)、rentalInfo(租车信息处理-车名、金额计算等)
  3. 显示和流程分析:在Initial类中引入了play(租车系统执行-初始化信息、租车信息录入、租车信息处理、账单输出)

代码内容
Initial类

package taxi;

import java.util.Scanner;

public class Initial {
    Scanner in = new Scanner(System.in);
    Vehicle [] carShow =initialVehicle(); //用于存放车辆信息的对象
    //车辆信息的初始化
    public Vehicle[] initialVehicle() {  
        Vehicle [] car = {      
        new CarPeople(1, "奥迪A4", 500, 4),
        new CarPeople(2, "马自达6", 400, 4),
        new CarPeoGo(3, "皮卡雪6", 450, 4, 2),
        new CarPeople(4, "金龙", 800, 20),
        new CarGoods(5, "松花江", 400, 4),
        new CarGoods(6, "依维柯", 1000, 20)
        };
        return car;
    }

    //租车信息处理
    public void rentalInfo() {    
        //租车数量环节
        System.out.println("请输入您需要租汽车的数量");
        int rentalNum = in.nextInt();              //租车数量
        int [] rentalNo = new int[rentalNum];      //选择租的每一辆车序号
        for(int i=0 ; i<rentalNo.length ; i++) {
            System.out.println("请输入第"+(i+1)+"辆车的序号:");
            rentalNo[i]=in.nextInt();
        }

        //租车天数环节
        System.out.println("请输入租车天数:");
        int rentalDay = in.nextInt();         //租车天数
          //载货和载人的车和总计容量计算
        StringBuffer CarNamePeo = new StringBuffer();  //可载人的车的名字输出
        StringBuffer CarNameGo = new StringBuffer();   //可载货的车的名字输出
        int sumPeo=0;  //总载人数
        double sumGo=0.0;  //总载货书
        for(int i=0 ; i<rentalNo.length ; i++)    //载人和载货车名组合,以及容量的计算
        {
            //可载人的车处理
            if(carShow[rentalNo[i]-1] instanceof CarPeople || carShow[rentalNo[i]-1] instanceof CarPeoGo)
            {
                CarNamePeo.append(carShow[rentalNo[i]-1].getCarName());
                CarNamePeo.append(" ");
                sumPeo+=carShow[rentalNo[i]-1].getPersonsCap();
            }
            //可载货的车处理
            if(carShow[rentalNo[i]-1] instanceof CarGoods || carShow[rentalNo[i]-1] instanceof CarPeoGo)
            {
                CarNameGo.append(carShow[rentalNo[i]-1].getCarName());
                CarNameGo.append(" ");
                sumGo+=carShow[rentalNo[i]-1].getGoodsCap();
            }
        }
         //租车金额计算
        double sumRental = 0.0;
        for(int k : rentalNo) {
            sumRental+=carShow[k-1].getCarRental();
        }
        //账单输出环节
        System.out.println("您的帐单:");
        System.out.println("***可载人的车有:");
        System.out.println(CarNamePeo+" 共载人:"+sumPeo+"人");
        System.out.println("***可载货的车有:");
        System.out.println(CarNameGo+" 共载货:"+sumGo+"吨");
        System.out.println("***租车总价格:"+(sumRental*rentalDay)+"元");
        in.close();
    }

    //租车系统执行
    public void Play() {
        System.out.println("欢迎使用答答租车系统:");
        System.out.println("您是否要租车:1是 0否");
        int wp = in.nextInt();
        while(true)
        {
            if(wp==1)
            {
                System.out.println("您可租车的类型及其价目表");
                System.out.println("序号\t汽车名称\t租金\t容量");
                for(int k=0; k<carShow.length;k++) {
                    System.out.println(carShow[k]); //可以租的车信息输出
                }
                rentalInfo(); //租车信息处理环节
                break;
            }
            else
            {
                System.out.println("系统已退出");
                break;
            }
        }
        in.close();
    }

    public static void main(String[] args) {
        Initial initial = new Initial();
        initial.Play();  //租车系统启动
        System.out.println("处理完毕,系统已退出");
    }

}

Vehicle类

package taxi;

public class Vehicle {
    //属性
    private int number;
    private String carName;
    private int carRental;

    //get属性的方法
    public int getNumber() {
        return number;
    }

    public String getCarName() {
        return carName;
    }

    public int getCarRental() {
        return carRental;
    }

    public int getPersonsCap() {
        return 0;
    }

    public int getGoodsCap() {
        return 0;
    } 

    //构造方法
    public Vehicle(int number, String carName, int carRental) {
        super();
        this.number = number;
        this.carName = carName;
        this.carRental = carRental;
    }

    //重写toString方法以便输出对象信息
    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return (number+".\t"+carName+"\t"+carRental+"元/天\t");
    }   
}

CarPeople类继承Vehicle类

package taxi;

public class CarPeople extends Vehicle {
    private int personsCap;

    public CarPeople(int number, String carName, int carRental,int personCap) {
        super(number, carName, carRental);
        // TODO Auto-generated constructor stub
        this.personsCap = personCap;
    }

    public int getPersonsCap() {
        return personsCap;
    }

    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return (super.toString()+"载人:"+personsCap+"人"+"\t");
    }
}

CarGoods类继承Vehicle类

package taxi;

public class CarGoods extends Vehicle {
    private int goodsCap;

    public CarGoods(int number, String carName, int carRental , int goodsCap) {
        super(number, carName, carRental);
        // TODO Auto-generated constructor stub
        this.goodsCap=goodsCap;
    }

    public int getGoodsCap() {
        return goodsCap;
    }

    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return (super.toString()+" 载货:"+goodsCap+"吨"+"\t");
    }
}

CarPeoGo类继承Vehicle类

package taxi;

public class CarPeoGo extends Vehicle {
    private int personsCap;
    private int goodsCap;
    public CarPeoGo(int number, String carName, int carRental , int personsCap , int goodsCap) {
        super(number, carName, carRental);
        // TODO Auto-generated constructor stub
        this.personsCap = personsCap;
        this.goodsCap = goodsCap;
    }

    public int getPersonsCap() {
        return personsCap;
    }

    public int getGoodsCap() {
        return goodsCap;
    }

    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return (super.toString()+"载人:"+personsCap+"人"+" 载货:"+goodsCap+"吨"+"\t");
    }
}

输出结果:
图片描述
图片描述
图片描述

遗留问题

  1. 异常情况的处理:输入非整数、负数等情况;
  2. 业务模型部分:数据与操作的耦合度高。

请各位大神指点,谢谢!

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

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

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

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

100積分直接送

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

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

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

購課補(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
提交
取消