Пример #1
1
  private static void allItems() {
    b[] bArray = a.getAllItems();
    System.out.println("******** All Current Auctions ********");
    for (int i = 0; i < bArray.length; i++) {
      System.out.println("***********************************");
      System.out.print(
          "ItemRef: "
              + bArray[i].itemRef
              + "\n\tItem Name: "
              + bArray[i].itemName
              + "\n\tPosted by: "
              + bArray[i].poster
              + "\n\tItem Description: "
              + bArray[i].itemDesc
              + "\n\tMinimum Bid: "
              + bArray[i].minBid
              + "\n\tWinning Bidder: "
              + bArray[i].winningBidder
              + "\n\t  Winning Bid: "
              + bArray[i].winningBid
              + "\n\tTime Remaining: ");
      long endMills = bArray[i].endTime;
      Calendar cal = Calendar.getInstance();
      Date now = cal.getTime();
      long nowMills = now.getTime();
      long time_remaining = endMills - nowMills;
      if (time_remaining > 0) {
        long tRSeconds = time_remaining / 1000;
        long tRMins = tRSeconds / 60;
        long tRHours = tRMins / 60;
        long tRDays = tRHours / 24;

        int hoursLeft = (int) tRHours % 24;
        int minsLeft = (int) tRMins % 60;
        int secsLeft = (int) tRSeconds % 60;

        System.out.println(
            tRDays
                + " Days, "
                + hoursLeft
                + " Hours, "
                + minsLeft
                + " Minutes, "
                + secsLeft
                + " Seconds.\n");
      } else System.out.println("Finished\n");
    }
  }
Пример #2
0
 private static void newAuction() {
   boolean correct = false;
   String iName = "";
   String iDesc = "";
   while (!correct) {
     try {
       System.out.print("Please enter the items name > ");
       iName = in.readLine();
       System.out.print("Please enter a description > ");
       iDesc = in.readLine();
       correct = true;
     } catch (Exception e) {
     }
   }
   double minBid = 0;
   try {
     System.out.print("Please enter a minimum bid > ");
     minBid = Double.parseDouble(in.readLine());
   } catch (Exception e) {
     System.out.println("Minimum bid has defaulted to 0.");
   }
   int days = 0;
   int hours = 0;
   int mins = 0;
   boolean correct2 = false;
   try {
     while (!correct2 && days >= 0 && hours >= 0 && mins >= 0) {
       System.out.print("Please enter the number of days that the Auction is running for > ");
       days = Integer.parseInt(in.readLine());
       System.out.print("Please enter the number of hours in that day > ");
       hours = Integer.parseInt(in.readLine());
       System.out.print("Please enter the number of minutes in that hour > ");
       mins = Integer.parseInt(in.readLine());
       correct2 = true;
     }
   } catch (Exception e) {
   }
   long tte = days * 86400000 + hours * 3600000 + mins * 60000;
   Calendar cal = Calendar.getInstance();
   Date d = cal.getTime();
   tte = tte + d.getTime();
   Random r = new Random();
   int rnum = (int) tte % r.nextInt(9999);
   String iRef = loggedUser.substring(loggedUser.length() / 2) + rnum;
   a.addItem(new b(iRef, loggedUser, iName, iDesc, minBid, tte, 0.0, ""));
 }