Homework Solution

$29.99 $18.99

This is the only assignment this semester in Java. This assignment is meant to review what you learned in CS 203. It reviews classes, instance variables, constructors, methods, arrays, loops, and selection. If this assignment is difficult for you, please take the time during the first week of class to practice your programming skills. If…

You’ll get a: . zip file solution

 

 
Categorys:
Tags:

Description

Rate this product

This is the only assignment this semester in Java. This assignment is meant to review what you learned in CS 203. It reviews classes, instance variables, constructors, methods, arrays, loops, and selection. If this assignment is difficult for you, please take the time during the first week of class to practice your programming skills. If you have hard time with the assignment, make standing appointments with the tutors, or see me to get more practice and to discuss strategies in order to be successful in CS 305.

Your project MUST compile and run on the university managed Ubuntu18 Linux VDI machines accessed at desktop.up.edu

This assignment is to be completed individually.

Specification

For this project, implement a record keeping application of a store inventory.

The implementation should include 3 Java classes:

  • Main (provided to you)

  • Item (you should implement this class)

  • Inventory (you should implement this class)

Here are the class diagrams for the two classes you should implement:

Inventory

Item

————————————-inventory:Item[]

————————————————————

-price: double

-stock : int[]

-name : String

-numItems : int

-ID : int

-maxInventorySize : int

+Item(price————————————————————-:double,name:String,ID:int)

+Inventory(maxInventorySize————————————- : int)

+print() : void

+addItem(it : Item, count: int) : int

+getPrice() : double

+soldItem(id : int) : int

+getID() : int

+printInventory() : void

Recall that – means private and + means public. Thus, the instance variables in the classes should be private and the constructors and methods should be public.

Inventory Class

This project implements Inventory as a collection of Item(s) who are located int the store. The Inventory object has maxInventorySize = the maximum number of items that can be found in the store. The numItems is the current number of items that are located in the inventory.

The constructor for the Inventory class should check the parameter maxInventorySize. If maxInventorySize <= 0, then set the maxInventorySize to 10. If the parameter is > 0, set the variable maxInventorySize is set to the value passed to the constructor. Then, create a new array of Item(s) objects of size maxInventorySize, create an integer array stock of the size maxInventorySize, and set numItems to 0.

The addItem method will check to see if numItems >= maxInventorySize. If so, this item cannot be added to the inventory since the maximum inventory size was reached. Print “Cannot add another item to the Inventory: Maximum number of items reached.” If this is the case, the method should return the value -1. Otherwise, add the item to the inventory array at position numItems, increment numItems by 1. Next, if the number of items added to the inventory is < 0, set the item’s stock count in the stock array to 0, otherwise set it the count passed in. Return 1.

The soldItem method will locate the item in the inventory by the ID:int, and if the item is in the inventory, it’s stock count is decremented by one and the following message is printed “Sold Item and inventory stock decremented”. If the item is not in the inventory, print “Could not sell item: not in inventory”, if the item’s count is <1, print “Count not sell item: Item’s inventory count is 0”.

The printInventory method should print “Store has the following items in the inventory: ” followed by a newline. Then, it should print every item in the store’s inventory, using the print() method in the Item class and adding the item’s current stock in the following format: Item <price> <tab> <name> <tab> <ID> <tab> <stock> The print method should also calculate the total value of inventory as the sum of each item’s price (unit price) multiplied by the number of items in stock, and the item with the min and max price in the inventory. Use the getPrice() method in the Item class to retrieve item’s price. Include items with zero stock count when looking for the cheapest and most expensive items in the inventory.

Item

The Item class represents individual Item that could be placed in the store’s inventory. For this project, we will keep it simple. Each Item has a price, a name, and an ID.

The constructor should take the item’s price, name and ID and assign these instance variables accordingly.

The print method should print the Item’s details in the format:

Item <price> <tab> <name> <tab><ID>

(see example output below for the format)

The getPrice and getID methods will return the value of the instance variable price and ID respectively.

Error-checking

All methods should do proper error-checking of the parameters. If the parameter value does not make sense (for example, a negative stock), then the code should set an appropriate value such as 0.

Documentation

The code should be well-commented, well indented, and include enough whitespace to be readable.

Example Output

The following should be printed to the console/screen when the main method is executed. (Check the driver Main.java, this is the output it generates)

  1. When you are finished and ready to submit:

    1. Create a new folder called username_HW0.

      1. (For example, my would be cenek_HW0.)

    1. Copy your Inventory.java file into this folder.

    2. Copy your Item.java file into this folder.

    3. Copy your Main.java file into this folder.

    1. Copy your HW0Summary.txt file into this folder.

    2. Zip the folder by right-clicking and Send To->Compressed Folder (on Windows or Linux). Very similar to the compression utilities on Mac.

  1. What to turn in: Submit your username_HW0.zip file to Moodle before the due date and time. After logging into learning.up.edu, navigate to CS 305. You will find a link to submit this file. You do not need to print anything.

Grading Guidelines (total of 20 points)

Your code files will be graded on a scale from 0 to 7 in two separate categories:

(0-7pts) Code Quality: Design, commenting, whitespace, readability, using private and public correctly

(0-7pts) Code Operation: Does code do what is listed in the specification?

Your summary report will be graded on a scale from 0 to 6 based on completeness and clarity.

HW 0 Report Guidelines and Format – use the template provided below

————-

Name:

CS 305 HW 0

1. (2 pts) Testing: Describe how you tested and evaluated your program. If your program does not meet the specifications, please note these differences. Include a representative printout from executing your program with the original main method.

2. (1 pt) Evaluation: Evaluate the quality of your code. Here are some questions

you may want to address: Is it readable and easy to follow? Do the parts make sense? Are your comments helpful?

3. (3 pts) Questions:

1a. At the bottom of the main method, uncomment the printing of the objects rei and amazon. Run the main method. What is printed for these objects?

1b. Slightly change the driver file Main.java by commenting out some “addItem” calls. Re-compile and re-run the code again. What is printed for these objects?

1c. What do these values represent?

  1. In the main method, you will see a comment after the rei store inventory – draw what the inventory looks like after the items were added to the inventory. Draw the inventory array, the item objects stored in the array and the stock at this point of the code execution. If an array cell is empty, label it with the word “null”.

3a. Describe the most challenging aspect(s) for you when writing this program. (Hopefully, this assignment is review for you from CS 203.)

3b. How much time did you spend in total on this homework assignment (including the report)?

Appendix A: Copy and paste your java code here (use Courier New 9pt font so the characters line up correctly)

Appendix B: I certify that the submitted work is my own work. Any help I received is documented in code comments.