コード例 #1
0
ファイル: BaselineApp.java プロジェクト: muskan21/Baseline
 private static void printResult(ArrayList<Item> items) {
   double s = 0;
   for (Item i : items) {
     System.out.println(i.getQuantity() + " " + i.getItemName() + " : " + i.getCost());
     s += i.getSalexTax();
   }
   System.out.println("Salex Tax : " + s);
 }
コード例 #2
0
 @Override
 public boolean equals(Object o) {
   if (this == o) return true;
   if (!(o instanceof Item)) return false;
   Item item = (Item) o;
   if (getQuantity() != item.getQuantity()) return false;
   return getCookie() == item.getCookie();
 }
コード例 #3
0
ファイル: Shop.java プロジェクト: erosario25/Javacourse_src
 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");
 }
コード例 #4
0
  private String buildTransaction() {
    String transaction = "";
    DateFormat dateFormat;

    for (Item i : order.getOrder()) {
      dateFormat = new SimpleDateFormat("YYMMddHHmmss");
      transaction += dateFormat.format(this.transDate) + ", ";
      transaction +=
          i.getBook().getId() + ", " + i.getBook().getTitle() + ", " + i.getBook().getPriceStr();
      transaction +=
          ", " + i.getQuantity() + ", " + i.getPercentStr() + ", " + i.getTotalStr() + ", ";
      dateFormat = new SimpleDateFormat("dd/MM/YY HH:mm:ss z");
      transaction += dateFormat.format(this.transDate) + newLine;
    }
    return transaction;
  }
コード例 #5
0
  public void confirmItem() {
    this.subtotal += item.getTotal();
    String subtotalStr = formatter.format(this.subtotal);
    text_bookID.setText("");
    text_quantity.setText("");
    text_subtotal.setText(subtotalStr);

    confirmAlert();

    order.addItem(item);
    this.totalQuantity += item.getQuantity();
    changeItemNumber();
    btn_confirm.setDisable(true);
    btn_view.setDisable(false);
    text_totalItems.setDisable(true);
    item = null;
  }
コード例 #6
0
ファイル: OrderServiceBean.java プロジェクト: KurtStam/dtgov
 @Override
 public OrderAck submitOrder(Order order) {
   // Create an order ack
   OrderAck orderAck = new OrderAck().setOrderId(order.getOrderId());
   // Check the inventory
   try {
     Item orderItem = _inventory.lookupItem(order.getItemId());
     // Check quantity on hand and generate the ack
     if (orderItem.getQuantity() >= order.getQuantity()) {
       orderAck.setAccepted(true).setStatus("Order Accepted"); // $NON-NLS-1$
     } else {
       orderAck.setAccepted(false).setStatus("Insufficient Quantity"); // $NON-NLS-1$
     }
   } catch (ItemNotFoundException infEx) {
     orderAck.setAccepted(false).setStatus("Item Not Available"); // $NON-NLS-1$
   }
   return orderAck;
 }
コード例 #7
0
  public Customer getMostItems() throws NotNegativeException {
    Customer temp = null;
    int max = Integer.MIN_VALUE;

    List<Customer> cs = custDAO.getAllCustomers();
    for (Customer c : cs) {
      List<Item> items = c.getItems();
      int num = 0;
      for (Item item : items) {
        num += item.getQuantity();
      }
      if (num > max) {
        temp = c;
      }
    }

    return temp;
  }
