This assignment focuses on defining Java classes and creating Java GUIS. Tum in the following six files: Catalog.java, I

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
correctanswer
Posts: 43759
Joined: Sat Aug 07, 2021 7:38 am

This assignment focuses on defining Java classes and creating Java GUIS. Tum in the following six files: Catalog.java, I

Post by correctanswer »

This Assignment Focuses On Defining Java Classes And Creating Java Guis Tum In The Following Six Files Catalog Java I 1
This Assignment Focuses On Defining Java Classes And Creating Java Guis Tum In The Following Six Files Catalog Java I 1 (147.78 KiB) Viewed 59 times
This Assignment Focuses On Defining Java Classes And Creating Java Guis Tum In The Following Six Files Catalog Java I 2
This Assignment Focuses On Defining Java Classes And Creating Java Guis Tum In The Following Six Files Catalog Java I 2 (114.87 KiB) Viewed 59 times
This Assignment Focuses On Defining Java Classes And Creating Java Guis Tum In The Following Six Files Catalog Java I 3
This Assignment Focuses On Defining Java Classes And Creating Java Guis Tum In The Following Six Files Catalog Java I 3 (109.97 KiB) Viewed 59 times
This Assignment Focuses On Defining Java Classes And Creating Java Guis Tum In The Following Six Files Catalog Java I 4
This Assignment Focuses On Defining Java Classes And Creating Java Guis Tum In The Following Six Files Catalog Java I 4 (62.83 KiB) Viewed 59 times
Starter Files:
ShoppingCartMain.java:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ItemTest.java:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TestingPrograms.java:
ItemOrderTest.java:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CatalogTest.java:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ShopingCartTest.java:
----------------------------------------------------------------------------------End---------------------------------------------------------------------------------------------
This assignment focuses on defining Java classes and creating Java GUIS. Tum in the following six files: Catalog.java, ItemOrder.java, Item.java, Shopping Cart.java, Shopping CartGUI.java, and shoppingCartMain.java. Program Description: Many websites and other computer programs allow a user to buy items by placing those items in a virtual shopping cart. In this assignment you will be writing a set of classes for your own simple shopping cart program. To the right is a screenshot of what the program could look like when the user has selected various items to order. 15 Prices are expressed using doubles and quantities are expressed as simple integers (e.g., you can't buy 2.345 of something). Notice that some of the items have a discount when you buy more. For example, silly putty normally costs $3.95 each, but you can buy 10 for $19.99. These items have, in effect, two prices: a single item price and a bulk item price for a bulk quantity. When computing the price for such an item, apply as many of the bulk quantity as you can and then use the single item price for any leftovers. For example, the user is ordering CS Gift Catalog X order total $28.89 silly putty, $3.95 (10 for $19.99) silly string, $3.50 (10 for $14.95) bottle o bubbles, $0.99 Nintendo Wii system, $389.99 Mario Computer Science Party 2 (WII), $49.99 Don Knuth Code Jam Challenge (Wii), $49.99 Computer Science pen, $3.40 Rubik's cube, $9.10 Computer Science Barbie, $19.99 'Java Rules!" button, $0.99 (10 for $5.00) 'Java Rules!" bumper sticker, $0.99 (20 for $8.95) quality for discount Calculate Total 2 15 D X CS Gift Catalog order total $32.10 silly putty, $3.95 (10 for $19.99) silly string, $3.50 (10 for $14.95) bottle o bubbles, $0.99 Nintendo Wii system, $389.99 Mario Computer Science Party 2 (Wii), $49.99 Don Knuth Code Jam Challenge (Wii), $49.99 Computer Science pen, $3.40 Rubik's cube, $9.10 Computer Science Barbie, $19.99 'Java Rules!' button, $0.99 (10 for $5.00) 'Java Rules!' bumper sticker, $0.99 (20 for $8.95) qualify for discount Calculate Total 12 buttons that cost $0.99 each but can be bought in bulk 10 for $5.00. The first 10 are sold at that bulk price ($5.00) and the two extras are charged at the single item price ($0.99 each) for a total of $6.98. At the bottom of the frame you will find a checkbox for an overall discount. If this box is checked, the user is given a 10% discount off the total price. This is computed using simple double arithmetic, computing a price that is 90% of what it would be otherwise. See an example of what happens if we turn on that checkbox to the left. The order total should only update when the Calculate Total button is pressed. You are to implement six classes to make this program work. Page 1
Item: The Item class stores information about the individual items. It should have the following public methods: Method Description Item (name, price) Constructor that takes a name and a price as arguments. The name will be a String and the price will be a double. Item (name, price, bulk quantity, bulk price) Constructor that takes a name and a single-item price and a bulk quantity and a bulk price as arguments. The name will be a string and the quantity will be an int and the prices will be doubles. priceFor (quantity) Returns the price for a given quantity of the item (taking into account bulk price, if applicable). Quantity will be an int. toString() Returns a String representation of this item: name followed by a comma and space followed by price. If this has a bulk price, then you should append an extra space and a parenthesized description of the bulk pricing that has the | bulk quantity, the word "for" and the bulk price. Catalog: The Catalog class stores information about a collection of Items. It should have the following public methods: Method Description Catalog (name, size) Constructor that takes the name of this catalog and the maximum size of this catalog as parameters. The name will be a string and the size an integer. add (item) Adds an Item at the end of this list and returns true if there is space. Otherwise does not alter the catalog and returns false. Returns the number of items in this catalog. size() get (index) | Returns the Item with the given index (0-based). Returns the name of this catalog. getName() ItemOrder: The Itemorder class stores information about a particular item and the quantity ordered for that Item. It should have the following public methods: Method Description ItemOrder (item, quantity) Constructor that creates an item order for the given item and given quantity. The quantity will be an integer. getPrice () Returns the cost for this item order. getItem() Returns a reference to the Item in this order. Shopping Cart: The Shopping Cart class stores information about the overall order. It should have the following public methods: Method Description Shopping Cart (size) Constructor that takes the size of the cart as a parameter and creates an empty array of item orders. add (item order) Adds an item order to the array, replacing any previous order for this item with the new order. The parameter will be of type Itemorder. set Discount (value) Sets whether or not this order gets a discount (true means there is a discount, false means no discount). getTotal () Retums the total cost of the shopping cart. Page 2
Shopping CartGUI: The ShoppingCartGUI class represents the graphical user interface for the program. It should have the following public methods: Method |Description Shopping CartGUI (product catalog) Constructor takes a Catalog as a parameter. It should display a GUI window matching the components and layout shown on the first page. The number and content of items should match the items in the passed in catalog. You are welcome to change the title, colors, borders, font and text-alignment to whatever you would like. The order total should be displayed in a disabled JTextField. We will create almost all of this together in class. Create this using the NetBeans drag-and-drop GUI creator; you do not need to write the GUI code out yourself Shopping CartMain: The ShoppingCartMain class contains the main method from which your program will run. We have provided an initial version with some sample products added to the catalog. You must replace these items with items of your own. Implementation Guidelines: You may not introduce any other public methods to these classes, although you can add as many private methods as you would like. However, you are allowed to redefine tostring in any of these classes (you might find that helpful in testing and debugging your code). You should use an array to implement the Shopping Cart and Catalog classes. Hint 1: Notice that when you add an Itemorder to a Shopping Cart, you have to deal with replacing any old order for the item. A user at one time might request 3 of some item and later change the request to 5 of that item. The order for 5 replaces the order for 3. The user isn't requesting 8 of the item in making such a change. The add method might be passed an item order with a quantity of 0. This should behave just like the others, replacing any current order for this item or being added to the order list. Hint 2: In the Item class you need to construct a string representation of the price. This isn't easy to do for a number of reasons, but Java provides a convenient built-in object that will do it for you. It's called a Number Format object and it appears in the java.text package (so you need to import java.text.*). You obtain a formatter by calling the static method called getCurrency Instance(), as in: NumberFormat nf Number Format.getCurrency Instance(); You can then call the format method of this object passing it the price as a double and it will return a String with a dollar sign and the price in dollars and cents. For example, you might say: double price = 38.5; String text= nf.format (price); This would set the variable text to "$38.50". Page 3
Development Strategy: This program has a lot more files than our previous assignments so it can feel pretty intimidating at first. However, most of the classes you need to write are a very small amount of code. We suggest working on this program in the following order: 1. Write the Item class. See Hint 2 for tips on the tostring method. Run the provided ItemTest.java program and make sure that your class matches the expected output. 2. Write the Itemorder class. Run the provided ItemorderTest.java program and make sure that your class matches the expected output. 3. Write the Catalog class. Run the provided CatalogTest.java program and make sure that your class matches the expected output. 4. Write the shopping Cart class. Run the provided Shopping CartTest.java program and make sure that your class matches the expected output. If you find your class failing to pass the tests and you aren't sure why, take a look at Hint 1. 5. Write the shopping CartGUI class. We will write most of this together in class on Tuesday. You will just need to alter our code from class to work with your other classes. Stylistic Guidelines: Your code should be well-structured and avoid redundancy. If you find yourself writing redundant code or with a very long method, add a private method. You may not add any public methods other than those described in this specification. Follow past stylistic guidelines about indentation, line lengths, and identifier names. Place a comment at the beginning of your classes, at the start of each method, and on complex sections of code. Use local variables when possible.
Register for solutions, replies, and use board search function. Answer Happy Forum is an archive of questions covering all technical subjects across the Internet.
Post Reply