菜鸟实在做不出来,需要一些参考,最好代码带有注释
http://www.imooc.com/article/15660
表示新手一枚,用了最笨的方法完成了。
import java.util.Scanner;
public class Car {
int num1,num2,num3,num4,num5,num6,day,b;
public Car(){
init();
}
public void init() {
System.out.println("欢迎使用答答租车系统 \n 您是否要租车:1.是 0.否");
Scanner s=new Scanner(System.in);
int a=s.nextInt();
if(a==1){
System.out.println("您可租用的类型及其价格表:");
System.out.println("序号: 汽车名称: 租金: 容量:");
System.out.println("1. 奥迪A4 500元/天 载人:4人");
System.out.println("2. 马自达6 400元/填 载人:4人");
System.out.println("3. 皮卡雪6 450元/天 载人:4 载货:2吨");
System.out.println("4. 金龙 800元/天 载人:20人 ");
System.out.println("5. 松花江 400元/天 载货:4吨");
System.out.println("6. 依维柯 1000元/天 载货:20吨");
System.out.println("请输入要租车的数量:");
b=s.nextInt();
if(b==1)
{
System.out.println("请输入一辆车的序号:");
num1=s.nextInt();
}else if(b==2)
{
System.out.println("请输入第一辆车的序号:");
num1=s.nextInt();
System.out.println("请输入第二辆车的序号:");
num2=s.nextInt();
}else if(b==3){
System.out.println("请输入第一辆车的序号:");
num1=s.nextInt();
System.out.println("请输入第二辆车的序号:");
num2=s.nextInt();
System.out.println("请输入第三辆车的序号:");
num3=s.nextInt();
}else if(b==4){
System.out.println("请输入第一辆车的序号:");
num1=s.nextInt();
System.out.println("请输入第二辆车的序号:");
num2=s.nextInt();
System.out.println("请输入第三辆车的序号:");
num3=s.nextInt();
System.out.println("请输入第四辆车的序号:");
num4=s.nextInt();
}else if(b==5){
System.out.println("请输入第一辆车的序号:");
num1=s.nextInt();
System.out.println("请输入第二辆车的序号:");
num2=s.nextInt();
System.out.println("请输入第三辆车的序号:");
num3=s.nextInt();
System.out.println("请输入第四辆车的序号:");
num4=s.nextInt();
System.out.println("请输入第五辆车的序号:");
num5=s.nextInt();
}else if(b==6){
System.out.println("请输入第一辆车的序号:");
num1=s.nextInt();
System.out.println("请输入第二辆车的序号:");
num2=s.nextInt();
System.out.println("请输入第三辆车的序号:");
num3=s.nextInt();
System.out.println("请输入第四辆车的序号:");
num4=s.nextInt();
System.out.println("请输入第五辆车的序号:");
num5=s.nextInt();
System.out.println("请输入第六辆车的序号:");
num6=s.nextInt();
}else
{
System.out.println("很抱歉,你所输入的数量超过了租车的上限!");
}
System.out.println("请输入你要租车的天数:");
int day=s.nextInt();
int mon=money(num1, num2, num3, num4, num5, num6, day);
System.out.println("您的账单为:"+mon);
}else{
System.out.println("欢迎你再次光临");
}
}
public int money(int Number1,int Number2,int Number3,int Number4,int Number5,int Number6,int day){
int count1=0,count2=0,count3 = 0,count4=0,count5=0,count6=0;
if(Number1==1){
count1=500;
}else if(Number1==2){
count1=400;
}else if(Number1==3){
count1=450;
}else if(Number1==4){
count1=800;
}else if(Number1==5){
count1=400;
}else if(Number1==6){
count1=1000;
}
if(Number2==1){
count2=500;
}else if(Number2==2){
count2=400;
}else if(Number2==3){
count2=450;
}else if(Number2==4){
count2=800;
}else if(Number2==5){
count2=400;
}else if(Number2==6){
count2=1000;
}
if(Number3==1){
count3=500;
}else if(Number3==2){
count3=400;
}else if(Number3==3){
count3=450;
}else if(Number3==4){
count3=800;
}else if(Number3==5){
count3=400;
}else if(Number3==6){
count3=1000;
}
if(Number4==1){
count4=500;
}else if(Number4==2){
count4=400;
}else if(Number4==3){
count4=450;
}else if(Number4==4){
count4=800;
}else if(Number4==5){
count4=400;
}else if(Number4==6){
count4=1000;
}
if(Number5==1){
count5=500;
}else if(Number5==2){
count5=400;
}else if(Number5==3){
count5=450;
}else if(Number5==4){
count5=800;
}else if(Number5==5){
count5=400;
}else if(Number5==6){
count5=1000;
}
if(Number6==1){
count6=500;
}else if(Number6==2){
count6=400;
}else if(Number6==3){
count6=450;
}else if(Number6==4){
count6=800;
}else if(Number6==5){
count6=400;
}else if(Number6==6){
count6=1000;
}
return (count1+count2+count3+count4+count5+count6)*day;
}
public static void main(String[] args) {
new Car();
}
}
看到回答,请送给我积分,很需要,拜托了。
同求答案
同求答案
待会告诉你