Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
子川3
Java
提交
fe3281ac
J
Java
项目概览
子川3
/
Java
与 Fork 源项目一致
Fork自
inscode / Java
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
Java
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
fe3281ac
编写于
5月 09, 2023
作者:
6
6459f7950975d14e43ddc890
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto commit
上级
5b0ce43e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
223 addition
and
4 deletion
+223
-4
Main.java
Main.java
+223
-4
未找到文件。
Main.java
浏览文件 @
fe3281ac
class
Main
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Hello world!"
);
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Scanner
;
public
class
CarRentalSystem
{
// 定义汽车信息类
static
class
Car
{
private
String
carId
;
private
String
make
;
private
String
model
;
private
int
year
;
private
String
color
;
private
double
price
;
public
Car
(
String
carId
,
String
make
,
String
model
,
int
year
,
String
color
,
double
price
)
{
this
.
carId
=
carId
;
this
.
make
=
make
;
this
.
model
=
model
;
this
.
year
=
year
;
this
.
color
=
color
;
this
.
price
=
price
;
}
public
String
getCarId
()
{
return
carId
;
}
public
void
setCarId
(
String
carId
)
{
this
.
carId
=
carId
;
}
public
String
getMake
()
{
return
make
;
}
public
void
setMake
(
String
make
)
{
this
.
make
=
make
;
}
public
String
getModel
()
{
return
model
;
}
public
void
setModel
(
String
model
)
{
this
.
model
=
model
;
}
public
int
getYear
()
{
return
year
;
}
public
void
setYear
(
int
year
)
{
this
.
year
=
year
;
}
public
String
getColor
()
{
return
color
;
}
public
void
setColor
(
String
color
)
{
this
.
color
=
color
;
}
public
double
getPrice
()
{
return
price
;
}
public
void
setPrice
(
double
price
)
{
this
.
price
=
price
;
}
@Override
public
String
toString
()
{
return
"Car{"
+
"carId='"
+
carId
+
'\''
+
", make='"
+
make
+
'\''
+
", model='"
+
model
+
'\''
+
", year="
+
year
+
", color='"
+
color
+
'\''
+
", price="
+
price
+
'}'
;
}
}
// 定义订单信息类
static
class
Order
{
private
String
orderId
;
private
String
carId
;
private
String
customerId
;
private
Date
rentDate
;
private
Date
returnDate
;
private
double
totalAmount
;
public
Order
(
String
orderId
,
String
carId
,
String
customerId
,
Date
rentDate
,
Date
returnDate
,
double
totalAmount
)
{
this
.
orderId
=
orderId
;
this
.
carId
=
carId
;
this
.
customerId
=
customerId
;
this
.
rentDate
=
rentDate
;
this
.
returnDate
=
returnDate
;
this
.
totalAmount
=
totalAmount
;
}
public
String
getOrderId
()
{
return
orderId
;
}
public
void
setOrderId
(
String
orderId
)
{
this
.
orderId
=
orderId
;
}
public
void
setCarId
(
String
carId
)
{
this
.
carId
=
carId
;
}
public
String
getCustomerId
()
{
return
customerId
;
}
public
void
setCustomerId
(
String
customerId
)
{
this
.
customerId
=
customerId
;
}
public
Date
getRentDate
()
{
return
rentDate
;
}
public
void
setRentDate
(
Date
rentDate
)
{
this
.
rentDate
=
rentDate
;
}
public
Date
getReturnDate
()
{
return
returnDate
;
}
public
void
setReturnDate
(
Date
returnDate
)
{
this
.
returnDate
=
returnDate
;
}
public
double
getTotalAmount
()
{
return
totalAmount
;
}
public
void
setTotalAmount
(
double
totalAmount
)
{
this
.
totalAmount
=
totalAmount
;
}
@Override
public
String
toString
()
{
return
"Order{"
+
"orderId='"
+
orderId
+
'\''
+
", carId='"
+
carId
+
'\''
+
", customerId='"
+
customerId
+
'\''
+
", rentDate="
+
rentDate
+
", returnDate="
+
returnDate
+
", totalAmount="
+
totalAmount
+
'}'
;
}
}
}
\ No newline at end of file
public
static
void
main
(
String
[]
args
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
// 初始化汽车信息
Map
<
String
,
Car
>
carMap
=
new
HashMap
<>();
carMap
.
put
(
"001"
,
new
Car
(
"001"
,
"Toyota"
,
"Camry"
,
2019
,
"White"
,
100.0
));
carMap
.
put
(
"002"
,
new
Car
(
"002"
,
"Honda"
,
"Accord"
,
2020
,
"Black"
,
120.0
));
carMap
.
put
(
"003"
,
new
Car
(
"003"
,
"Ford"
,
"Mustang"
,
2021
,
"Red"
,
150.0
));
carMap
.
put
(
"004"
,
new
Car
(
"004"
,
"BMW"
,
"X5"
,
2018
,
"Silver"
,
200.0
));
// 初始化客户信息
Map
<
String
,
String
>
customerMap
=
new
HashMap
<>();
customerMap
.
put
(
"001"
,
"John"
);
customerMap
.
put
(
"002"
,
"Mary"
);
customerMap
.
put
(
"003"
,
"David"
);
customerMap
.
put
(
"004"
,
"Alice"
);
// 初始化订单信息
List
<
Order
>
orderList
=
new
ArrayList
<>();
while
(
true
)
{
// 显示菜单
System
.
out
.
println
(
"1. Rent a car"
);
System
.
out
.
println
(
"2. Return a car"
);
System
.
out
.
println
(
"3. Display available cars"
);
System
.
out
.
println
(
"4. Display rented cars"
);
System
.
out
.
println
(
"5. Display rental history"
);
System
.
out
.
println
(
"6. Exit"
);
// 读取用户输入的选项
System
.
out
.
print
(
"Please enter your choice: "
);
int
choice
=
scanner
.
nextInt
();
switch
(
choice
)
{
case
1
:
// 租车
System
.
out
.
print
(
"Enter car ID: "
);
String
rentCarId
=
scanner
.
next
();
if
(!
carMap
.
containsKey
(
rentCarId
))
{
System
.
out
.
println
(
"Invalid car ID."
);
break
;
}
System
.
out
.
print
(
"Enter customer ID: "
);
String
customerId
=
scanner
.
next
();
if
(!
customerMap
.
containsKey
(
customerId
))
{
System
.
out
.
println
(
"Invalid customer ID."
);
break
;
}
System
.
out
.
print
(
"Enter rent date (yyyy-MM-dd): "
);
String
rentDateStr
=
scanner
.
next
();
Date
rentDate
=
new
Date
(
rentDateStr
);
Order
rentOrder
=
new
Order
(
String
.
format
(
"%d"
,
orderList
.
size
()
+
1
),
rentCarId
,
customerId
,
rentDate
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录