小白自己写的源码,求大神们给点意见
package com.zuche; public class Car { private int num; private String carName; private int momey; private int people; private int carGo; public int getCarGo() { return carGo; } public void setCarGo(int carGo) { this.carGo = carGo; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } public String getCarName() { return carName; } public void setCarName(String carName) { this.carName = carName; } public int getMomey() { return momey; } public void setMomey(int momey) { this.momey = momey; } public int getPeople() { return people; } public void setPeople(int people) { this.people = people; } }
package com.zuche; import java.util.Arrays; import java.util.Scanner; public class Initail { //判断选择的车的序号是否重复的功能没做 public static void main(String[] args) { System.out.println("************欢迎使用答答租车系统************"); System.out.println("您是否要租车:1是 0否"); Scanner scanner = new Scanner(System.in); int inputNum = scanner.nextInt(); if (inputNum==0) { System.out.println("好的,下次再见。"); }else{ Initail initail = new Initail(); while (inputNum>1) { System.out.println("请输入1或0"); inputNum = scanner.nextInt(); } initail.fangfa(); } // TODO Auto-generated method stub } public void fangfa(){ Scanner scanner = new Scanner(System.in); System.out.println("您可租车的类型及其价目表:"); System.out.println("序号 汽车名称 租金 容量"); Car aodi = new aodi(); System.out.println(aodi.getNum()+". "+aodi.getCarName()+" "+aodi.getMomey()+"元/天"+" "+"载人:"+aodi.getPeople()+"人"); Car mazida = new mazida(); System.out.println(mazida.getNum()+". "+mazida.getCarName()+" "+mazida.getMomey()+"元/天"+" "+"载人:"+mazida.getPeople()+"人"); Car pika = new pika(); System.out.println(pika.getNum()+". "+pika.getCarName()+" "+pika.getMomey()+"元/天"+" "+"载人:"+pika.getPeople()+"人"+" "+"载货:"+pika.getCarGo()+"吨"); Car jinlong = new jinlong(); System.out.println(jinlong.getNum()+". "+jinlong.getCarName()+" "+jinlong.getMomey()+"元/天"+" "+"载人:"+jinlong.getPeople()+"人"); Car songhuajiang = new songhuajiang(); System.out.println(songhuajiang.getNum()+". "+songhuajiang.getCarName()+" "+songhuajiang.getMomey()+"元/天"+" "+"载货:"+songhuajiang.getCarGo()+"吨"); Car yiwike = new yiweike(); System.out.println(yiwike.getNum()+". "+yiwike.getCarName()+" "+yiwike.getMomey()+"元/天"+" "+"载货:"+yiwike.getCarGo()+"吨"); System.out.println("请输入您要租汽车的数量"); int shuliang = scanner.nextInt(); int save[] = new int[shuliang]; for (int i = 1; i < shuliang+1; i++) { System.out.println("请输入您想选择的第"+i+"辆车的序号"); System.out.println("(注意:请不要输入重复的序号,否则会重复计算!!!)"); int xuhao = scanner.nextInt(); save[i-1]=xuhao; while (xuhao<=0||xuhao>6) { System.out.println("请输入正确的序号"); System.out.println("(注意:请不要输入重复的序号,否则会重复计算!!!)"); xuhao = scanner.nextInt(); save[i-1]=xuhao; } } System.out.println("请输入租车天数"); int tianshu = scanner.nextInt(); Car car[] = {aodi,mazida,pika,jinlong,songhuajiang,yiwike}; System.out.println("您的账单:"); System.out.println("***可载人的车有:"); int zairen = 0; for (int i = 0; i < save.length; i++) { if (car[save[i]-1].getPeople()!=0) { zairen+=car[save[i]-1].getPeople(); System.out.print(car[save[i]-1].getCarName()+"\t"); } } System.out.println("共载人:"+zairen+"人"); System.out.println("\n***载货的车有:"); int zaihuo = 0; for (int i = 0; i < save.length; i++) { zaihuo+=car[save[i]-1].getCarGo(); if (car[save[i]-1].getCarGo()!=0) { System.out.print(car[save[i]-1].getCarName()+"\t"); } } System.out.println("共载货:"+zaihuo+"吨"); int sum = 0; for (int i = 0; i < save.length; i++) { sum+=car[save[i]-1].getMomey(); } sum=sum*tianshu; System.out.println("\n***租车总价格:"+sum+"元"); } }
其他类的代码就不贴了,我想问一下判断输入的序号是否重复该怎么做