double priceHike(long minid, long maxid, double rate) { Map<Long, Item> rangeMap = ((TreeMap<Long, Item>) getStorage().getIdItemsMap()).subMap(minid, true, maxid, true); double totalIncrement = 0; if (rangeMap != null && rangeMap.size() > 0) { for (Map.Entry<Long, Item> rangeMapEntry : rangeMap.entrySet()) { Item item = rangeMapEntry.getValue(); double previousPrice = item.getPrice(); double increment = previousPrice * (rate / 100d); double newPrice = roundOff(previousPrice + increment); // adjust previousDescription getStorage().updateDescriptionDataSet(item, null, newPrice, previousPrice); // adjust previousPrice getStorage().updatePriceDataSet(item, previousPrice); // cumulative increments totalIncrement += roundOff(increment); } } return roundOff(totalIncrement); }
/** * searches all registry lists for a specific keyword and returns all matches in a a list * * <p>function is obsolete since 1.19 * * @param req the "search keyword" * @return list of matching objects */ public ArrayList<Object> search(String req) { ArrayList<Object> returnValues = new ArrayList<Object>(); for (Customer c : getCustomers().values()) { if (c.getName().contains(req) || c.getAddress().contains(req) || c.getCivic().contains(req) || c.getPhone().contains(req)) { returnValues.add(c); } } for (Item i : getItems().values()) { if (i.getName().contains(req) || i.getPrice().contains(req) || i.getDetails().contains(req)) { returnValues.add(i); } } for (Order i : getOrders().values()) { if (i.getOrderNo().contains(req) || i.getCustomer().getName().contains(req)) { returnValues.add(i); } } return returnValues; }
public static void main(String args[]) { Item item = new Item(); EComsite ecom = new EComsite(); ecom.choosePaymentMethod("COD"); ecom.makePayment(item.getPrice()); }
/** * Returns the price of the {@link Order} calculated from the contained items. * * @return will never be {@literal null}. */ public MonetaryAmount getPrice() { MonetaryAmount result = MonetaryAmount.ZERO; for (Item item : items) { result = result.add(item.getPrice()); } return result; }
/** * Method return the output of the ticket calculating the taxes * * @return a string representing the ticket to print */ public String print() { StringBuffer sb = new StringBuffer(); for (Item item : itemList) { sb.append(item.toString()); calculateTotal(item.getPrice(), item.getTax().getTaxValue()); } sb.append("Sales Taxes: ").append(this.totalTax.toString()).append("\n"); sb.append("Total: ").append(this.total.toString()).append("\n"); return sb.toString(); }
public void buyItemFromUser(User buyer, User seller, Item currentItem) // PRE: buyer, seller, currentItem must be initialized // POST: Purchases item from the store and has stores it into inventory. { int buyer_balance; // The new balance of the buyer int seller_balance; // The new balance of the seller String str; // First query String str2; // Second query String str3; // Third query buyer_balance = buyer.getBalance() - currentItem.getPrice(); seller_balance = seller.getBalance() + currentItem.getPrice(); if (buyer_balance > 0) // If the buyer wont go negative { str = String.format( "Update users set balance = (%d) where user_name = '%s'", buyer_balance, buyer.getUserName()); str2 = String.format( "Update users set balance = (%d) where user_name = '%s'", seller_balance, seller.getUserName()); str3 = String.format( "Update items set owner_id = (%d) where item_name = '%s'", buyer.getUserId(), currentItem.getItemName()); updateTables(str, str2, str3); } else { // Prompt the user with an error JOptionPane.showMessageDialog( null, "You will go bankrupt if you try buying that, try selling some items."); } }
public static void main(String[] args) { Item item; String itemName; double itemPrice; int quantity; ArrayList<Item> cart = new ArrayList<Item>(); Scanner scan = new Scanner(System.in); String keepShopping = "y"; NumberFormat fmt = NumberFormat.getCurrencyInstance(); do { System.out.print("Enter the name of the item: "); itemName = scan.nextLine(); System.out.print("Enter the unit price: "); itemPrice = scan.nextDouble(); System.out.print("Enter the quantity: "); quantity = scan.nextInt(); // *** create a new item and add it to the cart item = new Item(itemName, itemPrice, quantity); cart.add(item); // *** print the contents of the cart object using println System.out.println(); // System.out.println(cart); double totalprice = 0; for (Item myitem : cart) { System.out.println( myitem.getName() + ": " + myitem.getQuantity() + "*" + fmt.format(myitem.getPrice())); totalprice += myitem.getQuantity() * myitem.getPrice(); } System.out.println("Total price: " + fmt.format(totalprice)); System.out.println(); System.out.print("Continue shopping (y/n)?"); scan.nextLine(); // go to next line. keepShopping = scan.nextLine(); System.out.println(); } while (keepShopping.equals("y")); System.out.print("done"); }
/** * An insert operation to the MDSItemStorage. * * @param id * @param price * @param description * @param size * @return */ int insert(long id, double price, long[] description, int size) { if (find(id) != 0) { Item previousItem = findItem(id); Double previousPrice = previousItem.getPrice(); List<Long> previousDescription = previousItem.getDescription(); if (size > 0) { Integer previousDescriptionHash = previousItem.getDescriptionHash(); // Description of item is in description[0..size-1]. copy them into your data structure. previousItem.setDescription(size, (size == 0) ? null : description); // adjust previousDescription getStorage() .updateDescriptionDataSet( previousItem, previousDescription, price, (previousPrice == price ? null : previousPrice)); // adjust previousPrice getStorage().updatePriceDataSet(previousItem, previousPrice); // refresh and re-check associated same-same hash with the previous item. getStorage().addressSameSameHashing(previousItem, previousDescriptionHash); } else { if (previousPrice != price) { if (size == 0) getStorage().updateDescriptionDataSet(previousItem, null, price, previousPrice); // adjust previousPrice getStorage().updatePriceDataSet(previousItem, previousPrice); } } return 0; } // create the Item object. Item item = new Item(); item.setId(id).setPrice(price).setDescription(size, (size == 0) ? null : description); // register new item getStorage().registerItem(item); return 1; }
private void SetListText(TextLabel rowOne, TextLabel rowTwo, Item currentItem) { if (currentItem instanceof Album) { rowOne.SetText( String.format("Artist: %s; Album: %s", currentItem.getCreator(), currentItem.getName())); rowTwo.SetText( String.format( "Genre: %s; Year: %d; Rating: %.2f; Cost: %.2f", currentItem.getGenre(), currentItem.getYearOfRelease(), currentItem.getRating(), currentItem.getPrice())); } else if (currentItem instanceof Film) { rowOne.SetText( String.format( "Title: %s; Producer: %s", currentItem.getName(), currentItem.getCreator())); rowTwo.SetText( String.format( "Genre: %s; Year: %d; Rating: %.2f; Cost: %.2f", currentItem.getGenre(), currentItem.getYearOfRelease(), currentItem.getRating(), currentItem.getPrice())); } else if (currentItem instanceof Audiobook) { rowOne.SetText( String.format( "Title: %s; Author: %s", currentItem.getName(), currentItem.getCreator(), currentItem.getRating())); rowTwo.SetText( String.format( "Genre: %s; Year: %d; Rating: %.2f; Cost: %.2f", currentItem.getGenre(), currentItem.getYearOfRelease(), currentItem.getRating(), currentItem.getPrice())); } }
@Override public boolean equals(Object object) { if (!super.equals(object)) { return false; } if (!(object instanceof Item)) { return false; } if (this == object) { return true; } Item rhs = (Item) object; return rhs.getPrice() == this.price; }
/** * Get a line item to put in the database * * @param id for the line item * @param warehouse for the station * @param Station station * @param Customer customer * @param Order order * @param ArrayList<Item> itemList * @return lineItem */ public LineItem getLineItem( int id, Warehouse warehouse, Station station, Customer customer, Order order, ArrayList<Item> itemList) { LineItem lineItem = new LineItem(); Item item = itemList.get(randInt(0, itemList.size())); int numOrdered = randInt(1, 5); if (item.getCurrentStock() < numOrdered) return null; lineItem.setLineItemID(id); lineItem.setOrderID(order.getOrderID()); lineItem.setItemID(item.getItemID()); lineItem.setCustomerID(customer.getCustomerID()); lineItem.setWarehouseID(warehouse.getWarehouseID()); lineItem.setStationID(station.getStationID()); lineItem.setNumOrdered(numOrdered); lineItem.setAmountDue(item.getPrice().multiply(new BigDecimal(lineItem.getNumOrdered()))); lineItem.setAmountDue( lineItem.getAmountDue().add(station.getSalesTax().multiply(lineItem.getAmountDue()))); lineItem.setAmountDue( lineItem.getAmountDue().subtract(customer.getDiscount().multiply(lineItem.getAmountDue()))); lineItem.setDateDelivered(randDate()); item.setNumLineItems(item.getNumLineItems() + 1); item.setNumSold(item.getNumSold() + lineItem.getNumOrdered()); // item.setCurrentStock(item.getCurrentStock() - lineItem.getNumOrdered()); don't modify stock // counts for random generation customer.setTotalPaid(customer.getTotalPaid().add(lineItem.getAmountDue())); station.setTotalSales(station.getTotalSales().add(lineItem.getAmountDue())); warehouse.setTotalSales(warehouse.getTotalSales().add(lineItem.getAmountDue())); return lineItem; }
private void SetModify(int itemIndex) { Item current = DataLoader.getItemById(itemIndex); if (current != null) { CurrentModifyWindowId = itemIndex; ModifyItem.SetParent(MainFrame); Driver.GetGuiMain().GetTextBoxes(); ((TextLabel) ModifyItem.GetChild("Id")).SetText("ID #" + itemIndex); ((TextBox) ModifyItem.GetChild("TitleInput")).SetText(current.getName()); ((TextBox) ModifyItem.GetChild("ArtistInput")).SetText(current.getCreator()); ((TextBox) ModifyItem.GetChild("YearInput")).SetText("" + current.getYearOfRelease()); ((TextBox) ModifyItem.GetChild("GenreInput")).SetText(current.getGenre()); ((TextBox) ModifyItem.GetChild("CostInput")).SetText("" + current.getPrice()); ((TextBox) ModifyItem.GetChild("DurationInputH")).SetText("" + current.getHour()); ((TextBox) ModifyItem.GetChild("DurationInputM")).SetText("" + current.getMinute()); ((TextBox) ModifyItem.GetChild("DurationInputS")).SetText("" + current.getSecond()); ((TextBox) ModifyItem.GetChild("PreviewInput")).SetText("" + current.getPreview()); ((CheckBox) ModifyItem.GetChild("HiddenInput")).SetSelected(current.isVisible()); ((CheckBox) ModifyItem.GetChild("HiddenInput")) .SetText( ((CheckBox) ModifyItem.GetChild("HiddenInput")).GetSelected() ? "true" : "false"); } }
public void addItem(Item item) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_UPC, item.getUpc()); values.put(KEY_NAME, item.getName()); values.put(KEY_SUPPLIER, item.getSupplier()); values.put(KEY_PRICE, item.getPrice()); int numberOfResults = getItemCount(); // Delete last row in DB when there are more than 10 results if (numberOfResults > 9) { db.execSQL( "DELETE FROM " + TABLE_NAME + " WHERE id = (SELECT MIN(id) FROM " + TABLE_NAME + ")"); // db.delete(TABLE_NAME,"id = MIN(id)",null); } // Inserting Row db.insert(TABLE_NAME, null, values); db.close(); // Closing database connection }
public void addItem(Item item) { items.add(item); setValue(this.value + item.getPrice()); }
public void addItem(Item i) { this.items.add(i); this.total += i.getPrice(); }
private void drawItem(Graphics g, int item, Item currentItem) { Font font; // The font to be used. int x1; // The first x coordinate of drawing area. int y1; // The first y coordinate of drawing area. int x2; // The second x coordinate of drawing area. int y2; // The second y coordinate of drawing area. int width; // Width of drawing area. int height; // Height of drawing area. int iconX; // x coordinate of the icon. int iconY; // y coordinate of the icon. int iconLength; // Length of the icon. int itemNameX; // The x coordinate of the item name. int itemNameLength; // The length of the item name. int itemPriceX; // The x coordinate of the item price. int itemPriceWidth; // The width of the item price. x1 = itemPositions[item][0].getScaledX(); x2 = itemPositions[item][1].getScaledX(); y1 = itemPositions[item][0].getScaledY(); y2 = itemPositions[item][1].getScaledY(); width = x2 - x1; height = y2 - y1; iconX = x1 + (int) (width * .01); iconY = y1 + (int) (height * .1); iconLength = (int) (height * .8); Drawing.drawImage(g, iconX, iconY, iconLength, iconLength, currentItem.getItemPath()); itemNameX = iconX + (int) (iconLength * 1.5); itemNameLength = (int) (width * 0.6); font = Drawing.getFont( currentItem.getItemName(), itemNameLength, (int) (iconLength * 0.8), FONTNAME, FONTSTYLE); g.setFont(font); g.setColor(Color.WHITE); g.drawString(currentItem.getItemName(), itemNameX, iconY + (int) (iconLength * 0.9)); itemPriceX = x1 + (int) (width * 0.8); itemPriceWidth = (int) (width * 0.15); font = Drawing.getFont( Integer.toString(currentItem.getPrice()), itemPriceWidth, iconLength, FONTNAME, FONTSTYLE); g.setFont(font); g.setColor(Color.WHITE); g.drawString( Integer.toString(currentItem.getPrice()), itemPriceX, iconY + (int) (iconLength * .9)); return; }
@Override public void mousePressed(MouseEvent e) { CustomButton buttonPressed; // Button that was pressed. String buttonName; // The name of the button. int option; // Option chosen by user. User buyer; // User object for buyer User seller; // User object for seller Item selected_item; // Item object for selected item if (help) // if in help mode { help = false; repaint(); return; } wasItemSelected(e.getX(), e.getY()); buttonPressed = CustomButton.wasPressed(e.getX(), e.getY()); if (buttonPressed == null) // if no button was pressed { return; } buttonName = buttonPressed.getName(); playAudio(-1); switch (buttonName) // handle event associated with button name { case "rightTab": currentPage++; itemSelected = -1; break; case "leftTab": currentPage--; itemSelected = -1; break; case "buyTab": mode = false; break; case "sellTab": mode = true; break; case "button": selected_item = itemsArray[itemSelected]; option = JOptionPane.showConfirmDialog( this, ((!mode) ? "Buy " : "Sell ") + "for " + "$" + selected_item.getPrice() + "?"); if (option == 0 && (!mode)) // if they choose to buy { buyer = usersArray[0]; switch (store) // change message based on value of store. { case 0: seller = usersArray[2]; break; case 1: seller = usersArray[1]; break; case 2: seller = usersArray[3]; break; case 3: seller = usersArray[4]; break; default: seller = usersArray[1]; } buyItemFromUser(buyer, seller, selected_item); } else if (option == 0 && mode) // if they choose to sell { seller = usersArray[0]; switch (store) // change message based on value of store. { case 0: buyer = usersArray[2]; break; case 1: buyer = usersArray[1]; break; case 2: buyer = usersArray[3]; break; case 3: buyer = usersArray[4]; break; default: buyer = usersArray[1]; } buyItemFromUser(buyer, seller, selected_item); } itemSelected = -1; break; case "nextStore": if (++store == NUMSTORES) // if we're on the last store, loop around { store = 0; } switchStore(store); break; case "sort": // something orderToSort = JOptionPane.showOptionDialog( this, "Sort by:", "Sort", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, SORTOPTIONS, null); break; case "help": help = true; break; default: } repaint(); }
public Item(Item i) { super(i); this.price = i.getPrice(); }
@Override public void keyPressed(KeyEvent e) { int option; // The option the user selected. User buyer; // User object for buyer User seller; // User object for seller Item selected_item; // Item object for selected item if (help) // if in help mode { return; } switch (e.getKeyCode()) // handle event associated with key { case KeyEvent.VK_F1: // if f1 was pressed switchStore(0); break; case KeyEvent.VK_F2: // if f2 was pressed switchStore(1); break; case KeyEvent.VK_F3: // if f3 was pressed switchStore(2); break; case KeyEvent.VK_F4: // if f4 was pressed switchStore(3); break; case KeyEvent.VK_D: // if d or right was pressed case KeyEvent.VK_RIGHT: if (currentPage != totalPages - 1) // if we are not on the last page { currentPage++; itemSelected = -1; } break; case KeyEvent.VK_A: // if a or left was pressed case KeyEvent.VK_LEFT: if (currentPage != 0) // if we are not on the first page { currentPage--; itemSelected = -1; } break; case KeyEvent.VK_W: // if w or up was pressed case KeyEvent.VK_UP: if (itemSelected == -1) // if no items currently selected { itemSelected = 0; } else // if an item was selected { itemSelected--; if (itemSelected < 0) // loop if at beginning of list { itemSelected = ITEMSPERPAGE - 1; } } break; case KeyEvent.VK_S: // if s or down was pressed case KeyEvent.VK_DOWN: itemSelected++; if (itemSelected >= ITEMSPERPAGE) // if at end of list, loop around { itemSelected = 0; } break; case KeyEvent.VK_ENTER: // if enter was pressed if (itemSelected == -1) // if no item was selected { break; } selected_item = itemsArray[itemSelected]; option = JOptionPane.showConfirmDialog( this, ((!mode) ? "Buy " : "Sell ") + "for " + "$" + selected_item.getPrice() + "?"); if (option == 0 && mode) // if they choose to buy { buyer = usersArray[0]; switch (store) // change message based on value of store. { case 0: seller = usersArray[2]; break; case 1: seller = usersArray[1]; break; case 2: seller = usersArray[3]; break; case 3: seller = usersArray[4]; break; default: seller = usersArray[1]; } buyItemFromUser(buyer, seller, selected_item); } else if (option == 0 && mode) // if they choose to sell { seller = usersArray[0]; switch (store) // change message based on value of store. { case 0: buyer = usersArray[2]; break; case 1: buyer = usersArray[1]; break; case 2: buyer = usersArray[3]; break; case 3: buyer = usersArray[4]; break; default: buyer = usersArray[1]; } buyItemFromUser(buyer, seller, selected_item); } itemSelected = -1; break; default: return; } repaint(); }