Shopping Cart Management System Assignment 6

User Generated

N360

Programming

Description

just follow the steps and I will give all you need

you have to have the intelliJ to use the Scala programming

Unformatted Attachment Preview

Title: Shopping Cart Management System (Part 4) This is a continuation of the assignment 5. In this assignment, you need to address the following requirements. Requirements (1) Overall, your program must support the following 9 commands. Instead of processing all commands as string inputs (as you did in the previous assignment 3 and 4), you must process all the commands as digits. In detail, the user needs to enter the digits of 1 ~ 9 for initiating an action of each command. To support the commands, you must use match expression. a. Add → 1 b. Remove → 2 c. Change i. Rename → 3 ii. Quantity → 4 iii. Price → 5 d. Sort i. Sort by item name → 6 ii. Sort by item price → 7 e. Print → 8 f. Quit → 9 (2) For this assignment, you must create the shopping cart management system as a class a. In the previous assignment (3 ~ 5), you probably used “ArrayBuffer” for managing item names, quantities, and prices. To make the shopping cart management system efficiently, you must declare two classes as ShoppingCartManagement and ShoppingItem. b. The ShoppingCartManagement class is used for handling all items. And the Item class is used for storing each item’s name, quantity, and price information. Specifically, you can create the class ShoppingCartManagement similar to the one as shown below. Of course, it is an example. You do not need to follow this class declaration. class ShoppingCartManagement { private var ShoppingCart: ArrayBuffer[ShoppingItem] // for storing items def PrintAllItems(): Unit = {……………………} def AddProductItem(Name:String, Quantity:Int, Price:Double): Unit = {……………………} def RemoveInventoryItem(IndexPos: Int): Unit = {……………………} def SortByName(): Unit = {……………………} def SortByPrice(): Unit = {……………………} } i. As shown in the class declaration, ArrayBuffer is used for storing ShoppingItems. ii. Several methods needs to be defined for handling each command. The PrintAllItems() is used to print all items stored in the ShoppingCart. The AddProductItem() is used to add user entered items to the ShoppingCart. The AddProductItem(…) is used to add user entered items to the ShoppingCart. Of course, you need to pass each item’s name, quantity, and price. The RemoveInventoryItem(…) is used to remove the user selected item from the ShoppingCart. For removing item, you need to use index position. iii. Since you need to support sorting by name and price, the two methods are needed as SortByName() and SortByPrice(). Whenever the sorting is performed, the sorted result needs to be stored back to the ShoppingCart. iv. To support the sorting, you can implement sequential sort yourself (check the Exam 2 – Question 2 (TYPE-A)). Alternatively, you can use the method ("sortWith") that is included in ArrayBuffer. scala> import scala.collection.mutable.ArrayBuffer import scala.collection.mutable.ArrayBuffer scala> var items = ArrayBuffer(10, 5, 8, 1, 7) items: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(10, 5, 8, 1, 7) scala> items = items.sortWith(_ < _) items: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(1, 5, 7, 8, 10) v. Since there are two items in the ShoppingItem class as item name and price, when sorting by name and price, you need to consider applying the sortWith() method as shown below. scala> case class item(name: String, price: Int) defined class item scala> var items = ArrayBuffer(item("Shoes", 25), item("Toy", 20), item("Socks", 5)) items: scala.collection.mutable.ArrayBuffer[item] = ArrayBuffer(item(Shoes,25), item(Toy,20), item(Socks,5)) scala> items = items.sortWith(_.name < _.name) items: scala.collection.mutable.ArrayBuffer[item] = ArrayBuffer(item(Shoes,25), item(Socks,5), item(Toy,20)) scala> items = items.sortWith(_.price < _.price) items: scala.collection.mutable.ArrayBuffer[item] = ArrayBuffer(item(Socks,5), item(Toy,20), item(Shoes,25)) i. To use the ShoppingCartManagement class, you need to create an object inside of the main() function first. (3) Exception handling a. Unsupported commands (other than 1 ~ 10) need to be handled properly with notifying the user “The entered command (…) is not valid!”. b. Handling incorrectly entered inputs for the quantity and unit price needs to be supported. For instance, if the user enters “toy” for the quantity, a notification message (“-->The quantity has been entered incorrectly!”) needs to be printed and ask the user again. ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------- | 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 1 Enter new item's name: shoes Enter new item's quantity: toy -->The quantity has been entered incorrectly! Enter new item's quantity: ten Enter new item's unit price: 300.00 c. Also, processing string numbers for the quantity need to be supported (This is the same requirement that you did in Assignment 5). As shown above, if the user enters “ten” for the quantity, it needs to be converted to a numeric value 10. For this requirement, you must support the following string numbers as "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty". For Scala programming, you can simply use “indexOf” method. For example, if the user enters “two” as a String value, it can be compared with all string numbers stored in the Array (“numStrings”). Since the index number starts from 0, plus 1 needs to be applied to get a correct numeric value. val numStrings = Array("one", "two", "three") val intValue:Int = numStrings.indexOf("two") + 1 println(intValue) PROCESSING COMMAND(S) For any invalid commands, a notification message must be printed on screen. ======================================================================== Shopping Cart!! ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: test The entered command ( test ) is not valid! ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------- Enter a command: 0 The entered command ( 0 ) is not valid! ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 1 Enter new item's name: shoes Enter new item's quantity: five Enter new item's unit price: 300 ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: ADD -->The entered command ( ADD ) is not valid! ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 1 Enter new item's name: Banana Mango Enter new item's quantity again: 2 Enter new item's unit price: 10 -------------------------------------------------* Note that the red colored text indicates the user entered text. REMOVE ITEM(S) When the user wants to remove, a list of items in the cart needs to be printed. Also, it is necessary to ask the user to enter an item number for removal. Any incorrectly entered information needs to handled by showing a warning message (“-->The item number has been entered incorrectly!”). ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 2 1: name: Shoes, quantity: 5, unit price: $300.50 2: name: Mango, quantity: 10, unit price: $10.00 Enter the item number that you want to remove: shoes -->The item number has been entered incorrectly! Enter the item number that you want to remove: 0 -->The item number has been entered incorrectly! Enter the item number that you want to remove: 1 The item number (1) has been removed successfully. ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 2 1: name: Mango, quantity: 10, unit price: $10.00 Enter the item number that you want to remove: 1 The item number (1) has been removed successfully. ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 2 -->There is no item to remove! -------------------------------------------------* Note that the red colored text indicates the user entered text. CHANGE THE NAME OF THE ITEM(S) This command is for changing the name of the selected item(s). ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 3 1: name: Shoes, quantity: 5, unit price: $300.50 2: name: Mango, quantity: 10, unit price: $10.00 Enter the item number that you want to adjust the quantity: shoes -->The item number has been entered incorrectly! Enter the item number that you want to adjust the quantity: 0 -->The item number has been entered incorrectly! Enter the item number that you want to adjust the quantity: 1 Enter new name of the item: Toy The name of the item number (1) has been changed successfully. * Note that the red colored text indicates the user entered text. ADJUST THE QUANTITY OF THE ITEM(S) This command is for adjusting the quantity of the selected item(s). Any incorrectly entered information needs to be processed by showing a warning message. ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 4 1: name: Shoes, quantity: 5, unit price: $300.50 2: name: Mango, quantity: 10, unit price: $10.00 Enter the item number that you want to adjust the quantity: shoes -->The item number has been entered incorrectly! Enter the item number that you want to adjust the quantity: 0 -->The item number has been entered incorrectly! Enter the item number that you want to adjust the quantity: 1 Enter new quantity of the item: 10 The quantity information of the item number (1) has been changed successfully. * Note that the red colored text indicates the user entered text. ADJUST THE PRICE OF THE ITEM(S) This command is for adjusting the quantity of the selected item(s). Any incorrectly entered information needs to be handled with showing a warning message. ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 5 1: name: Shoes, quantity: 5, unit price: $300.50 2: name: Mango, quantity: 10, unit price: $10.00 Enter the item number that you want to adjust the quantity: shoes -->The item number has been entered incorrectly! Enter the item number that you want to adjust the quantity: 0 -->The item number has been entered incorrectly! Enter the item number that you want to adjust the quantity: 1 Enter new price of the item: 100.00 The quantity information of the item number (1) has been changed successfully. * Note that the red colored text indicates the user entered text. SORTING ITEM(S) This command is for sorting items by name and price. ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 6 -- SORTED BY NAME -1: name: Shoes, quantity: 5, unit price: $300.50 2: name: Mango, quantity: 10, unit price: $10.00 ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 7 -- SORTED BY PRICE -1: name: Mango, quantity: 10, unit price: $10.00 2: name: Shoes, quantity: 5, unit price: $300.50 * Note that the red colored text indicates the user entered text. PRINT THE ITEM(S) This command is for printing all items in the cart. At the same time, total sum needs to be printed. ------------------------------------------------------------------------Supported Commands ------------------------------------------------------------------------| 1: Add | 2: Remove | 3: Rename the item | 4: Change the quantity | 5: Change the price | 6: Sort by name | 7: Sort by price | 8: Print | 9: Quit ------------------------------------------------------------------------Enter a command: 8 1: name: Shoes, quantity: 10, unit price: $300.50 2: name: Mango, quantity: 10, unit price: $10.00 Total Sum: $3,105.00 * Note that the red colored text indicates the user entered text. NAMING REQUIREMENTS: • • Your IntelliJ project should be named as “YourLastname_Assignment06”. Your Scala source code must be named as “YourLastname_Assignment06.scala”. When compiled successfully (with no compilation error), IntelliJ generates the file “YourLastname_Assignment06.jar”. • You need to zip two files (YourLastname_Assignment06.scala and YourLastname_Assignment06.jar) as “YourStudentID_Assignment06.zip”. For instance, if your student ID is N012345, the zip file name must be N012345_Assignment06.zip. Submit the zip file to the Blackboard. HINTS: • • • In your program, you must create an object named as “YourLastname_Assignment06”. Inside of the object, you need to create a main method as “def main(args: Array[String])”. For handling commands, you must use match expression (see Lecture 5). To support exception handling, you must use try… catch statement (see Lecture 5). Requirements (& Grading policy): 1. 2. 3. 4. 5. You need to add your name and student id in the first line of the program. (2pt) You must add comments in your source codes (possibly most lines). (15pt) Processing all commands as numeric values (instead of processing them as string values). (5pt) You need to support two sorting options (6pt) All commands need to work as described above (24pt) o Otherwise, deduction (up to 4pt per each command 1 ~ 6) will be applied. 6. Using try…catch statement for exception handling for incorrectly entered quantity and price. (2pt) 7. Processing the user entered string numbers for the quantity and price as numeric values (5pt) 8. You need print the unit price and the total price of items with a leading dollar sign, a comma used as the grouping separator, and a period used as the decimal indicator. For example, $1,234.56. (2pt) 9. Your program source code must be named as "YourLastname_Assignment06.scala". (2pt) 10. Your jar file must be named as “YourLastname_Assignment06.jar”. (2pt) 11. You need to zip the two files (YourLastname_Assignment06.scala and YourLastname_Assignment06.jar) as “YourStudentID_Assignment06.zip”. For instance, if your student ID is N012345, the zip file name must be N012345_Assignment06.zip. Submit the zip file to the Blackboard. (2pt)
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer


Anonymous
Really great stuff, couldn't ask for more.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags