Exemplo n.º 1
0
 public static void finalization() {
   Scanner input = new Scanner(System.in);
   if (AuctionType.getMainOption() != 3) {
     System.out.println("--The bidding sheet is being collected now--");
   }
   System.out.println("1. Show bidding result");
   System.out.println("2. Cancel auction");
   System.out.print("Enter: ");
   int in = input.nextInt();
   if (in == 1) {
     if (AuctionType.getMainOption() == 1) {
       Vickreyresult();
     } else if (AuctionType.getMainOption() == 2) {
       FPSBresult();
     } else if (AuctionType.getMainOption() == 3) {
       BAresult();
     }
   } else if (in == 2) {
     AuctionState c = new AuctionState(State.CANCELLED);
     c.steps();
   } else {
     finalization();
   }
 }
Exemplo n.º 2
0
 public static void FPSBresult() {
   String[] regNo = {"B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "B10"};
   List[] b = {B1, B2, B3, B4, B5, B6, B7, B8, B9, B10};
   List<String> name = new LinkedList<>();
   for (int i = 0; i < regNo.length; i++) {
     File a = new File(regNo[i] + ".txt");
     if (a.exists()) {
       b[i].addAll(sort(a));
       usableBidder.add(b[i]);
       name.add(regNo[i]);
     }
   }
   System.out.println("----------------RESULT------------------");
   String[] regItem = {"L1", "L2", "L3", "L4", "L5", "L6", "L7", "L8", "L9", "L10"};
   for (int i = 0; i < itemID.size(); i++) {
     for (int j = 0; j < regItem.length; j++) {
       // for one item, eg: L1
       int frequency = 0;
       if (itemID.get(i).equals(regItem[j])) {
         List<Double> t = new LinkedList<>();
         for (int k = 0; k < usableBidder.size(); k++) {
           t.add((Double) (usableBidder.get(k)).get(j));
           if ((Double) (usableBidder.get(k)).get(j) != 0) {
             frequency++;
           }
         }
         List<Double> tt = new LinkedList<>();
         tt.addAll(t);
         Collections.sort(tt);
         for (int l = 0; l < t.size(); l++) {
           if (tt.get(tt.size() - 1).equals(t.get(l))) {
             System.out.println("Bidding Item: " + regItem[j] + "[" + item.get(i) + "]");
             if (tt.get(tt.size() - 1) == 0) {
               System.out.println("No winner");
             } else {
               // read file
               try {
                 Scanner a = new Scanner(new FileInputStream(bidder));
                 for (int m = 0; a.hasNextLine(); m++) {
                   String s = a.nextLine();
                   String[] details = s.split(", ");
                   if (name.get(l).equals(details[0])) {
                     System.out.println(
                         "Winner: " + details[0] + "[" + details[1] + " " + details[2] + ']');
                     System.out.println("Frequency of bidding: " + frequency);
                   }
                 }
                 a.close();
               } catch (FileNotFoundException e) {
                 System.out.println("Cannot read from the file");
               }
               System.out.println("Price: " + tt.get(tt.size() - 1));
             }
           }
         }
         System.out.println("________________________________");
       }
     }
   }
   AuctionState e = new AuctionState(State.ENDED);
   e.steps();
 }