Sedang Disiapkan

83224 Lab 5

Due Date: Monday May 20th 12pm PST Objectives: 1. Read and understand other programmer’s code 2. Get familiar with list container class 3. Practice using loop structure I will be picky on your programming style this time. Watch out the comments and format (indentation) of your program. The class documentation is under “Class Specification” link and source code for the project is under “Source Code” link. Both links are located at the same line as “Lab 5”. Copy the source files in your lab5 project. When you read the source file, pay attention to the comments part. If you don’t understand what “require:” and “ensure:” means, please read Chapter 7. Some classes used in this project like Vector are new for you, refer to the API on how to use them. Containers and lists: A container is an object whose function is to contain a collection of other objects. A list is a container with the following properties: • contains any (finite) number of objects; • contains only objects of one given class; i.e, all objects on the list must be instances of the same class; • allows access to a contained object by means of an integer index denoting the object's position on the list. (We will see later that with sub-classing, the restriction that all objects on the list must be of the same class is not limiting.) The class RetailItemList: In this lab, you will use the class RetailItemList. A RetailItemList can contain, surprise, only RetailItems. • Open and read the definition of the class RetailItem in file RetailItem.java. • Open and read the definition of the class RetailItemList in file RetailItemList.java. Note in particular the following methods: • size returns the number of objects on the list. The size of a list can be 0, in which case the list is empty: it contains no elements. • get returns the object at the specified position (index). Indexing starts at 0. If a list contains 10 objects, the first object is at index 0 and the last object is at index 9. • append adds an object to the end of the list. • remove removes the object at the specified index position. This does not leave a "hole" in the list. For instance, if the object with index 3 is removed, the object that was at index 4 "moves up" to 3. The class Inventory: To see how a list can be used, we examine a simple class that uses a RetailItemList. • Open and read the definition of the class Inventory in file Inventory.java. • Open and read the test code in InventoryTest.java. • Compile the project and run InventoryTest. Now you will add two methods to the class Inventory. Examining the methods already defined in the class, particularly the method numberOutOfStock, should give you clues as to how to proceed. • First, implement a method totalUnitsOnHand. This method returns the total number of units on hand for all retail items in the inventory. • Second, implement a method outOfStock. This method should return a RetailItemList containing all of the items that are currently out of stock: that is, items for which there are no units on hand. Note that this method should create a new RetailItemList, and append RetailItems to it. • Modify the test code to test your methods. • Compile and test. Submission: Submit hardcopy of the modified Inventory class code and modified test code InventoryTest as well as output for running InventoryTest showing the results of your test in class on due date.

Kemahiran: Semua Boleh, Java

Lihat lagi: which java collection to use, what is new in java 1.5, what is java programming used for, what is an object in programming, what is a method in programming, what is a loop in programming, what are classes in programming, vector remove, vector containers, vector container, vector 3 container, vector 2 container, use of collection in java, the practice of programming, the elements of programming style, size of vector, size of a vector, read vector, programming what is a class, programming vector

Tentang Majikan:
( 0 ulasan )

ID Projek: #1829679

Dianugerahkan kepada:

catsl

I will do this project for you.

$30 USD dalam 4 hari
(1 Ulasan)
0.0