源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Java实现一个达达租车系统的步骤详解

  • 时间:2021-04-09 09:47 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Java实现一个达达租车系统的步骤详解
本文介绍的是利用java编写一个控制台版的“达达租车系统”,下面话不多说了,来看看详细实现方法吧。 [b]实现目标[/b] java编写一个控制台版的“达达租车系统” [b]实现功能[/b]      1.展示所有可租车辆      2.选择车型、租车量      3.展示租车清单,包含:总金额、总载货量及其车型、总载人量及其车型 [b]三大分析[/b] [b]数据模型分析[/b] [img]http://files.jb51.net/file_images/article/201704/2017426113125404.png?2017326113137[/img] [b]业务模型分析[/b] [img]http://files.jb51.net/file_images/article/201704/2017426113257679.png?201732611335[/img] [b]显示和流程分析[/b] [img]http://files.jb51.net/file_images/article/201704/2017426113323451.jpg?2017326113345[/img] [b]实现效果[/b] [b]租车页面[/b] [img]http://files.jb51.net/file_images/article/201704/2017426113517481.png?2017326113527[/img] [b]租车账单[/b] [img]http://files.jb51.net/file_images/article/201704/2017426113558407.png?201732611365[/img] [b]实现思路[/b]   首先定义一个Car类,它包含基本功能:车名、载客数、载货量、日租金。接着创建三个小类,分别是客车类、货车类和皮卡类(既能载客又能载货),它们都继承Car类。最后需要一个主类,用于开启整个系统,调用每个小类。 [b]实现代码[/b]
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('\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("租车总价格:"+price+"元");
  System.out.println('\n');
  System.out.println("****感谢您的惠顾,欢迎再次光临!****");
 
 }
 }
 }
[b]收获[/b] 思路决定编码。 编程要注重自顶而下、逐步求精的设计方法。 [b]源程序下载:[/b] github:[url=https://github.com/hubojing/Car-rental-system]https://github.com/hubojing/Car-rental-system[/url] 本地下载:[url=http://xiazai.jb51.net/201704/yuanma/Car-rental-system-master(jb51.net).rar]http://xiazai.jb51.net/201704/yuanma/Car-rental-system-master(jb51.net).rar[/url] [b]总结[/b] 以上就是这篇文章的全部内容了,希望本文的内容对大家或者使用java能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对编程素材网的支持。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部