Java面向对象实现 * 系统
作者:勤奋的小镇青年、 发布时间:2023-05-20 07:03:06
标签:java,租赁系统
本文实例为大家分享了Java实现 * 系统的具体代码,供大家参考,具体内容如下
父类Vehicle
public abstract class Vehicle {
private String num;
private String brand;
private double rent;
//重写equals方法
public abstract boolean equals(Vehicle v);
//计算费用
public abstract double cost(int days,double rent);
//3个参数的有参构造
public Vehicle(String num, String brand, double rent) {
this.num = num;
this.brand = brand;
this.rent = rent;
}
//无参构造
public Vehicle() {
}
//get,set方法
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public double getRent() {
return rent;
}
public void setRent(double rent) {
this.rent = rent;
}
}
子类Cars
public class Cars extends Vehicle{
private String type;
//重写父类equals方法
@Override
public boolean equals(Vehicle v) {
if(v instanceof Cars){
Cars c=(Cars) v;
return this.getBrand().equals(c.getBrand())&&this.getType().equals(c.getType());
}
return false;
}
//重写父类费用方法
@Override
public double cost(int days,double sent) {
if (days>150){
return days*sent*0.7;
}else if (days>30){
return days*sent*0.8;
}else if (days>7){
return days*sent*0.9;
}else {
return days*sent;
}
}
//无参构造
public Cars() {
}
//有参构造
public Cars(String num, String brand, double rent, String type) {
super(num, brand, rent);
this.type = type;
}
//2个有参构造的方法
public Cars(String brand,String type){
super.setBrand(brand);
this.type = type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
子类Bus
public class Bus extends Vehicle{
private int seat;
//重写父类的equals方法
@Override
public boolean equals(Vehicle v) {
if(v instanceof Bus){
Bus b=(Bus) v;
return this.getBrand().equals(b.getBrand())&&this.getSeat()==b.getSeat();
}
return false;
}
//重写父类费用方法
@Override
public double cost(int days,double rent) {
if (days>=150){
return days*rent*0.6;
}else if (days>=30){
return days*rent*0.7;
}else if (days>=7){
return days*rent*0.8;
}else if (days>=3){
return days*rent*0.9;
}else {
return days*rent;
}
}
//2个参数的有参构造
public Bus(String brand,int seat){
super.setBrand(brand);
this.seat=seat;
}
//子类有参构造
public Bus(String num, String brand, double rent, int seat) {
super(num, brand, rent);
this.seat = seat;
}
//子类无参构造
public Bus(){}
//子类get set 方法
public int getSeat() {
return seat;
}
public void setSeat(int seat) {
this.seat = seat;
}
}
汽车业务类VehicleServicer
public class VehicleServicer {
public static List initVehicle(){
Vehicle v1=new Bus("京6566754","金杯",800,16);
Vehicle v2=new Bus("京9696996","金杯",1500,34);
Vehicle v3=new Bus("京8696997","金龙",800,16);
Vehicle v4=new Bus("京8696998","金龙",1500,34);
Vehicle c1 =new Cars("京NT37465","别克",300,"林荫大道");
Vehicle c2 =new Cars("京9696996","别克",600,"GLB");
Vehicle c3 =new Cars("京8696997","宝马",800,"X6");
Vehicle c4 =new Cars("京8696998","宝马",600,"550i");
//先装入数组中
Vehicle[] ve = {v1,v2,v3,v4,c1,c2,c3,c4};
//将数组转换成集合
List<Vehicle> vehicles = Arrays.asList(ve);
return vehicles;
}
}
测试类Test
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("**********欢迎光临秋明山守望者 * 公司**********");
System.out.println("1.轿车 2.客车");
System.out.print("请选择你要租赁的汽车类型:");
int type = sc.nextInt();
//桥车
Vehicle ve;
String brand;
if(type==1){
System.out.print("请选择你要租赁的汽车品牌(1.别克 2.宝马):");
int pinpai = sc.nextInt();
String model=pinpai==1?"别克":"宝马";
if(pinpai==1){
System.out.print("请输入你要租赁的汽车类型(1.X6 2.550i):");
int leixin = sc.nextInt();
brand=leixin==1?"林荫大道":"GL8";
}else {
System.out.print("请输入你要租赁的汽车类型(1.X6 2.550i):");
int leixin = sc.nextInt();
brand=leixin==1?"X6":"550i";
}
ve = new Cars(model, brand);
}else {//客车
int seat;
System.out.print("请选择你要租赁的汽车品牌(1.金龙 2.金杯):");
int pinpai = sc.nextInt();
String s=pinpai==1?"金龙":"金杯";
System.out.print("请选择你要租赁的汽车座位数(1.16座 2.34座):");
int z = sc.nextInt();
seat =z==1?16:34;
ve = new Bus(s, seat);
}
//根据选好的车型,输出车牌和总价
List<Vehicle> list = VehicleServicer.initVehicle();
for (Vehicle v:list) {
if(ve.equals(v)){
System.out.print("请输入你要租赁的天数:");
int days = sc.nextInt();
System.out.println("分配给您的汽车牌号是:"+v.getNum());
System.out.println("您需要支付的租赁费用是:"+v.cost(days,v.getRent()));
}
}
}
}
来源:https://blog.csdn.net/weixin_53106424/article/details/111911118


