Assignment task
Write a java console application that allows the user to keep track of various items in a grocery
shop. The application must allow the user to read, validate, store, display, sort and search the item
name (String), item id (integer number), quantity of the item in-stock (integer number), factory
price (double number) and shop price (double number) for N items in the grocery shop. N should be
declared as a constant and it should be equal to the largest digit of your student id number (e.g. if
your ID number is S0234111 then N should be equal to 4 and you can declare it as final int N=4;).
The item name, item id, quantity of the item in-stock, factory price and shop price must be stored in
five separate single dimension Arrays/ArrayLists (index 0 for item 1 and index N-1 for item N).
The minimum and maximum id numbers which can be stored are 1 and 333. The minimum and
maximum factory prices for each item which can be stored are $1 and $1000. The item id and
factory price must be entered from the keyboard and a validation for minimum and maximum
values must be done.
Your application should display and execute a menu with the following options. A switch statement
must be used to execute the following menu options.
1. Read, validate and store all items
2. Calculate and store shop price for all items
3. Display all items
4. Sell an item
5. Display all items with the lowest factory price
6. Sort and display sorted items
7. Exit from the application
1. Read, validate and store all items
This option reads item name, item id, quantity of the item in-stock and factory price for N items
from the keyboard and stores them in four separate single dimension Arrays/ArrayLists. If the id
number is less than 1 and greater than 333 then an appropriate message should be displayed and the
user should be asked to enter a new id number. Similarly if the factory price is less than $1 and
greater than $1000 then an appropriate message should be displayed and the user should be asked to
enter a new price.
2. Calculate and store shop price for all items
This option asks user to enter the discount percentage (e.g. 5%), calculates the shop price for each
item and then stores shop price in fifth Array/ArrayList.
3. Display all items
Display all information (item name, item id, quantity of the item in-stock, factory price and shop
price) for each item in the shop.
4. Sell an item
This option asks user to enter item id, searches for that item id and quantity of the item in-stock. If
item is found and the quantity of items in-stock is not 0 then it displays a message “item sold” and
decreases the quantity of items in-stock by one for that item. If item is not found or item found but
the quantity of items in-stock is 0 then it displays a message “item is not in-stock”. A built-in
search algorithm for searching can be used in this assignment.
5. Display all items with the lowest factory price
This option finds and displays the item in Array/ArrayList which has the lowest price. If there is
more than one item with the lowest price then it displays all of them.
6. Sort and display sorted items
This option sorts (by item name) all items stored in Array/ArrayList in descending order and
displays all sorted items (item name, item id, quantity of the item in-stock, factory price, shop
price). You can use any sorting algorithm. A built-in sort algorithm for sorting is not allowed in
this assignment.
7. Exit from the application
The application should display the message an appropriate message with your student id and then
exit from the application.
The application should work in a loop to enable the user to Read, validate and store all items,
Calculate and store shop price for all items, Display all items, Sell an item, Display all items with
the lowest factory price, Sort and display sorted items and Exit from the application.

Related posts: