欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java編寫汽車租賃系統(tǒng)

 更新時間:2022年02月24日 11:19:53   作者:??悲宸???  
這篇文章主要為大家詳細介紹了java編寫汽車租賃系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java編寫汽車租賃系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

題目要求:

1,汽車租賃信息表如下:

2,類和屬性:

3,運行效果:

效果實現(xiàn):

代碼實現(xiàn):

1,車類:

package homework.exam;

public abstract ?class Vehicle {
? ? private String num;
? ? private String brand;
? ? private double rent;

? ? public String getNum() {
? ? ? ? return num;
? ? }

? ? public void setNum(String num) {
? ? ? ? this.num = num;
? ? }

? ? public String getBrand() {
? ? ? ? return brand;
? ? }

? ? public void setBrand(String brand) {
? ? ? ? this.brand = brand;
? ? }

? ? public double getRent() {
? ? ? ? return rent;
? ? }

? ? public void setRent(double rent) {
? ? ? ? this.rent = rent;
? ? }

? ? public Vehicle() {
? ? }
? ? //含參構造
? ? public Vehicle(String num, String brand, double rent) {
? ? ? ? this.num = num;
? ? ? ? this.brand = brand;
? ? ? ? this.rent = rent;
? ? }

? ? @Override
? ? public String toString() {
? ? ? ? return "汽車{" +
? ? ? ? ? ? ? ? "車牌號='" + num + '\'' +
? ? ? ? ? ? ? ? ", 品牌='" + brand + '\'' +
? ? ? ? ? ? ? ? ", 日租金=" + rent +
? ? ? ? ? ? ? ? '}';
? ? }
? ? public abstract double totalmoney(int days , double rent);
? ? public abstract boolean equals(Vehicle o);
}

2,汽車類:

package homework.exam;

public class Cars extends Vehicle{
? ? private String type;


? ? public String getType() {
? ? ? ? return type;
? ? }

? ? public void setType(String type) {
? ? ? ? this.type = type;
? ? }

? ? public Cars(String brand,String type) {
? ? ? ? this.type = type;

? ? }

? ? public Cars(String num, String brand, double rent, String type) {
? ? ? ? super(num, brand, rent);
? ? ? ? this.type = type;
? ? }

? ? @Override
? ? public String toString() {
? ? ? ? return "Cars{" +
? ? ? ? ? ? ? ? "type='" + type + '\'' +
? ? ? ? ? ? ? ? '}';
? ? }

? ? //計算小汽車的總租金
? ? @Override
? ? public double totalmoney(int days, double rent) {
? ? ? ? if (days>7){
? ? ? ? ? ? return days*rent*0.9;
? ? ? ? }else if (days>30){
? ? ? ? ? ? return days*rent*0.8;
? ? ? ? }else if (days>150){
? ? ? ? ? ? return days*rent*0.7;
? ? ? ? }
? ? ? ? return days*rent;
? ? }
? ? //重寫equals方法
? ? @Override
? ? public boolean equals(Vehicle o) {
? ? ? ? if (o instanceof Cars){
? ? ? ? ? ? Cars cars= (Cars) o;
? ? ? ? ? ? return this.getType().equals(cars.getType())&&this.getBrand().equals(o.getBrand());
? ? ? ? }
? ? ? ? return false;
? ? }
}

3,客車類:

package homework.exam;

public class Bus extends Vehicle {
? ? private String seat;

? ? public String getSeat() {
? ? ? ? return seat;
? ? }

? ? public void setSeat(String seat) {
? ? ? ? this.seat = seat;
? ? }

? ? public Bus(String num, String brand, double rent, String seat) {
? ? ? ? super(num, brand, rent);
? ? ? ? this.seat = seat;
? ? }

? ? //計算客車的租金
? ? @Override
? ? public double totalmoney(int days, double rent) {
? ? ? ? if (days>=3){
? ? ? ? ? ? return days*rent*0.9;
? ? ? ? }else if (days>=7){
? ? ? ? ? ? return days*rent*0.8;
? ? ? ? }else if (days>=30){
? ? ? ? ? ? return days*rent*0.7;
? ? ? ? }else if (days>=150){
? ? ? ? ? ? return days*rent*0.6;
? ? ? ? }
? ? ? ? return days*rent;
? ? }
? ? //重寫equals方法
? ? @Override
? ? public boolean equals(Vehicle o) {
? ? ? ? return false;
? ? }
}

4,車輛管理類:

package homework.exam;

