>  기사  >  Java  >  Java로 렌터카 시스템을 구현하는 세부 프로세스

Java로 렌터카 시스템을 구현하는 세부 프로세스

Y2J
Y2J원래의
2017-05-08 16:00:153300검색

이 기사에서는 주로 Java를 사용하여 Dada 자동차 렌탈 시스템을 구현하는 단계를 소개합니다. 기사에서는 자세한 구현 아이디어와 샘플 코드를 제공하고, 필요한 경우 모든 사람이 배우고 다운로드할 수 있도록 마지막에 완전한 소스 코드를 제공합니다. 참고할 수 있으니 아래를 살펴보도록 하겠습니다.

이 기사에서는 Java를 사용하여 "다다 렌터카 시스템"의 콘솔 버전을 작성하는 방법을 소개합니다. 아래에서는 자세한 구현 방법을 살펴보겠습니다.

목표 달성

"다다 렌터카 시스템" 콘솔 버전을 Java로 작성

기능 구현

1. 이용 가능한 모든 렌트 차량 조회

2. 차종 및 렌탈 수량 선택

3 . 총 금액, 총 화물 용량 및 유형, 총 승객 수용 능력 및 유형을 포함한 렌터카 목록 표시

3가지 주요 분석

데이터 모델 분석

비즈니스 모델 분석

디스플레이 및 프로세스 분석

성취효과

자동차 렌트 페이지

렌터카 요금

구현 아이디어

먼저 자동차 이름, 승객 수, 화물 용량, 일일 대여 등 기본 기능이 포함된 Car 클래스를 정의합니다. 그런 다음 승용차 클래스, 트럭 클래스, 픽업 트럭 클래스(승객과 화물을 모두 운반할 수 있음)라는 세 개의 작은 클래스를 만듭니다. 이 클래스는 모두 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("****感谢您的惠顾,欢迎再次光临!****");
 
 }
 }
 }

Harvest

아이디어가 인코딩을 결정합니다.


프로그래밍은 하향식, 단계별 설계 접근 방식에 중점을 두어야 합니다.

[관련 추천]


1.

Java 무료 동영상 튜토리얼

Java 주석 종합 분석

3.

FastJson 튜토리얼 매뉴얼

위 내용은 Java로 렌터카 시스템을 구현하는 세부 프로세스의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.