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"); } }
private Bidder join(XMPPAuctionHouse house, String itemId) throws AuctionIsNotAvailable { Auction auction = house.auctionFor(itemId); Bidder bidder = new Bidder(auction); auction.addAuctionEventListener(bidder); bidder.addBidderListener(new UIThreadBidderListener(new BidderDisplayer())); bidder.join(); bidder.setIdImage(idImages[idSelect]); return bidder; }
public void printItemsUtility() { String highBidder; for (int i = 0; i < Auctions.size(); i++) { // Iterate through the ArrayList of auctions generated by the scenario generator Auction auction = Auctions.get(i); if (auction.getHighBidder() == null) { highBidder = " "; } else { highBidder = auction.getHighBidder().getUserName(); } System.out.println( auction.getItem().getTitle() + " has a current high bid of $" + decFor.format(auction.getCurrentPrice()) + " and an rrp of $" + decFor.format(auction.getItem().getRrp()) + " giving it a buyer utility of $" + decFor.format(auction.getUtility()) + ". The high bidder is: " + highBidder); } System.out.println("\n"); }
@Override public void currentPrice(int price, int increment, PriceSource priceSource) { String itemId = ""; isWinning = priceSource == PriceSource.FromSniper; if (isWinning) sniperListener.sniperWinning(); else { int bid = price + increment; auction.bid(price + increment); sniperListener.sniperBidding(new SniperState(itemId, price, bid)); } }
public void printResults( ArrayList<Bidder> Bidders, ArrayList<Auction> Auctions, OptimisedBidder OptimisedBidder) { DecimalFormat decFor = new DecimalFormat("00.00"); // Print the utility that all generated bidders have made from the auction for (int i = 0; i < Bidders.size(); i++) { Bidder bidder = Bidders.get(i); double utility = 0; for (int j = 0; j < Auctions.size(); j++) { Auction auction = Auctions.get(j); if (bidder == auction.getHighBidder()) { utility = utility + auction.getUtility(); } } System.out.println( bidder.getUserName() + " has made a utility of $" + decFor.format(utility)); } double optimisedBidderutility = 0; for (int j = 0; j < Auctions.size(); j++) { Auction auction = Auctions.get(j); if (OptimisedBidder == auction.getHighBidder()) { optimisedBidderutility = optimisedBidderutility + auction.getUtility(); } } System.out.println( OptimisedBidder.getUserName() + " has made a utility of $" + decFor.format(optimisedBidderutility)); }
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, "")); }
private static void placeBid() { String ir = getRef(); double bid = 0; boolean correct = false; if (!ir.equals("cancel")) { while (!correct) { try { System.out.print("Please enter your bid in £ > "); String x = in.readLine(); bid = Double.parseDouble(x); correct = true; } catch (Exception e) { System.out.println("That's not correct"); } } System.out.println(a.placeBid(ir, loggedUser, bid)); } }
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"; }
public static void main(String[] args) { loggedUser = args[0]; try { ORB orb = ORB.init(args, null); // initialize ORB o = orb.resolve_initial_references("NameService"); // get reference to Deal object NamingContext ncRef = NamingContextHelper.narrow(o); NameComponent[] nc = new NameComponent[1]; nc[0] = new NameComponent(); nc[0].id = "Auction"; nc[0].kind = ""; a = AuctionHelper.narrow(ncRef.resolve(nc)); isr = new InputStreamReader(System.in); in = new BufferedReader(isr); int sel = 0; System.out.println("******* You have logged in Successfully! ********"); while (sel == 0) { System.out.println("Please make a selection"); System.out.println("\t1. Get all the listed auctions"); System.out.println("\t2. List a new item for auction."); System.out.println("\t3. Lookup an auction."); System.out.println("\t4. Place a bid on an auction."); System.out.println("\t5. Logout."); System.out.print("Please make your selection > "); String f = in.readLine(); try { sel = Integer.parseInt(f); } catch (Exception e) { sel = 42; } switch (sel) { case 1: allItems(); sel = 0; break; case 2: newAuction(); sel = 0; break; case 3: System.out.println("Stub"); sel = 0; break; case 4: placeBid(); sel = 0; break; case 5: a.logout(loggedUser); System.out.println("BYE!"); System.exit(0); default: System.out.println("You have not made a valid selection, please try again."); sel = 0; break; } } } catch (Exception e) { System.out.println("ERROR : " + e); e.printStackTrace(System.out); } }
@Test @SuppressWarnings({"unchecked"}) @SkipForDialect( value = {PostgreSQL81Dialect.class}, comment = "doesn't like boolean=1") public void testLazy() { Session s = openSession(); Transaction t = s.beginTransaction(); Auction a = new Auction(); a.setDescription("an auction for something"); a.setEnd(new Date()); Bid b = new Bid(); b.setAmount(new BigDecimal(123.34).setScale(19, BigDecimal.ROUND_DOWN)); b.setSuccessful(true); b.setDatetime(new Date()); b.setItem(a); a.getBids().add(b); a.setSuccessfulBid(b); s.persist(b); t.commit(); s.close(); Long aid = a.getId(); Long bid = b.getId(); s = openSession(); t = s.beginTransaction(); b = (Bid) s.load(Bid.class, bid); assertFalse(Hibernate.isInitialized(b)); a = (Auction) s.get(Auction.class, aid); assertFalse(Hibernate.isInitialized(a.getBids())); assertTrue(Hibernate.isInitialized(a.getSuccessfulBid())); assertSame(a.getBids().iterator().next(), b); assertSame(b, a.getSuccessfulBid()); assertTrue(Hibernate.isInitialized(b)); assertTrue(b.isSuccessful()); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); b = (Bid) s.load(Bid.class, bid); assertFalse(Hibernate.isInitialized(b)); a = (Auction) s.createQuery("from Auction a left join fetch a.bids").uniqueResult(); assertTrue(Hibernate.isInitialized(b)); assertTrue(Hibernate.isInitialized(a.getBids())); assertSame(b, a.getSuccessfulBid()); assertSame(a.getBids().iterator().next(), b); assertTrue(b.isSuccessful()); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); b = (Bid) s.load(Bid.class, bid); a = (Auction) s.load(Auction.class, aid); assertFalse(Hibernate.isInitialized(b)); assertFalse(Hibernate.isInitialized(a)); s.createQuery("from Auction a left join fetch a.successfulBid").list(); assertTrue(Hibernate.isInitialized(b)); assertTrue(Hibernate.isInitialized(a)); assertSame(b, a.getSuccessfulBid()); assertFalse(Hibernate.isInitialized(a.getBids())); assertSame(a.getBids().iterator().next(), b); assertTrue(b.isSuccessful()); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); b = (Bid) s.load(Bid.class, bid); a = (Auction) s.load(Auction.class, aid); assertFalse(Hibernate.isInitialized(b)); assertFalse(Hibernate.isInitialized(a)); assertSame(s.get(Bid.class, bid), b); assertTrue(Hibernate.isInitialized(b)); assertSame(s.get(Auction.class, aid), a); assertTrue(Hibernate.isInitialized(a)); assertSame(b, a.getSuccessfulBid()); assertFalse(Hibernate.isInitialized(a.getBids())); assertSame(a.getBids().iterator().next(), b); assertTrue(b.isSuccessful()); t.commit(); s.close(); }
public boolean logSales(Auction auction) { AuctionLogger al = AuctionLogger.getInstance(); al.log("Sales.txt", auction.buildMessage()); return al.findMessage("Sales.txt", auction.buildMessage()); }
public boolean chickIfIsActive(int aID) { Auction a = auctionCatalog.getAuctionByID(aID); return a.checkIfIsActive(); }
/** * Main driving method behind this entire program. Contains a simple UI so the user can interact * with the AuctionTable. * * @param args standard input arguments */ public static void main(String[] args) { boolean finished = false; Scanner sc = new Scanner(System.in); String input, parsedInput[]; AuctionTable myTable = null; String username; // Code to read the auctiontable File data = new File("data"); // Dir to hold auctions is called "data" // If it does not exist, create it if (data.exists() && data.isDirectory()) System.out.println("Data directory detected, continuing..."); else if (!data.mkdir()) System.out.println("These was a problem with creating the data directory"); else { System.out.println( "Data directory missing! Generating new Data Directory...\nData directory successfully generated..."); } // If it is empty, automatically create a new auctiontable if (data.list().length == 0) { myTable = new AuctionTable(); System.out.println("No saved data detected: generating new auction table..."); } else // If it is not, ask user if they want to load a new table { System.out.print("Saved auctions detected. Load from file? (y/n): "); String answer = sc.nextLine().toUpperCase(); if (answer.equals("Y") || answer.equals("YES")) { for (String file : data.list()) System.out.print("\"" + file + "\"" + " "); System.out.print("\nAuction to load (do not include .obj):"); String auctionToRead = "data/" + sc.nextLine() + ".obj"; try { ObjectInputStream fileIn = new ObjectInputStream(new FileInputStream(auctionToRead)); myTable = (AuctionTable) fileIn.readObject(); fileIn.close(); } catch (FileNotFoundException e) { System.out.println(auctionToRead + " was not found.\nAborting program, try again!"); sc.close(); return; } catch (Exception e) { System.out.println(e.getMessage() + ": Something went wrong"); } } else { System.out.println("New auction table generated."); myTable = new AuctionTable(); } } // Proceed as normal System.out.print("\nLOGIN - Enter your username: "******"\n(D) - Import Data from URL (WARNING: This will overwrite the current auction table\n" + "(A) - Create a New Auction\n" + "(B) - Bid on an Item\n" + "(I) - Get Info on Auction\n" + "(P) - Print All Auctions\n" + "(R) - Remove Expired Auctions\n" + "(T) - Let Time Pass\n" + "(Q) - Quit"); while (!finished) { System.out.print("> "); input = sc.nextLine().toUpperCase(); parsedInput = input.split(" "); if (parsedInput[0].equals("Q") || parsedInput[0].equals("EXIT")) { System.out.println("Exiting.."); finished = true; } else if (parsedInput[0].equals("D")) { System.out.print("URL: "); try { myTable = AuctionTable.buildFromUrl(sc.nextLine()); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } } else if (parsedInput[0].equals("A")) { // Code to add a function String newID = "", itemInfo; int timeRemaining; System.out.println("Creating a new Auction as " + username); try { System.out.print("Please enter an Auction ID: "); newID = sc.nextLine(); System.out.print("Please enter an Auction time (hours): "); timeRemaining = Integer.parseInt(sc.nextLine()); System.out.print("Please enter some Item Info: "); itemInfo = sc.nextLine(); myTable.putAuction(newID, new Auction(newID, username, itemInfo, timeRemaining)); } catch (NumberFormatException e) { System.out.println("Invalid input. Try again"); } System.out.println("Auction " + newID + " added to table."); } else if (parsedInput[0].equals("B")) { // Code to bid on an auction System.out.print("Enter an auction ID to bid on: "); try { String auctionID = sc.nextLine(); Auction toBidOn = myTable.getAuction(auctionID); if (toBidOn == null) throw new IllegalArgumentException("Auction " + auctionID + " not found."); // Checks if the auction is closed if (toBidOn.getTimeRemaining() > 0) { System.out.print( "Auction " + toBidOn.getAuctionID() + " is OPEN." + "\nCurrent Bid: $ " + toBidOn.getCurrentBid() + "\n" + "What would you like to bid?: $"); double bidAmt = Double.parseDouble(sc.nextLine()); toBidOn.newBid(username, bidAmt); System.out.println("Bid accepted."); } else { System.out.println( "Auction " + toBidOn.getAuctionID() + " is CLOSED." + "\nCurrent Bid: $ " + toBidOn.getCurrentBid() + "\n" + "You can no longer bid on this item."); } } catch (NumberFormatException e) { System.out.println("Input not valid. Try again"); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } // Technically this exception will never be thrown since it's already checked for catch (ClosedAuctionException e) { } } else if (parsedInput[0].equals("I")) { // Code to get information on a specific auction System.out.print("Enter an auction ID: "); try { myTable.printAuctionInfo(sc.nextLine()); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } } else if (parsedInput[0].equals("P")) { // Prints a neatly formatted table of auctions myTable.printTable(); } else if (parsedInput[0].equals("R")) { // Removes all closed auctions from this table System.out.println("Removing closed auctions..."); myTable.removeClosedAuctions(); System.out.println("Done."); } else if (parsedInput[0].equals("T")) { // Passes a certain number of hours over each auction System.out.print("How many hours to pass?\nHours:"); int hours = 0; try { hours = Integer.parseInt(sc.nextLine()); } catch (NumberFormatException e) { System.out.println("Invalid input. Try again"); } myTable.letTimePass(hours); } else { // Otherwise, the input was wrong System.out.println("Command not recognized. Try again"); } } // Code to save the auctiontable // save the auction as this name under "data" // Otherwise terminate the program // Prompts to save the auction table (y/n) System.out.print("Save the current auction table to file? (y/n): "); String answer = sc.nextLine().toUpperCase(); if (answer.equals("Y") || answer.equals("YES")) { // If yes, prompt for a name System.out.print("Name to save as (do not include .obj): "); String fileName = "data/" + sc.nextLine() + ".obj"; try { ObjectOutputStream fileOut = new ObjectOutputStream(new FileOutputStream(fileName)); fileOut.writeObject(myTable); fileOut.close(); System.out.println("Table saved. Goodbye!"); } catch (Exception e) { System.out.println(e.getMessage() + " : something went wrong"); } } else { System.out.print("Table not saved. Goodbye!"); } sc.close(); }
/** * This method will set owner for Fort * * @param clan * @param updateClanPoints */ public boolean setOwner(L2Clan clan, boolean updateClansReputation) { ClanHall hall = ClanHallManager.getInstance().getClanHallByOwner(clan); if (hall != null) { clan.broadcastToOnlineMembers( new SystemMessage(SystemMessageId.S1) .addString("Вы потеряли ваш кланхолл " + hall.getName())); ClanHallManager.getInstance().setFree(hall.getId()); AuctionManager.getInstance().initNPC(hall.getId()); } if (clan.getAuctionBiddedAt() > 0) { Auction a = AuctionManager.getInstance().getAuction(clan.getAuctionBiddedAt()); if (a != null) { a.cancelAuction(); clan.broadcastToOnlineMembers( new SystemMessage(SystemMessageId.S1).addString("Ваше участие в аукционе отменено")); } } if (updateClansReputation) updateClansReputation(clan, false); // update reputation first for (L2PcInstance member : clan.getOnlineMembers(0)) { giveResidentialSkills(member); member.sendSkillList(); } // Remove old owner if (getOwnerClan() != null && (clan != null && clan != getOwnerClan())) { updateClansReputation(clan, true); L2PcInstance oldLord = getOwnerClan().getLeader().getPlayerInstance(); if (oldLord != null && oldLord.getMountType() == 2) oldLord.dismount(); removeOwner(true); } setFortState(0, 0); // initialize fort state // if clan already have castle, don't store him in fortress if (clan.getHasCastle() > 0) { getSiege() .announceToPlayer( new SystemMessage(SystemMessageId.S1).addString("Форт снова пренадлежит NPC"), 0, false); return false; } else { getSpawnManager().spawnSpecialEnvoys(); ThreadPoolManager.getInstance() .scheduleGeneral( new ScheduleSpecialEnvoysDeSpawn(this), 1 * 60 * 60 * 1000); // Prepare 1hr task for special envoys despawn // if clan have already fortress, remove it if (clan.getHasFort() > 0) FortManager.getInstance().getFortByOwner(clan).removeOwner(true); setOwnerClan(clan); _ownerId = clan.getClanId(); updateOwnerInDB(); // Update in database if (getSiege().getIsInProgress()) { // If siege in progress if (Config.FORTSIEGE_REWARD_ID > 0) { clan.getWarehouse() .addItem( "Siege", Config.FORTSIEGE_REWARD_ID, Config.FORTSIEGE_REWARD_COUNT, null, null); if (clan.getLeader().getPlayerInstance() != null) clan.getLeader() .getPlayerInstance() .sendMessage( "Your clan obtain " + Config.FORTSIEGE_REWARD_COUNT + " " + ItemTable.getInstance().getItemName(Config.FORTSIEGE_REWARD_ID)); } getSiege().endSiege(); } return true; } }
public void markItemAsReceived(int aID) { Auction a = auctionCatalog.getAuctionByID(aID); a.setIsInactive(); //notifier? //tror inte det. M�ste dubbelkollas /p }
public void markItemAsSent(int aID) { Auction a = auctionCatalog.getAuctionByID(aID); a.setItemSent(); notifier.notifyItemSent(a, userCatalog.getUserByID(a.getBuyerID())); }
// Vad �r det h�r till f�r? // Vet inte s� h�r p� rak arm, vi f�r kolla upp det, kan ju vara ngt gamalt som slunkit igenom. /p public void checkIfIsPaid(int aID) { Auction a = auctionCatalog.getAuctionByID(aID); a.getIsPaid(); //notifier? }
public void chooseDeliveryType(String deliveryType, int aID) { Auction a = auctionCatalog.getAuctionByID(aID); a.setDeliveryType(deliveryType); notifier.notifyDeliveryTypeChosen(a, userCatalog.getUserByID(a.getSellerID())); }