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

Java實(shí)現(xiàn)一個(gè)達(dá)達(dá)租車系統(tǒng)的步驟詳解

 更新時(shí)間:2017年04月26日 11:40:17   作者:胡博靖  
這篇文章主要給大家介紹了利用Java實(shí)現(xiàn)一個(gè)達(dá)達(dá)租車系統(tǒng)的步驟,文中給出了詳細(xì)的實(shí)現(xiàn)思路和示例代碼,并在文末給出了完整的源碼供大家學(xué)習(xí)下載,需要的朋友可以參考借鑒,下面來一起看看吧。

本文介紹的是利用java編寫一個(gè)控制臺(tái)版的“達(dá)達(dá)租車系統(tǒng)”,下面話不多說了,來看看詳細(xì)實(shí)現(xiàn)方法吧。

實(shí)現(xiàn)目標(biāo)

java編寫一個(gè)控制臺(tái)版的“達(dá)達(dá)租車系統(tǒng)”

實(shí)現(xiàn)功能

     1.展示所有可租車輛

     2.選擇車型、租車量

     3.展示租車清單,包含:總金額、總載貨量及其車型、總載人量及其車型

三大分析

數(shù)據(jù)模型分析

業(yè)務(wù)模型分析

顯示和流程分析

實(shí)現(xiàn)效果

租車頁面

租車賬單

實(shí)現(xiàn)思路

  首先定義一個(gè)Car類,它包含基本功能:車名、載客數(shù)、載貨量、日租金。接著創(chuàng)建三個(gè)小類,分別是客車類、貨車類和皮卡類(既能載客又能載貨),它們都繼承Car類。最后需要一個(gè)主類,用于開啟整個(gè)系統(tǒng),調(diào)用每個(gè)小類。

實(shí)現(xiàn)代碼

package com.jinger;
public abstract class Car {
 public int rent;//日租金
 public int people;//載客人數(shù)
 public int loads;//載貨量
 public String name;//車名
public int getRent(){
 return rent;
}
public void setRent(int rent){
 this.rent=rent;
}
public int getPeople(){
 return people;
}
public void setPeople(int people){
 this.people=people;
}
public int getLoads(){
 return loads;
}
public void setLoads(int loads){
 this.loads=loads;
}
public String getName(){
 return name;
}
public void setName(String name){
 this.name=name;
}
}

客車類

package com.jinger;
public class PassageCar extends Car{
 public PassageCar(String name,int people,int rent){
 this.setName(name);
 this.setPeople(people);
 this.setRent(rent);
 
 
 }
 
 public String toString(){
 return this.getName()+"\t"+this.getPeople()+"\t\t\t\t"+this.getRent();
 }
 }

卡車類

package com.jinger;
public class Truck extends Car {
 public Truck(String name,int loads,int rent){
 this.setName(name);
 this.setLoads(loads);
 this.setRent(rent);
 }
 
 public String toString(){
 return this.getName()+"\t\t\t"+this.getLoads()+"\t\t"+this.getRent();
 }
 }

皮卡類

package com.jinger;
public class Pickup extends Car {
 public Pickup(String name,int people,int loads,int rent){
 this.setName(name);
 this.setPeople(people);
 this.setLoads(loads);
 this.setRent(rent);
 }
 
 public String toString(){
 return this.getName()+"\t"+this.getPeople()+"\t\t"+this.getLoads()+"\t\t"+this.getRent();
 }
 }

主類

package com.jinger;
import java.util.*;
public class Initial {
 public static void main(String[] args) {
 //對(duì)各類車實(shí)例化并保存到cars數(shù)組
 Car[] cars={
 new PassageCar("奧迪A4",4,500),
 new PassageCar("馬自達(dá)6",4,400),
 new Pickup("皮卡雪6",4,2,450),
 new PassageCar("金龍",20,800),
 new Truck("松花江",4,400),
 new Truck("依維柯",20,1000)};
 System.out.println("****歡迎使用達(dá)達(dá)租車系統(tǒng)!****");
 System.out.println("****您確認(rèn)租車嗎?****"+"\n"+"是(請(qǐng)輸入1) \t 否(請(qǐng)輸入2)");
 
 Scanner in1=new Scanner(System.in);
 int is=in1.nextInt();
 if(is!=1){
 System.out.println("****歡迎下次光臨!****");
 System.exit(0);
 }
 if(is==1){
 System.out.println("****您可租車的類型及價(jià)目表****");
 System.out.println("序號(hào)"+"\t車名"+"\t載客數(shù)(人)"+"\t載貨量(噸)"+"\t日租金(元/天)");
 
 //使用循環(huán)方式將各類車輸出
 for(int i=0;i<cars.length;i++){
 System.out.println((i+1)+"\t"+cars[i]);
 }
 
 
 
 System.out.println("****請(qǐng)輸入您的租車數(shù)量:****");
 int num1=in1.nextInt();
 Car[] rentcar=new Car[num1];
 int price=0;//總價(jià)格
 int totalpeople=0;//總?cè)藬?shù)
 int totalloads=0;//總載貨量
 
 for(int i=0;i<num1;i++){
 System.out.println("****請(qǐng)輸入第"+(i+1)+"輛車的序號(hào):****");
 int numx=in1.nextInt();
 rentcar[i]=cars[numx-1];
 
 }
 System.out.println("****請(qǐng)輸入天數(shù):****");
 int day=in1.nextInt();
 for(int i=0;i<num1;i++){
 price=price+rentcar[i].rent *day;
 }
 System.out.println("****您的賬單:****");
 System.out.println("已選載人車:");
 for(int i=0;i<num1;i++){
 if(rentcar[i].people!=0){
  System.out.println(rentcar[i].name+"\t");
 }
 
 totalpeople=totalpeople+rentcar[i].people;
 }
 
 System.out.println('\n');
 System.out.println("已選載貨車:");
 for(int i=0;i<num1;i++){
 if(rentcar[i].loads!=0){
  System.out.println(rentcar[i].name+"\t");
 }
  
 totalloads=totalloads+rentcar[i].loads;
 }
 
 
  System.out.println('\n');
  System.out.println("共載客:"+totalpeople+"人");
  System.out.println("共載貨:"+totalloads+"噸");
  System.out.println("租車總價(jià)格:"+price+"元");
  System.out.println('\n');
  System.out.println("****感謝您的惠顧,歡迎再次光臨!****");
 
 }
 }
 }

