java实现简单租车系统
这篇文章主要为大家详细介绍了java实现简单租车系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下本文实例为大家分享了java实现租车系统demo,供大家参考,具体内容如下
这也是参考了mooc上的一个基础项目,所以拿来写一下。不过我的demo肯定有不好或者错误的地方,欢迎指出
1、项目功能/需求
a、展示所有可租车辆
b、选择车型、租车量
c、展示租车清单,包含:总金额、总载货量、总载客量
2、项目系统uml图
3、项目源码demo
car类
package car.rental;
public class car {
private string name;
private int rent;
private int passenger;
private double volume;
public string getname() {
return name;
}
public void setname(string name) {
this.name = name;
}
public int getrent() {
return rent;
}
public void setrent(int rent) {
this.rent = rent;
}
public int getpassenger() {
return passenger;
}
public void setpassenger(int passenger) {
this.passenger = passenger;
}
public double getvolume() {
return volume;
}
public void setvolume(double volume) {
this.volume = volume;
}
}
truck类
package car.rental;
public class truck extends car {
private string name;
private int rent;
private double volume;
public truck(string name,int rent,double volume)
{
this.name=name;
this.rent=rent;
this.volume=volume;
}
public string getname() {
return name;
}
public void setname(string name) {
this.name = name;
}
public int getrent() {
return rent;
}
public void setrent(int rent) {
this.rent = rent;
}
public double getvolume() {
return volume;
}
public void setvolume(double volume) {
this.volume = volume;
}
}
coach类
package car.rental;
public class coach extends car {
private string name;
private int rent;
private int passenger;
public coach(string name,int rent,int passenger) {
this.name=name;
this.passenger=passenger;
this.rent=rent;
}
public int getpassenger() {
return passenger;
}
public void setpassenger(int passenger) {
this.passenger = passenger;
}
public string getname() {
return name;
}
public void setname(string name) {
this.name = name;
}
public int getrent() {
return rent;
}
public void setrent(int rent) {
this.rent = rent;
}
}
pickup类
package car.rental;
public class pickup extends car {
private string name;
private int rent;
private int passenger;
private double volume;
public pickup(string name,int rent,int passenger,double volume)
{
this.name=name;
this.passenger=passenger;
this.rent=rent;
this.volume=volume;
}
public int getpassenger() {
return passenger;
}
public void setpassenger(int passenger) {
this.passenger = passenger;
}
public double getvolume() {
return volume;
}
public void setvolume(double volume) {
this.volume = volume;
}
public string getname() {
return name;
}
public void setname(string name) {
this.name = name;
}
public int getrent() {
return rent;
}
public void setrent(int rent) {
this.rent = rent;
}
}
测试类
package car.rental;
import java.util.scanner;
public class main_car {
public static void main(string[] args) {
// todo auto-generated method stub
/*****创建车对象*******/
/*car tru=new truck("拉丝货车",200,1.1);
car coa=new coach("法法客车",150,20);
car pic=new pickup("无名皮卡车",300,4,0.5);*/
car[] allcar= {new truck("拉丝货车",200,1.1),new coach("法法客车",150,20),
new pickup("无名皮卡车",300,4,0.5)};
system.out.println("请问您是否要租车:1.是 2.否");
scanner scan=new scanner(system.in);
string input=scan.next();
if(input.equals("1"))
{
int all_rent = 0;//总租金
int all_passenger=0;//总载客
double all_volume=0.0;//总载货
system.out.println("您可租车的类型及其价目");
system.out.println("序号\t汽车名称\t租金\t容量\t");
for(int i=0;i<allcar.length;i++)
{
if(allcar instanceof truck)
{
system.out.println((i+1)+"\t"+allcar.getname()+"\t"+allcar.getrent()+"\t"+"载货:"+allcar.getvolume());
}
if(allcar instanceof coach)
{
system.out.println((i+1)+"\t"+allcar.getname()+"\t"+allcar.getrent()+"\t"+"载客:"+allcar.getpassenger());
}
if(allcar instanceof pickup)
{
system.out.println((i+1)+"\t"+allcar.getname()+"\t"+allcar.getrent()+"\t"+"载客:"+allcar.getpassenger()+"载货:"+allcar.getvolume());
}
}
system.out.println("请输入您要租车的数量");
int sum=scan.nextint();
int car_order;
for(int j=0;j<sum;j++)
{
system.out.print("你要租的第"+(j+1)+"辆车的序号是:");
car_order=scan.nextint();
system.out.println();
if(allcar instanceof truck)
{
all_rent+=allcar.getrent();
all_volume+=allcar.getvolume();
}
if(allcar instanceof coach)
{
all_rent+=allcar.getrent();
all_passenger+=allcar.getpassenger();
}
if(allcar instanceof pickup)
{
all_rent+=allcar.getrent();
all_passenger+=allcar.getpassenger();
all_volume+=allcar.getvolume();
}
}
system.out.println("您的总租金是:"+all_rent);
system.out.println("您的总载货是:"+all_volume);
system.out.println("您的总载客是:"+all_passenger);
}
}
}
4、项目命令行演示结果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持CodeAE代码之家。
原文链接:https://blog.csdn.net/w_linux/article/details/79181092
http://www.zzvips.com/article/176038.html
页:
[1]