ホームページ  >  記事  >  Java  >  Javaでレンタカーシステムを実装する詳細なプロセス

Javaでレンタカーシステムを実装する詳細なプロセス

Y2J
Y2Jオリジナル
2017-05-08 16:00:153299ブラウズ

この記事では、主に Java を使用して Dada レンタカー システムを実装する手順を紹介します。この記事では、詳細な実装アイデアとサンプル コードを示し、記事の最後には、誰もが学習してダウンロードできるように完全なソース コードを示します。 need it can 参考までに、以下を見てみましょう。

この記事では、Java を使用してコンソール バージョンの「Dada Car Rental System」を作成する方法を紹介します。以下では詳細は説明しません。詳細な実装方法を見てみましょう。

目標を達成する

Javaで「Dada Car Rental System」のコンソールバージョンを作成します

関数を実装します

1. レンタル可能なすべての車両を表示します

2.車種とレンタカーの台数

3. 総額、総貨物容量とそのモデル、総乗客定員とそのモデルを含むレンタカーリストを表示します

3つの主要な分析

データモデル分析

ビジネスモデル分析

ディスプレイとプロセス分析

成果効果

レンタカーページ

レンタカーbill

実現したアイデア

まず、車の名前、乗客数、貨物容量、日次賃料などの基本機能を含む車クラスを定義します。次に、乗用車クラス、トラック クラス、ピックアップ トラック クラス (乗客と貨物の両方を運ぶことができます) という 3 つのサブクラスを作成し、それらはすべて Car クラスを

継承します。最後に、システム全体を起動して各サブクラスを呼び出すためにメイン クラスが必要です。

実装コード

package com.jinger;
public abstract class Car {
 public int rent;//日租金
 public int people;//载客人数
 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) {
 //对各类车实例化并保存到cars数组
 Car[] cars={
 new PassageCar("奥迪A4",4,500),
 new PassageCar("马自达6",4,400),
 new Pickup("皮卡雪6",4,2,450),
 new PassageCar("金龙",20,800),
 new Truck("松花江",4,400),
 new Truck("依维柯",20,1000)};
 System.out.println("****欢迎使用达达租车系统!****");
 System.out.println("****您确认租车吗?****"+"\n"+"是(请输入1) \t 否(请输入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("****您可租车的类型及价目表****");
 System.out.println("序号"+"\t车名"+"\t载客数(人)"+"\t载货量(吨)"+"\t日租金(元/天)");
 
 //使用循环方式将各类车输出
 for(int i=0;i<cars.length;i++){
 System.out.println((i+1)+"\t"+cars[i]);
 }
 
 
 
 System.out.println("****请输入您的租车数量:****");
 int num1=in1.nextInt();
 Car[] rentcar=new Car[num1];
 int price=0;//总价格
 int totalpeople=0;//总人数
 int totalloads=0;//总载货量
 
 for(int i=0;i<num1;i++){
 System.out.println("****请输入第"+(i+1)+"辆车的序号:****");
 int numx=in1.nextInt();
 rentcar[i]=cars[numx-1];
 
 }
 System.out.println("****请输入天数:****");
 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(&#39;\n&#39;);
 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(&#39;\n&#39;);
  System.out.println("共载客:"+totalpeople+"人");
  System.out.println("共载货:"+totalloads+"吨");
  System.out.println("租车总价格:"+price+"元");
  System.out.println(&#39;\n&#39;);
  System.out.println("****感谢您的惠顾,欢迎再次光临!****");
 
 }
 }
 }

ハーベスト

アイデアがコーディングを決定します。


プログラミングでは、トップダウンの段階的な設計アプローチに焦点を当てる必要があります。

【関連おすすめ】


1.

無料のJavaビデオチュートリアル

2.

Javaアノテーションの包括的な分析

3.

FastJsonチュートリアルマニュアル

以上がJavaでレンタカーシステムを実装する詳細なプロセスの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。