慕课网-Java入门第二季实战练习-答答租车系统下载
生活随笔
收集整理的這篇文章主要介紹了
慕课网-Java入门第二季实战练习-答答租车系统下载
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
更具所學知識,編寫一個控制臺版的”答答租車系統”
功能:
1.展示所有可租車輛
2.選擇車型、租車量
3.展示租車清單,包含:總金額、總載貨量及其車型、總載人量及其車型
代碼下載地址:
http://download.csdn.net/download/qq_29132907/10248426
1.公共
package com.imooc.zuche;public class Car {private String name;private int busload;//載客量private double burden;//載貨量private double rentdaily;//日租金public String getName(){return name;}public void setName(String name){this.name=name;}public int getBusload(){return busload;}public double getBurden() {return burden;}public void setBurden(double burden) {this.burden = burden;}public double getRentdaily() {return rentdaily;}public void setRentdaily(double rentdaily) {this.rentdaily = rentdaily;}public void setBusload(int busload){this.busload=busload;} }2.載客汽車
package com.imooc.zuche;//載客汽車 public class PassengerCar extends Car {private String name;private int busload;//載客量private double rentdaily;//日租金//構造函數public PassengerCar(String name, int busload, double rentdaily) {super();this.name = name;this.busload = busload;this.rentdaily = rentdaily;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getBusload() {return busload;}public void setBusload(int busload) {this.busload = busload;}public double getRentdaily() {return rentdaily;}public void setRentdaily(double rentdaily) {this.rentdaily = rentdaily;} }3.卡車
package com.imooc.zuche;//卡車:載貨 public class Trunk extends Car {private String name;private double burden;//載貨量private double rentdaily;//日租金//構造函數public Trunk(String name, double burden, double rentdaily) {super();this.name = name;this.burden = burden;this.rentdaily = rentdaily;}public String getName() {return name;}public void setName(String name) {this.name = name;}public double getBurden() {return burden;}public void setBurden(double burden) {this.burden = burden;}public double getRentdaily() {return rentdaily;}public void setRentdaily(double rentdaily) {this.rentdaily = rentdaily;}}4.皮卡
package com.imooc.zuche;//皮卡:載客、載貨 public class pickUp extends Car {private String name;private int busload;//載客量private double burden;//載貨量private double rentdaily;//日租金public String getName() {return name;}public void setName(String name) {this.name = name;}public int getBusload() {return busload;}public void setBusload(int busload) {this.busload = busload;}public double getBurden() {return burden;}public void setBurden(double burden) {this.burden = burden;}public double getRentdaily() {return rentdaily;}public void setRentdaily(double rentdaily) {this.rentdaily = rentdaily;}public pickUp(String name, int busload, double burden, double rentdaily) {super();this.name = name;this.busload = busload;this.burden = burden;this.rentdaily = rentdaily;} }5.租車APP主函數
package com.imooc.zuche; import java.util.Scanner;//獲取控制臺輸入public class RentApp {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("**********歡迎使用答答租車系統******");Car[] dada={new PassengerCar("奧迪A4",3,500),new Trunk("東風200",10,500),new pickUp("皮卡",3,5,300),new PassengerCar("奧迪A6",3,600),new PassengerCar("豐田",3,300),new Trunk("解放60",12,500),new pickUp("皮卡200",4,8,600)};System.out.println("你是否需要租車?是:1 否:0");Scanner scan=new Scanner(System.in);int inputNum=scan.nextInt();if(inputNum==1){int totalBusload=0;//總載客量double totalBurden=0;//總載貨量double totalRent=0;//日總租金int rentDays;//租車天數int number=1;//循環輸出數組for(Car tempCar:dada){System.out.println(number+". ");//instanceof判斷是否含有PassengerCarif(tempCar instanceof PassengerCar){System.out.println("車型:"+tempCar.getName()+",載客量:"+tempCar.getBusload()+"人"+",日租金:"+tempCar.getRentdaily()+"元/日");}if(tempCar instanceof Trunk){System.out.println("車型:"+tempCar.getName()+",載貨量:"+tempCar.getBurden()+"噸"+",日租金:"+tempCar.getRentdaily()+"元/日");}if(tempCar instanceof pickUp){System.out.println("車型:"+tempCar.getName()+",載客量:"+tempCar.getBusload()+"人"+",載貨量:"+tempCar.getBurden()+"噸"+",日租金:"+tempCar.getRentdaily()+"元/日");}number++;}System.out.println("請輸入你要租車的數量:");//租車數量int count=scan.nextInt();for(int i=0;i<count;i++){System.out.println("請輸入您要選擇的第"+(i+1)+"輛車的序號");//輸入選擇車輛型號int chooseNum=scan.nextInt();System.out.println("你選擇是是第"+chooseNum+"號車型");//判斷是否包含PassengerCar類型的車if(dada[chooseNum-1] instanceof PassengerCar){System.out.println("車型:"+dada[chooseNum-1].getName()+",載客量:"+dada[chooseNum-1].getBusload()+"人"+",日租金:"+dada[chooseNum-1].getRentdaily()+"元/日");//總載客量totalBusload+=dada[chooseNum-1].getBusload();}//選擇卡車if(dada[chooseNum-1] instanceof Trunk){System.out.println("車型:"+dada[chooseNum-1].getName()+",載貨量:"+dada[chooseNum-1].getBurden()+"噸"+",日租金:"+dada[chooseNum-1].getRentdaily()+"元/日");//總載貨量totalBurden+=dada[chooseNum-1].getBurden();}//選擇皮卡if(dada[chooseNum-1] instanceof pickUp){System.out.println("車型:"+dada[chooseNum-1].getName()+",載客量:"+dada[chooseNum-1].getBusload()+"人"+",載貨量:"+dada[chooseNum-1].getBurden()+"噸"+",日租金:"+dada[chooseNum-1].getRentdaily()+"元/日");//總載客量totalBusload+=dada[chooseNum-1].getBusload();//總載貨量totalBurden+=dada[chooseNum-1].getBurden();}//日租金totalRent+=dada[chooseNum-1].getRentdaily();}System.out.println("請輸入你租車的天數");//輸入租車天數rentDays=scan.nextInt();System.out.println("你租賃了:"+count+"輛車");System.out.println("總載客量:"+totalBusload+"人");System.out.println("總載貨量:"+totalBurden+"噸");System.out.println("總租金為:"+totalRent*rentDays+"元");}else{System.out.println("你退出了租車系統");}}}6.運行結果
總結
以上是生活随笔為你收集整理的慕课网-Java入门第二季实战练习-答答租车系统下载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java web租车系统_JavaWeb
- 下一篇: 出租车系统java_基于WEB的JAVA