猜你喜欢
- Android 无障碍的全局悬浮窗可以在屏幕上添加 UI 供用户进行快捷操作,可以展示在所有应用程序之上长期展示。另一方面,在一些自动化场景
- Java中可以使用关键字synchronized进行线程同步控制,实现关键资源顺序访问,避免由于多线程并发执行导致的数据不一致性等问题。sy
- WPF在样式定义和UI动画上面相对于以前的技术有了不少的提升,下面给出WPF技术实现钟表的效果:1、Visual Studio新建一个WPF
- 废话不多说了,直接给大家贴java代码了。 import java.io.IOException;import sun.net.Telnet
- 简介API Gateway,时系统的唯一对外的入口,介于客户端和服务端之间的中间层,处理非业务功能,提供路由请求,鉴权,监控,缓存,限流等功
- 有一段时间,正则表达式学习很火热很潮流,当时在脚本之间平台一天就能看到好几个正则表达式的帖子,那段时间借助论坛以及Wrox Press出版的
- ObjectUtils.isEmpty()和null区别分配内存和赋值的区别isEmpty():判断值是否为空,即使已经分配内存,但没有赋值
- 一、Collections说明:Collcetions是集合框架中的工具,特点是方法都是静态的。二、Collections中的常见方法1,对
- 一、使用 System.Xml.Serialization类1、定义元数据引入System.Xml.Serialization命名空间。XM
- 分布式项目和传统项目的区别就是,分布式项目有多个服务,每一个服务仅仅只实现一套系统中一个或几个功能,所有的服务组合在一起才能实现系统的完整功
- 在网上找了半天,说的都没有解决我的问题,我自己花了点时间在idea中找到并解决了问题,希望可以帮助到大家。File---->setti
- 本文实例为大家分享了Android微信摇一摇功能的实现方法,供大家参考,具体内容如下import java.util.ArrayList;
- 前不久,我们发布了《选择 .NET 的 n 个理由》。它提供了对平台的高层次概述,总结了各种组件和设计决策,并承诺对所涉及的领域发表更深入的
- 为避免繁琐的注册登陆,很多平台和网站都会实现三方登陆的功能,增强用户的粘性。这篇文章主要介绍了java实现微信扫码登录第三方网站功能(原理和
- 问题描述:在用fabric集成后编译出现如下错误,Error:Cause: hostname in certificate didn'
- JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,易于阅读和编写,同时也易于机器解析和生成。同X
- 单点登录概念单点登录(Single Sign On),简称为 SSO,是目前比较流行的企业业务整合的解决方案之一。SSO的定义是在多个应用系
- 一、javaBeanjavaBean:一种类的规格编写规范javaBean在MVC设计模型中是model,又称模型层,在一般的程序中,我们称
- 本文为大家介绍了java.util.ArrayDeque类使用方法,供大家参考,具体内容如下1. ArrayDeque有两个类属性,head
- 1.相关概念Spring Boot 默认为我们提供了静态资源处理,使用 WebMvcAutoConfiguration 中的配置各种属性。建