public class CarRent {
? ? //創(chuàng)建汽車數(shù)組,將汽車的信息放在數(shù)組中
? ? public Cars[] carMake(){
? ? ? ? Cars c1 = new Cars("京NY28588", "寶馬", 800, "x6");
? ? ? ? Cars c2 = new Cars("京CNY3284", "寶馬", 600, "550i");
? ? ? ? Cars c3 = new Cars("京NT37465", "別克", 300, "林蔭大道");
? ? ? ? Cars c4 = new Cars("京NT96928", "別克", 600, "GL8");
? ? ? ? Cars[] arr1 ={c1,c2,c3,c4};
? ? ? ? return arr1;
? ? }
? ? //創(chuàng)建客車數(shù)組,將汽車的信息放在數(shù)組中
? ? public Bus[] busMake(){
? ? ? ? Bus b1 = new Bus("京6566754", "金杯", 800, "16座");
? ? ? ? Bus b2 = new Bus("京8696667", "金龍", 800, "16座");
? ? ? ? Bus b3 = new Bus("京9696996", "金杯", 1500, "34座");
? ? ? ? Bus b4 = new Bus("京8696998", "金龍", 1500, "34座");
? ? ? ? Bus[] arr2={b1,b2,b3,b4};
? ? ? ? return arr2;
? ? }
}

5,業(yè)務服務類:

package homework.exam;

import java.util.Scanner;

