Assignment 1 Solution

$30.00

Description

Assignment 1 Skills

Using Arrays

Writing methods given a speci cation

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 f

  • /

3

The

s p a c e s on

t h e

s h e l f . Each

a r r a y

e l e m e n t h o l d s a r e f e r e n c e

4

t o

a

Product

t h a t

i s d i s p l a y e d

i n t h a t s p a c e .

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 a c e .

  • /

7

private

Product [ ] [ ] s p a c e s ;

8

S t o r e S h e l f ( int m, int n ) f

9

public

10

s p a c e s = new Product [m] [ n ] ;

  1. g

  1. /

14

Method t o add P r o d u c t s t o t h e S t o r e S h e l f

  1. /

  1. public void addProduct ( int m, int n , Product p ) f

17

s p a c e s [m] [ n ] = p ;

  1. g

  1. /

21

Returns

t h e

p r i c e o f

t h e

Product

w i t h

t h e

s p e c i f i e d

name .

22

Returns

1

i f t h e r e

i s no

Product

w i t h

t h e

s p e c i f i e d

name .

  1. NO 2 PRODUCTS WILL HAVE THE SAME NAME

  1. /

25

public double g e t P r i c e ( S t r i n g productName )fg

26

  1. /

28

Checks each

space , i f

t h e Product

c o u n t i s

b e l o w 10 ,

29

t h e

Product

I n f o r m a t i o n s h o u l d be

p r i n t e d

t o St an da rd Out

30

Once

a l l

s p a c e s have

been c h e c k e d

t h e l i n e

31

End

o f

L i s t ’ s h o u l d

be p r i n t e d .

  1. /

33

public void p r i n t R e s t o c k L i s t ( ) fg

34

  1. g

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 le 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 le.