Starting from:

$29

Elementary Data Structures and Algorithms  Assignment 1

Elementary Data Structures and Algorithms
 Assignment 1

Assignment 1 Skills
Using Arrays
Writing methods given a specification
Assignment 1 Background
Consider a software system that models a StoreShelf. A StoreShelf has M shelves, each with N
spaces for holding a Product. We can model this with an MxN array.
The Product class was discussed in class.
The incomplete declaration for the StoreShelf is shown below. You will complete the declaration and
write two unrelated methods for the StoreShelf class.
1 public c l a s s S t o r e S h e l f {
2 /∗ ∗
3 ∗ The s p a c e s on t h e s h e l f . Each a r r ay elemen t h o l d s a r e f e r e n c e
4 ∗ t o a Produc t t h a t i s d i s p l a y e d in t h a t s p ace .
5 ∗ A n u l l r e f e r e n c e i n d i c a t e s an empty s p ace .
6 ∗/
7 private Product [ ] [ ] s p a c e s ;
8
9 public S t o r e S h e l f ( int m, int n ) {
10 s p a c e s = new Product [m] [ n ] ;
11 }
12
13 /∗ ∗
14 ∗ Method t o add Pr o duc t s t o t h e S t o r e S h e l f
15 ∗/
16 public void addProduct ( int m, int n , Product p ) {
17 s p a c e s [m] [ n ] = p ;
18 }
19
20 /∗ ∗
21 ∗ Re turns t h e p r i c e o f t h e Produc t w i t h t h e s p e c i f i e d name .
22 ∗ Re turns −1 i f t h e r e i s no Produc t w i t h t h e s p e c i f i e d name .
23 ∗ NO 2 PRODUCTS WILL HAVE THE SAME NAME
24 ∗/
25 public double g e t P ri c e ( S t ri n g productName ){ }
26
27 /∗ ∗
28 ∗ Checks each space , i f t h e Produc t coun t i s bel ow 10 ,
29 ∗ t h e Produc t I n f o rm a t i o n s h o ul d be p r i n t e d t o S tandard Out
30 ∗ Once a l l s p a c e s have been c hecke d t h e l i n e
31 ∗ ’End o f L i s t ’ s h o ul d be p r i n t e d .
32 ∗/
33 public void p ri n t R e s t o c k Li s t ( ) {}
34
35 }
Assignment 1 Requirements
40% - Write the StoreShelf method getPrice.
50% - Write the StoreShelf method printRestockList.
10% - Provide comments where appropriate.
Assignment 1 Submission Submit on Blackboard:
1. StoreShelf.java
Required Each submitted file should include your name and a statement that this is your own work. This
should appear as a comment at the beginning of any code file.

More products