public class CarService {
? ? public void rentcar(){
? ? ? ? System.out.println("**********歡迎光臨秋名山守望者汽車租賃公司**********");
? ? ? ? Scanner sc = new Scanner(System.in);
? ? ? ? System.out.println("1,轎車 ?2,客車");
? ? ? ? System.out.print("請輸入您要租賃的汽車類型:");
? ? ? ? int i = sc.nextInt();
? ? ? ? CarRent carRent = new CarRent(); ? ?//創(chuàng)建車庫對象
? ? ? ? Cars[] cars = carRent.carMake(); ? ?//拿到轎車數(shù)組對象
? ? ? ? Cars car=null;
? ? ? ? Bus[] buses = carRent.busMake(); ? ?//拿到客車數(shù)組對象
? ? ? ? Bus bus=null;
? ? ? ? //判斷用戶選擇的車型
? ? ? ? if (i==1){
? ? ? ? ? ? System.out.print("請選擇你要租賃的汽車品牌:(1,別克 ?2,寶馬)");
? ? ? ? ? ? int i1 = sc.nextInt();
? ? ? ? ? ? if (i1==1){
? ? ? ? ? ? ? ? System.out.print("請輸入你要租賃的汽車類型:(1,林蔭大道 2,GL8 )");
? ? ? ? ? ? }else {
? ? ? ? ? ? ? ? System.out.print("請輸入你要租賃的汽車類型:(1,x6 2,550i )");
? ? ? ? ? ? }
? ? ? ? ? ? String i2 = sc.next();
? ? ? ? ? ? //遍歷汽車數(shù)組,拿到用戶選擇的汽車
? ? ? ? ? ? for (int j = 0; j < cars.length; j++) {
? ? ? ? ? ? ? ? if (cars[j].getType().equals(i2)){ ?//當選擇的車的類型與數(shù)組中的匹配時
? ? ? ? ? ? ? ? ? ? car=cars[j]; ? ? ? ?//將車賦值給car
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? System.out.print("請輸入你要租賃的天數(shù):");
? ? ? ? ? ? int days = sc.nextInt();
? ? ? ? ? ? System.out.print("分配給你的汽車牌號是:");
? ? ? ? ? ? System.out.println(car.getNum()); ? //獲取汽車的車牌
? ? ? ? ? ? double totalmoney =0; ? ? ? ? ? //調(diào)用total
? ? ? ? ? ? totalmoney = car.totalmoney(days, car.getRent()); ? //計算用戶的租金
? ? ? ? ? ? System.out.print("你需要支付的租賃分費用是:");
? ? ? ? ? ? System.out.print(totalmoney);

? ? ? ? }else if (i==2){
? ? ? ? ? ? System.out.print("請選擇你要租賃的汽車品牌:(1,金龍 ?2,金杯)");
? ? ? ? ? ? String i2 = sc.next();
? ? ? ? ? ? System.out.print("請輸入你要租賃的汽車座位數(shù):(1,16座 ?2,34座)");
? ? ? ? ? ? String i3 = sc.next();
? ? ? ? ? ? //遍歷客車數(shù)組,拿到用戶選擇的客車
? ? ? ? ? ? for (int j = 0; j < buses.length; j++) {
? ? ? ? ? ? ? ? //當輸入的客車的車牌和座位與數(shù)組中的相等,就選出用戶選擇的車
? ? ? ? ? ? ? ? if (buses[j].getBrand().equals(i2)&&buses[j].getSeat().equals(i3)){
? ? ? ? ? ? ? ? ? ? bus=buses[j]; ? //將選擇的車輛賦值給bus
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? System.out.print("請輸入你要租賃的天數(shù):");
? ? ? ? ? ? int days = sc.nextInt();
? ? ? ? ? ? System.out.print("分配給你的汽車牌號是:");
? ? ? ? ? ? System.out.println();
? ? ? ? ? ? System.out.println(bus.getNum()); ? //拿到用戶選擇的車牌號
? ? ? ? ? ? double totalmoney = 0; ? ? ?//調(diào)用totalmoney方法
? ? ? ? ? ? totalmoney=bus.totalmoney(days, bus.getRent()); ? ? //用用戶輸入的天數(shù)。來計算租金
? ? ? ? ? ? System.out.print("你需要支付的租賃分費用是:");
? ? ? ? ? ? System.out.print(totalmoney);
? ? ? ? }
? ? }
}

6,測試類:

package homework.exam;

public class Test {
? ? public static void main(String[] args) {
? ? ? ? CarService cs = new CarService();
? ? ? ? cs.rentcar();
? ? }
}

控制臺輸入的內(nèi)容,我選擇的是輸入字符串類型,沒有按照效果圖上,如果你做的話,你可以用三元運算符來實現(xiàn)哦!

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • JAVA中的final關鍵字用法實例詳解

    JAVA中的final關鍵字用法實例詳解

    這篇文章主要介紹了JAVA中的final關鍵字用法,結合實例形式較為詳細的分析了Java中的final關鍵字用于修飾數(shù)據(jù),方法及類的具體使用技巧,需要的朋友可以參考下
    2015-12-12
  • SpringBoot配置外部靜態(tài)資源映射問題

    SpringBoot配置外部靜態(tài)資源映射問題

    這篇文章主要介紹了SpringBoot配置外部靜態(tài)資源映射問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • 如何在java 8 map中使用stream

    如何在java 8 map中使用stream

    這篇文章主要介紹了如何在java 8 map中使用stream,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-04-04
  • Eureka源碼解析服務離線狀態(tài)變更

    Eureka源碼解析服務離線狀態(tài)變更

    這篇文章主要為大家介紹了Eureka源碼解析服務離線的狀態(tài)變更示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-10-10
  • Centos6.5下Jdk+Tomcat+Mysql環(huán)境安裝圖文教程

    Centos6.5下Jdk+Tomcat+Mysql環(huán)境安裝圖文教程

    這篇文章主要為大家詳細介紹了Centos6.5系統(tǒng)下Jdk+Tomcat+Mysql環(huán)境安裝過程,感興趣的小伙伴們可以參考一下
    2016-05-05
  • java字符串求并集的方法

    java字符串求并集的方法

    這篇文章主要介紹了java字符串求并集的方法,涉及Java字符串操作中union方法的使用,是Java字符串操作中非常實用的基本技巧,需要的朋友可以參考下
    2014-11-11
  • Java實現(xiàn)屏幕截圖工具的代碼分享

    Java實現(xiàn)屏幕截圖工具的代碼分享

    這篇文章主要為大家介紹了如何利用Java語言編寫一個電腦屏幕截圖工具,文中的示例代碼講解詳細,對我們學習有一定的幫助,需要的可以參考一下
    2022-05-05
  • Quartz定時任務管理方式(動態(tài)添加、停止、恢復、刪除定時任務)

    Quartz定時任務管理方式(動態(tài)添加、停止、恢復、刪除定時任務)

    這篇文章主要介紹了Quartz定時任務管理方式(動態(tài)添加、停止、恢復、刪除定時任務),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • java中如何判斷JSONObject是否存在某個Key

    java中如何判斷JSONObject是否存在某個Key

    這篇文章主要介紹了java中如何判斷JSONObject是否存在某個Key,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • Maven屬性與版本管理詳細步驟分解

    Maven屬性與版本管理詳細步驟分解

    這篇文章主要介紹了Maven中關于屬性與版本控制管理的步驟操作,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-08-08

最新評論