感觉很难 ,虽然看了老师的分析 但是还是不知道怎么入手
System.out.println("请输入你要租借的天数");
int day=input.nextInt();
System.out.println("你的账单为:");
System.out.println("******可载人的车有:");
for(int b=0;b<x;b++){
if(carNum[b]==5||carNum[b]==6){
continue;
}
System.out.print(carNames[carNum[b]-1]+",");
}
在不在?
if(carNum[b]==5||carNum[b]==6)
这句判断的是什么啊?5?6?
package dadazucheERcilianxi; import java.util.Scanner; public class dadazuche { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("欢迎使用达达租车系统"); System.out.println("你是否要租车:1是;0否"); Scanner input=new Scanner(System.in); int a=input.nextInt(); switch(a){ case 0: System.out.println("感谢关注达达租车,再见!"); break; case 1: System.out.println("您可租车的类型及其价目表:"); System.out.println("序号\t汽车名称\t租金\t容量"); String[]carNames={"奥迪A4","马自达6","皮卡雪6","金龙","松花江","依维柯"}; Audi audi=new Audi(); Mazda mazda=new Mazda(); JinLong jinlong=new JinLong(); Pickup pickup=new Pickup(); SongHuaJiang songhuajiang=new SongHuaJiang(); YiWeiKe yiweike=new YiWeiKe(); int[]zuJins={audi.zuJin,mazda.zuJin,pickup.zuJin,jinlong.zuJin,songhuajiang.zuJin,yiweike.zuJin}; int[]zairens={audi.zaiRen,mazda.zaiRen,pickup.zaiRen,jinlong.zaiRen,songhuajiang.zaiRen,yiweike.zaiRen}; int[]zaihuos={audi.zaiHuo,mazda.zaiHuo,pickup.zaiHuo,jinlong.zaiHuo,songhuajiang.zaiHuo,yiweike.zaiHuo}; String[]rongLs={audi.zaiLiang,mazda.zaiLiang,pickup.zaiLiang,jinlong.zaiLiang,songhuajiang.zaiLiang,yiweike.zaiLiang}; for(int i=0,j=0;i<6;i++,j++){ System.out.println((i+1)+"\t"+carNames[i]+"\t"+zuJins[i]+"元/天"+"\t"+rongLs[i]); } System.out.println("请输入你要租借车的数量:"); int x=input.nextInt(); int [] carNum=new int[x]; for(int y=1;y<=x;y++){ System.out.println("请输入你要租借的第"+y+"辆车的序号"); int z=input.nextInt(); carNum[y-1]=z; } System.out.println("请输入你要租借的天数"); int day=input.nextInt(); System.out.println("你的账单为:"); System.out.println("******可载人的车有:"); for(int b=0;b<x;b++){ if(carNum[b]==5||carNum[b]==6){ continue; } System.out.print(carNames[carNum[b]-1]+","); } int zongrenshu=0; for(int c=0;c<x;c++){ zongrenshu=zongrenshu+zairens[carNum[c]-1]; } System.out.println("共载人"+zongrenshu+"人!"); System.out.println("******可载货的车有:"); for(int d=0;d<x;d++){ if(carNum[d]==1||carNum[d]==2||carNum[d]==4){ continue; } System.out.print(carNames[carNum[d]-1]+","); } int zongzaihuo=0; for(int e=0;e<x;e++){ zongzaihuo=zongzaihuo+zaihuos[carNum[e]-1]; } System.out.println("共载货"+zongzaihuo+"吨"); int jiage=0; for(int f=0;f<x;f++){ jiage=jiage+zuJins[carNum[f]-1]; } int zongjiage=jiage*day; System.out.println("总价格"+zongjiage+"元"); } } }
public class Audi { String zaiLiang="载人:4人"; int zaiRen=4; int zaiHuo=0; int zuJin=500; }
public class JinLong { String zaiLiang="载人:20人"; int zaiRen=20; int zuJin=800; int zaiHuo=0; }
public class Mazda { String zaiLiang="载人:4人"; int zaiRen=4; int zuJin=400; int zaiHuo=0; }
public class Pickup { String zaiLiang="载人:4人;载货2吨"; int zaiRen=4; int zaiHuo=2; int zuJin=450; }
public class SongHuaJiang { String zaiLiang="载货4吨"; int zuJin=400; int zaiHuo=4; int zaiRen=0; }
public class YiWeiKe { String zaiLiang="载货20吨"; int zuJin=1000; int zaiHuo=20; int zaiRen=0; }
终于写出来了。
不是那么难吧。兄弟