虽然做完了,但是好像所学的大部分没用上................
package com.tata;
import java.util.ArrayList;
import java.util.Scanner;
public class Taxi {
public void Hooping() {
//显示欢迎信息
System.out.println("欢迎使用tata租车系统");
Scanner hoop=new Scanner(System.in);
//询问用户是否需要租车
System.out.println("请问您是否需要租车 1:需要 0:不需要");
int hoopa=hoop.nextInt();
//判断用户输入
if (hoopa==1 ) {
System.out.println("您可租车的类型如下");
CarInfo();
}else if (hoopa==0) {
System.out.println("谢谢");
Hooping();
}else {
System.out.println("你的输入有误,请重新输入");
Hooping();
}
hoop.close();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Taxi show=new Taxi();
show.Hooping();
}
public void CarInfo() {
//定义汽车价格属性信息
final int[] carnum = {1,2,3,4,5,6};
final String[] carname = {"奥迪A4","马自达6","皮卡 ","金龙","松花江","依维柯"};
final double[] carrmb = {500,400,450,800,400,900};
final int [] carr = {4,4,4,20,0,0};
final double[] carh = {0,0,2,0,4,20};
System.out.println("序号"+"\t"+"名称"+"\t"+"租金(元)"+"\t"+"\t"+"容量");
//根据条件列出所有车辆的信息
for (int i=0;i<carnum.length;i++) {
if (carh[i]==0) {
System.out.println(carnum[i]+"\t"+carname[i]+"\t"+carrmb[i]+"/天"+"\t"+"\t"+"载人"+carr[i]+"人");
}else
if (carr[i]==0) {
System.out.println(carnum[i]+"\t"+carname[i]+"\t"+carrmb[i]+"/天"+"\t"+"\t"+"载货"+carh[i]+"吨");
}else
System.out.println(carnum[i]+"\t"+carname[i]+"\t"+carrmb[i]+"/天"+"\t"+"\t"+"载人"+carr[i]+"人"+"\t"+"载货"+carh[i]+"吨");
}
System.out.println();
class CArnumb {
public void carnumbe() {
System.out.println("请输入你要租用汽车的数量");
Scanner carNumint=new Scanner(System.in);
//租用数量
int talNum=carNumint.nextInt();
//租用金额
double talRmb=0;
//载人数量
int talR=0;
//载货数量
double talH=0;
//保存载人汽车名字
ArrayList carnn= new ArrayList();
//保存载货汽车名字
ArrayList carnh= new ArrayList();
for (int i=0;i<talNum;i++) {
System.out.println("请输入你要租用的第"+(i+1)+"量车的序号");
int Num1=carNumint.nextInt();
int Num=Num1-1;
if (Num>=0) {
if (Num<=carnum.length) {
talRmb=talRmb+carrmb[Num];
talR=talR+carr[Num];
talH=talH+carh[Num];
if (carr[Num]!=0) {
carnn.add(carname[Num]);
}
if (carh[Num] !=0 ) {
carnh.add(carname[Num]);
}
}
else {
System.out.println("你的输入有误,请重新输入!!!!");
i--;
}
}
}
System.out.println("请输入你要租车的天数:");
int carDay=carNumint.nextInt();
System.out.println("你的帐单:");
System.out.println("可载人的车有:");
System.out.println(carnn+"一共可以载"+talR+"人");
System.out.println("可载货的车有:");
System.out.println(carnh+"一共可以载"+talH+"吨");
System.out.println("租车总金额为:"+talRmb*carDay);
carNumint.close();
System.exit(0);
}
}
CArnumb aaa=new CArnumb();
aaa.carnumbe();
}
}