Esempio n. 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");
    }
  }
Esempio n. 2
0
 private static String getRef() {
   boolean correct = false;
   b[] bArray = a.getAllItems();
   String candidate = "";
   while (!correct) {
     System.out.println("Please enter the reference code of the item you want to place a bid on.");
     System.out.print("Or type 'cancel' to cancel > ");
     try {
       candidate = in.readLine();
     } catch (Exception e) {
     }
     if (!candidate.equals("cancel")) {
       for (int i = 0; i < bArray.length; i++) {
         if (bArray[i].itemRef.equals(candidate)) {
           return candidate;
         }
       }
     } else {
       return "cancel";
     }
   }
   return "cancel";
 }