收獲

思路決定編碼。

編程要注重自頂而下、逐步求精的設(shè)計(jì)方法。

源程序下載:

github:https://github.com/hubojing/Car-rental-system

本地下載:http://xiazai.jb51.net/201704/yuanma/Car-rental-system-master(jb51.net).rar

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家或者使用java能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

  • Java AES加密解密的簡(jiǎn)單實(shí)現(xiàn)方法

    Java AES加密解密的簡(jiǎn)單實(shí)現(xiàn)方法

    下面小編就為大家?guī)硪黄狫ava AES加密解密的簡(jiǎn)單實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-06-06
  • Java groovy如何提升代碼運(yùn)行效率

    Java groovy如何提升代碼運(yùn)行效率

    這篇文章主要介紹了Java groovy如何提升代碼運(yùn)行效率,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Java并行處理的實(shí)現(xiàn)

    Java并行處理的實(shí)現(xiàn)

    并行計(jì)算一般是指許多指令得以同時(shí)進(jìn)行的計(jì)算模式。本文主要介紹了Java并行處理的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-07-07
  • SpringBoot集成Redis向量數(shù)據(jù)庫實(shí)現(xiàn)相似性搜索功能

    SpringBoot集成Redis向量數(shù)據(jù)庫實(shí)現(xiàn)相似性搜索功能

    Redis?是一個(gè)開源(BSD?許可)的內(nèi)存數(shù)據(jù)結(jié)構(gòu)存儲(chǔ),用作數(shù)據(jù)庫、緩存、消息代理和流式處理引擎,向量檢索的核心原理是通過將文本或數(shù)據(jù)表示為高維向量,并在查詢時(shí)根據(jù)向量的相似度進(jìn)行搜索,本文給大家介紹了SpringBoot集成Redis向量數(shù)據(jù)庫實(shí)現(xiàn)相似性搜索功能
    2024-09-09
  • Feign調(diào)用全局異常處理解決方案

    Feign調(diào)用全局異常處理解決方案

    這篇文章主要介紹了Feign調(diào)用全局異常處理解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • Java 數(shù)據(jù)結(jié)構(gòu)與算法系列精講之時(shí)間復(fù)雜度與空間復(fù)雜度

    Java 數(shù)據(jù)結(jié)構(gòu)與算法系列精講之時(shí)間復(fù)雜度與空間復(fù)雜度

    對(duì)于一個(gè)算法,其時(shí)間復(fù)雜度和空間復(fù)雜度往往是相互影響的,當(dāng)追求一個(gè)較好的時(shí)間復(fù)雜度時(shí),可能會(huì)使空間復(fù)雜度的性能變差,即可能導(dǎo)致占用較多的存儲(chǔ)空間,這篇文章主要給大家介紹了關(guān)于Java時(shí)間復(fù)雜度、空間復(fù)雜度的相關(guān)資料,需要的朋友可以參考下
    2022-02-02
  • java一個(gè)接口多個(gè)實(shí)現(xiàn)類的調(diào)用方式

    java一個(gè)接口多個(gè)實(shí)現(xiàn)類的調(diào)用方式

    這篇文章主要給大家介紹了關(guān)于java一個(gè)接口多個(gè)實(shí)現(xiàn)類的調(diào)用方式的相關(guān)資料,經(jīng)測(cè)試確認(rèn),當(dāng)一個(gè)接口有多個(gè)實(shí)現(xiàn)時(shí),調(diào)用時(shí)只會(huì)執(zhí)行一個(gè),有時(shí)候需要多個(gè)實(shí)現(xiàn)調(diào)用,需要的朋友可以參考下
    2023-09-09
  • Java中List.contains(Object?object)方法使用

    Java中List.contains(Object?object)方法使用

    本文主要介紹了Java中List.contains(Object?object)方法,使用List.contains(Object?object)方法判斷ArrayList是否包含一個(gè)元素對(duì)象,感興趣的可以了解一下
    2022-04-04
  • 淺談Java中的this作為返回值時(shí)返回的是什么

    淺談Java中的this作為返回值時(shí)返回的是什么

    Java中的this作為返回值時(shí)返回的是什么?下面小編就為大家介紹一下Java中的this作為返回值時(shí)返回。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11
  • java實(shí)現(xiàn)清理DNS Cache的方法

    java實(shí)現(xiàn)清理DNS Cache的方法

    這篇文章主要介紹了java實(shí)現(xiàn)清理DNS Cache的方法,分析了幾種常用的清理方法,并給出了反射清理的完整實(shí)例,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01

最新評(píng)論