コード例 #8
0
  private void dropItem() {
    Game game = PemberleyGame.getCurrentGame();
    Player player = game.getPlayerOne();
    ItemControl itemControl = new ItemControl();
    Item[] inventoryItemArray = game.getInventoryItemArray();
    String gameMessage = " ";
    int indexOfItem;
    int quantityOfItem = 1;
    String playerSelection;
    InventoryControl inventoryControl = new InventoryControl();
    // designate the inventory
    Inventory inventory = player.getInventory();
    // while player's selection is not X loop
    do {
      // if there is nothing in the localItemArray say there is nothing to take.
      if (inventoryItemArray.length == 0) {
        this.console.println("Nothing to drop");
        break;
      } else {
        String prompt = "What do you want to drop? Type X to exit.";
        // get input from the player
        playerSelection = this.getStringInput(prompt);
        // see if the player's selected item is in the room. return it's index in the array.
        indexOfItem = itemControl.getItemIndex(playerSelection, player, inventoryItemArray);

        if (indexOfItem != -1) { // run this code if there was an index match
          // set the item to whatever item matched the players selection
          Item selectedItem = inventoryItemArray[indexOfItem];
          // if the item's multiple attribute is true run this code
          if (selectedItem.getQuantity() > 1) {
            prompt = "How Many do you want to drop? (1 - " + selectedItem.getQuantity() + ")";
            // get the players selection and make sure it is an integer
            playerSelection = this.getStringInput(prompt); // gets a string
            // make the player's selection an integer
            try {
              quantityOfItem = Integer.parseInt(playerSelection); // converts string to int

            } catch (NumberFormatException nf) {
              ErrorView.display(
                  this.getClass().getName(),
                  "\nYou must enter a valid number." + " Try again or type X to exit.");
            }
            // call the takeMultipleItem function.
            try {
              gameMessage =
                  inventoryControl.dropMultipleItem(selectedItem, quantityOfItem, inventory);
            } catch (InventoryControlException ie) {
              ErrorView.display(this.getClass().getName(), ie.getMessage());
            }
          } else { // run this code if the item's multiple attribue is not true
            quantityOfItem = 1;

            // call the takeSingleItem function
            try {
              gameMessage =
                  inventoryControl.dropSingleItem(selectedItem, quantityOfItem, inventory);
            } catch (InventoryControlException ie) {
              ErrorView.display(this.getClass().getName(), ie.getMessage());
            }
          }

        } else {
          // if the player's selection is not in the array send this message
          gameMessage = "Not sure what you are trying to drop.";
        }
      }
      this.console.println(gameMessage);
    } while (!playerSelection.equalsIgnoreCase("X")); // loop
  }
コード例 #9
0
  private void giveItem() {
    Game game = PemberleyGame.getCurrentGame();

    if (game.getInventoryItemNames().length == 0 || game.getLocalActorNames().length == 0) {
      this.console.println("You have nothing to give or there is no one to give something to.");
      return;
    }

    ItemControl itemControl = new ItemControl();
    ActorControl actorControl = new ActorControl();
    InventoryControl inventoryControl = new InventoryControl();
    String prompt = "What do you want to give?";
    Player player = game.getPlayerOne();
    Item[] inventoryItems = game.getInventoryItemArray();
    Actor[] actorArray = game.getLocalActorArray();
    String gameMessage = " ";
    int quantityOfItem = 1;
    Item itemToGive;
    Actor actorToGive;
    // check to see if there is anything to use.

    this.console.println("These things are in your inventory\n");

    for (String i : game.getInventoryItemNames()) {
      this.console.print(i + "\n");
    }

    String playerSelection;
    do {
      playerSelection = this.getStringInput(prompt);

      int indexOfItem = itemControl.getItemIndex(playerSelection, player, inventoryItems);

      try {
        itemToGive = inventoryItems[indexOfItem];
      } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
        ErrorView.display(this.getClass().getName(), "\nNot Sure what you are trying to give.");
        return;
      }

      if (itemToGive.getQuantity() > 1) {
        prompt = "How many " + itemToGive.getName() + " do you want to give?";
        playerSelection = this.getStringInput(prompt);

        try {
          quantityOfItem = Integer.parseInt(playerSelection); // converts string to int

        } catch (NumberFormatException nf) {
          ErrorView.display(
              this.getClass().getName(),
              "\nYou must enter a valid number." + " Try again or type X to exit.");
          break;
        }

      } else {
        quantityOfItem = 1;
      }

      this.console.print("\nThese people are here:");
      prompt = "Who do you want to give the " + itemToGive.getName() + " to?\n";
      for (String i : game.getLocalActorNames()) {
        this.console.print(i + "\n");
      }

      playerSelection = this.getStringInput(prompt);

      int indexOfActor = actorControl.getActorIndex(playerSelection, player, actorArray);

      try {
        actorToGive = actorArray[indexOfActor];
      } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
        ErrorView.display(
            this.getClass().getName(),
            "\nNot Sure who you are trying to give the " + itemToGive.getName() + " to.");
        return;
      }

      this.console.println(inventoryControl.giveItem(itemToGive, quantityOfItem, actorToGive));

      break;

    } while (!playerSelection.equalsIgnoreCase("x"));
  }