Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - Gadget Order Taker

dickersonka
dickersonka 


(#13 on page 670 – 671) Gadgets by Mail sells many interesting items through its catalogs. Write an application that prompts the user for order details, including item numbers and quantity of each item ordered, based on the available items shown in Table 12-2. Table 12-2 Items offered by Gadgets by Mail Item # Description Price ($) 101 Electric hand warmer 12.99 124 Battery-operated plant waterer 7.55 256 Gerbil trimmer 9.99 512 Talking bookmark 6.89 The shipping and handling fee for an order is based on the total order price, as shown in Table 12-3. Table 12-3 Shipping and handling fees charged by Gadgets by Mail Price of Order ($) Shipping and Handling ($) 0–24.99 5.55 25.00–49.99 8.55 50.00 or more 11.55 Create the following classes:  Gadget, which contains an item number, description, and price for a gadget; a constructor that sets all the fields; and get methods to retrieve the field values.  Order, which contains an order number, customer name, and address (assume you need just a street address, not city, state, and zip code); a list of item numbers ordered (up to four); the total price of all items ordered; and a shipping and handling fee for the order. Include a constructor to set the field values and get methods to retrieve the field values. GadgetOrderTaker, which is an interactive application that takes four customer orders. The class contains an array of the four Gadget objects offered (from Table 12-2). The application prompts each user for a name and street address and assigns a unique order number to each customer, starting with 101. The application asks each user to enter an item number and quantity wanted. When the user enters 999 for the item number, the order is complete, and the next customer can enter data. Each customer can order up to four item numbers. When a customer’s order is complete (the customer has entered 999 for an item number, or has ordered four different items), calculate the shipping and handling charges. After four customers have placed Orders, display each Order’s data, including the order number, the name and address of the customer, and the list of items ordered, including the item number, description, and price of each Order, the total price for the order, and the shipping and handling charge. The GadgetOrderTaker class handles all thrown Exceptions by displaying an explanatory message and ending the application.  OrderException, which is an Exception that is created and thrown under any of the following conditions:  A customer attempts to order more than four different items.  A customer orders more than 100 of any item.  A customer enters an invalid item number.  Also, catch the Exception generated by either of these conditions:  A customer enters a nonnumeric character as the item number.  A customer enters a nonnumeric character as the quantity. Save the files as Gadget.java, Order.java, GadgetOrderTaker.java, and OrderException.java.  The GadgetOrderTaker class handles all thrown Exceptions by displaying an explanatory message and ending the application. Create a new application that handles all Exceptions by requiring the user to reenter the offending data. Save the file as GadgetOrderTaker2.java. Attachments
Tags Clarifications

Answers

Java - Gadget Order Taker - Solution

dickersonka
dickersonka 



Attached is the solution to the Java - Gadget Order Taker assignment including source and comments Attachments
GadgetOrder.zip (5 K) Download
Preview
{ this.orderNumber = orderNumber; this.customerName = customerName; this.customerAddress = customerAddress; this.itemList = itemList; this.totalPrice = totalPrice; this.shippingHandling = shippingHandling; } /** * Get order number * @return order number */ public int getOrderNumber() { return orderNumber;

Preview
//initialize gadget list gadgetList = initGadgetList(); //create array to hold orders Order[] orders = new Order[4]; try { //loop through array for(int i = 0; i < orders.length; i++){ //set order in array orders[i] = getOrder(STARTING_ORDER_NUMBER + i);

Preview
order.getItemList()) { message += item + " "; message += getDescription(item) + "\n"; } message += "-------------------------------------\n"; //total details message += "Price: " + money.format(order.getTotalPrice()) + "\n"; message += "S/H: " + money.format(order.getShippingHandling()) + "\n"; message += "Total: " +

Preview
* @param message exception message */ public

Preview
String description, double price){ this.itemNumber = itemNumber; this.description = description; this.price = price; } /** * Get item number * @return item number */ public int getItemNumber() { return itemNumber;

GadgetOrderTakerPart1_output1.png (17 K) Download Preview

GadgetOrderTakerPart1_output2.png (19 K) Download Preview

GadgetOrderTakerPart2_output.png (10 K) Download Preview

Screenshots
Screenshot
Screenshot
Screenshot
Purchase Answer