Java实现简单汽车租赁系统

发布时间:2020-08-26 11:44:27 作者:HurryRabbit
来源:脚本之家 阅读:438

本文实例为大家分享了Java实现简单汽车租赁系统的具体代码,供大家参考,具体内容如下

需求如下:  

Java实现简单汽车租赁系统

问题分析:

首先应当构建一个MotoVehicle的抽象(abstract)类,类里面包含一个brand属性,表示汽车品牌;还包含一个no属性,表示汽车牌号;

package cn.jbit.car;
 
public abstract class MotoVehicle {
 private String no;
 private String brand;
 /**
 * 无参构造方法
 */
 public MotoVehicle() {
 
 }
 /**
 * 有参构造方法
 * @param no 汽车牌号
 * @param brand 汽车品牌
 */
 public MotoVehicle(String no,String brand) {
 this.no=no;
 this.brand=brand;
 }
 
 public String getNo() {
 return no;
 }
 
 public String getBrand() {
 return brand;
 }
 public abstract int calRent(int days);
}

其次,应有Car类继承自MotoVehicle类,并有一个type属性,表示轿车型号,应有一个计算租金的方法calRent()

package cn.jbit.car;
 
public class Car extends MotoVehicle{
 private String type;
 public Car() {
 
 }
 public Car (String no,String brand,String type) {
 super(no,brand);
 this.type=type;
 }
 
 public String getType() {
 return type;
 }
 
 public void setType(String type) {
 this.type = type;
 }
 @Override
 public int calRent(int days) {
 // TODO Auto-generated method stub
 if("2".equals(type)) {
  return days*500;
 }
 else if ("1".equals(type)) {
  return days*600;
 }
 else {
  return 300*days;
 }
 } 
}

再次,应有Bus类继承自MotoVehicle类,并有一个CountSet属性,表示客车的容量,同样的,应有一个计算租金的方法calRent();

package cn.jbit.car;
 
public class Bus extends MotoVehicle {
 int CountSet;
 public Bus() {
 }
 /**
 * 带参构造函数
 */
 public Bus(String brand,String no,int CountSet) {
 super(brand,no);
 this.CountSet=CountSet; 
 }
 public int getCountSet() {
 return CountSet;
 } 
 public void setCountSet(int countSet) {
 CountSet = countSet;
 }
 
 @Override
 public int calRent(int days) {
 // TODO Auto-generated method stub
 if(CountSet<16) {
  return 800*days;
 }
 else {
  return 1600*days;
 }
 }
 
}

最后,以上三类应在test类中测试;

package cn.jbit.car;
import java.util.Scanner;
 
public class Test {
 public static void main(String[] args) {
 String no,brand,mtype;
 int countSet,days;
 Scanner input=new Scanner(System.in);
 System.out.println("*****欢迎来到汽车租赁公司!******");
 System.out.println("请输入天数:");
 days=input.nextInt();
 System.out.println("请输入车辆类型:");
 System.out.println("1、轿车  2、客车");
 mtype=input.next();
 if("1".equals(mtype)) {
  System.out.println("请输入轿车品牌:");
  System.out.println("1、宝马 2、别克");
  brand=input.next();
  if("1".equals(brand)) {
  System.out.println("2、宝马550i:500");
  System.out.println("请输入轿车型号:");
  mtype=input.next();
  System.out.println("请输入辆数:");
  int count=input.nextInt();
  Car car=new Car("辽B000",brand,mtype);
  System.out.println("您需支付:"+count*car.calRent(days));
  
  }
  else {
  System.out.println("1、别克商务GL8:600  3、别克林荫大道:300");
  mtype=input.next();
  System.out.println("请输入辆数:");
  int count=input.nextInt();
  Car car=new Car("辽B000",brand,mtype);
  System.out.println("您需支付:"+count*car.calRent(days));
  }
 }
 else {
  System.out.println("请输入品牌:");
  System.out.println("1、金杯  2、金龙");
  brand=input.next();
  System.out.println("请输入座位数:");
  countSet=input.nextInt();
  System.out.println("请输入辆数:");
  int count=input.nextInt();
  Bus b=new Bus(brand,"辽B000",countSet);
  System.out.println("您需支付:"+b.calRent(days)*count);
 }
 }
 
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。

推荐阅读:
  1. python如何实现汽车管理系统
  2. C#实现汽车租赁系统项目

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

java 汽车租赁 租赁系统

上一篇:php设置错误报告级别的方法

下一篇:apache2无法解析php的解决方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》