----------------------------------------car.java-----------------------------------------------
package com.car;
public class Card {
private Integer people;
private Integer dunwei;
private Integer qian;
private String carname;
public Card(Integer people,Integer dunwei,Integer qian,String carname)
{
this.setPeople(people);
this.setDunwei(dunwei);
this.qian=qian;
this.carname=carname;
}
public Integer getPeople() {
return people;
}
public void setPeople(Integer people) {
this.people = people;
}
public Integer getDunwei() {
return dunwei;
}
public void setDunwei(Integer dunwei) {
this.dunwei = dunwei;
}
public Integer getQian() {
return qian;
}
public void setQian(Integer qian) {
this.qian = qian;
}
public String getCarname() {
return carname;
}
public void setCarname(String carname) {
this.carname = carname;
}
}
------------------------------------------Test.java--------------------------------------------
package com.car;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Test {
int[] arr=new int[50];
int sumPeople=0;
int sumDunwei=0;
int sumQian=0;
List<Card> shuzu = new ArrayList<>();
public int scanner()
{
Scanner scanner = new Scanner(System.in);
int sCanner = scanner.nextInt();
return sCanner;
}
public int caidan()
{
System.out.println("有如下这些车:");
System.out.println("序号 汽车名称 租金 容量");
Card AoDi = new Card(4,0,500,"奥迪A4");
Card MaZiDa = new Card(4,0,400,"马自达6");
Card PiKaXue = new Card(4,2,450,"皮卡雪");
Card JingNong = new Card(20,0,800,"金龙");
Card SongHuaJiang = new Card(0,4,400,"松花江");
Card YWK = new Card(0,20,1000,"以为课");
shuzu.add(AoDi);shuzu.add(MaZiDa);shuzu.add(PiKaXue);shuzu.add(JingNong);shuzu.add(SongHuaJiang);shuzu.add(YWK);
for(int i=0;i<6;i++)
{
System.out.println((i+1)+". "+shuzu.get(i).getCarname()+" "+shuzu.get(i).getQian()+"元 "+shuzu.get(i).getPeople()+"人 "+shuzu.get(i).getDunwei()+"吨");
}
System.out.println("输入你要租车的辆数:");
Test Carnum = new Test();
int carnum = Carnum.scanner();
return carnum;
}
public int xuanche(int i)
{
for(int j=1;j<=i;j++)
{
do {
System.out.println("你要的第"+j+"辆车的序号是:");
arr[j]=scanner();
}while(arr[j]>6);
}
return i;
}
public void zairen(int i)
{
for(int j=1;j<=i;j++)
{
if(arr[j]!=5&&arr[j]!=6)
{
System.out.print(shuzu.get(j-1).getCarname()+" ");
sumPeople+=shuzu.get(j-1).getPeople();
sumDunwei+=shuzu.get(j-1).getDunwei();
sumQian+=shuzu.get(j-1).getQian();
}
}
System.out.println("共载人:"+sumPeople);
}
public void zaihuo(int i)
{
for(int j=1;j<=i;j++)
{
if(arr[j]==3)
System.out.print(shuzu.get(j-1).getCarname()+" ");
if(arr[j]==5||arr[j]==6)
{
System.out.print(shuzu.get(j-1).getCarname()+" ");
sumPeople+=shuzu.get(j-1).getPeople();
sumDunwei+=shuzu.get(j-1).getDunwei();
sumQian+=shuzu.get(j-1).getQian();
}
}
System.out.println("共载货:"+sumDunwei);
}
public static void main(String[] args) {
Test CaiDan = new Test();
System.out.println("欢迎使用你爸爸的租车系统:\n你到底租不租?:1租 0不租");
int p=CaiDan.scanner();
if(p==0)
{
System.out.println("滚滚滚滚滚滚滚滚");
}
else
{
int f=CaiDan.xuanche(CaiDan.caidan());
System.out.println("输入祖车天数:");
int TianSu=CaiDan.scanner();
System.out.println("你的账单:\n****可以坐人的车:");
CaiDan.zairen(f);
System.out.println("****可以放货的车:");
CaiDan.zaihuo(f);
System.out.println("****合计"+CaiDan.sumQian*TianSu+"元");
}
}
}
-------------------------------------运行结果-------------------------------------------
欢迎使用你爸爸的租车系统:
你到底租不租?:1租 0不租
1
有如下这些车:
序号 汽车名称 租金 容量
- 奥迪A4 500元/天 载人:4
- 马自达6 400元/天 载人:4
- 皮卡雪 450元/天 载人:4 载货2
- 金龙 800元/天 载人:20
- 松花江 400元/天 载货:4
- 以为课 1000元/天 载货:20
输入你要租车的辆数:
4
你要的第1辆车的序号是:
1
你要的第2辆车的序号是:
2
你要的第3辆车的序号是:
3
你要的第4辆车的序号是:
4
输入祖车天数:
3
你的账单:
可以坐人的车:
奥迪A4 马自达6 皮卡雪 金龙 共载人:32
可以放货的车:
皮卡雪 共载货:2
****合计6450元