日期:2014-05-20 浏览次数:20822 次
public String [] dvd = new String [50] ; //储存DVD信息 public int[] Lendstate = new int [50] ;//借出状态,0为已借出,1为可借出 public String[] data = new String [50];//定义日期 Scanner sc = new Scanner (System.in); //借出DVD public void lentdvd (){ String lentname=""; boolean zhi = true; System.out.println("可以借出的DVD:"); for (int w=0;w<dvd.length;w++){ if (dvd[w]!=null){ System.out.println(dvd[w]); } } System.out.println("请输入需要借出的DVD:"); //for (int t=0;t<data.length;t++){ lentname = sc.next(); int random = (int)(Math.random()*49); System.out.println("请输入借出的日期(以-号分隔,参照:2012-06-01):"); String riqi = sc.next(); if (data[random]==null){ data[random]=riqi;//////////////////无法将这个值放入数组,而且在下面无法获取 } for (int r=0;r<dvd.length;r++){ if (lentname.equalsIgnoreCase(dvd[r])&&Lendstate[r]==1){ System.out.println("借出成功!"); //Lendstate=1; //定义借出成功状态 Lendstate[r]=0; zhi=true; } //} } if (zhi==false){ System.out.println("借出失败"); System.out.println(); } for (int q=0;q<data.length;q++){ if (data[q]!=null){ System.out.println(data[q]); } } } /////////////////////////////////////////////////////////归还DVD public void returndvd (){ boolean zhi = true; System.out.println("请输入DVD名称:"); String returnName = sc.next(); for (int c=0;c<data.length;c++){ if (data[c]!=null){ System.out.println(data[c]); } } System.out.println("请输入归还的日期(以-号分隔,参照:2012-06-01):"); String sReturn = sc.next();//归还的日期 String sBorrow=""; for (int e=0;e<dvd.length;e++){ if ((returnName.equalsIgnoreCase(dvd[e]))&&Lendstate[e]==0&&data[e]!=null){ zhi=true; sBorrow=data[e];/////////////这一步有错,但按照逻辑来说是没错的 } } if (zhi==true){ final double MILLS_TO_DAY = 1000d * 60 * 60 * 24; // 可以加一些格式验证 SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd"); Date borrowDate = null; Date returnDate = null; try { borrowDate = formater.parse(sBorrow); returnDate = formater.parse(sReturn); } catch (ParseException e) { e.printStackTrace(); } //else{ //System.out.println("归还失败!"); System.out.println("供需支付(元):"+(returnDate.getTime() - borrowDate.getTime())/ MILLS_TO_DAY); } }
int random = (int)(Math.random()*49); //不知道这个随机的意义是什么 System.out.println("请输入借出的日期(以-号分隔,参照:2012-06-01):"); String riqi = sc.next(); //if (data[random]==null){ // data[random]=riqi;//这里是随机保存,和DVD的位置不一致 //} for (int r=0;r<dvd.length;r++){ if (lentname.equalsIgnoreCase(dvd[r])&&Lendstate[r]==1){ System.out.println("借出成功!"); //Lendstate=1; //定义借出成功状态 Lendstate[r]=1; data[r] = riqi; //在这里设置借书日期 zhi=true; } //} }