You are on page 1of 6

Java 1

Centre for Information and Communication Technology


Assignment 3:

Electronics shop application using ArrayLists

1. Due Date
This assignment uses the skills and knowledge you have learnt in Java 1 up to and including
ArrayLists & Inheritance. It is a simulation of a work task.
The completed application is due 08 September 2016 at 11pm by submitting in eLearn. Face-to-face
students should also demonstrate it to teachers in class. The resubmit, if required, is due 15
September 2016 at 11pm.
Please note that procedures in the IT Department at CIT require submission on time unless a doctors
certificate is provided, otherwise you will need to resubmit having lost your first chance.

2. Assessment Task Description


This assignment is a work simulation task. You work for an IT company that has been engaged by a
local electronic goods shop to develop a GUI application to list properties that they have for sale and
those that they have sold. Your boss has met with the CEO of the shop to determine requirements and
he has done analysis on the project and come up with a design for the solution.
Your boss has got one programmer working on the user interface and the task she has given to you is
to code classes matching the URL diagrams she provides you. The GUI created by the other
employee will use these classes that you create.
A test script is provided by your boss in a class called TestShop. To run the test script you right click
on the class in BlueJ and choose to run the void main method. You should check the output that the
script produces against the output that she has provided as expected results. Your boss is happy for
the formatting of your output to be a little different as long as all the information is there and is correct.
You are required to code the classes in a BlueJ project. Also include the TestShopclass with no
changes made to the code except to change the name of the shop to your name. After successfully
testing you should zip up the whole folder in which your BlueJ project is stored and submit it on
eLearn.
Some requirements to successfully pass the assignment are:

1. Classes match class diagrams & all attributes are declared private
2. Code is well structured, uses camel case naming standards & is commented
including javadoc comments (the /** comments generated by default at the
top of each class where you can enter your name and the date)
3. Put your name as the name of the shop in the test script and ensure that it
works and produces the expected results

Canberra Institute of Technology (Version 1.5)

Java 1 Assignment 2

Subject Name: Java 1

Class Diagrams

Item (abstract)

Shop

String name
double price;
int numInStock
int numSold;

String storeName
ArrayList items
Shop(String inStoreName)
boolean addItem(Item newItem)
boolean findItem(String searchName)
void listItems()
void listLowStockToFile(int threshhold)
void listGamesByPlatform(String inPlatform)
void calcTotalSales()

Item(String inName, double inPrice)


String getName()
double getPrice()
int getNuminStock()
int getNumSold()
void receiveStock(int amount)
boolean sellCopy()
String toString()

Game (extends Item)


int maxPlayers
Game(String inName, int inMaxPlayers, double inPrice)
String toString()

CD (extends Item)
String artist

ElectronicGame (extends Game)

CD(String inName, String inArtist, double inPrice) String platform


String toString()

ElectronicGame(String inName, String inPlatform, int inMaxPlayers, double inPrice)


String getPlatform()
String toString()

The test class that your boss provides to you is:


public class TestShop
{
public static void main (String args[])
{
//create the shop
Shop myShop = new Shop("Amy Smith Superstore"); //change this to your name
//create a CD and add it to the shop
CD cd1 = new CD("Abba Gold", "Abba", 15);
myShop.addItem(cd1);
//create a Game and add it to the shop
Game game1 = new Game("Chess", 2, 39.95);
myShop.addItem(game1);

Canberra Institute of Technology (Version 1.6)

Java 1 Assignment 1

Subject Name: Java 1

//create 3 ElectronicGames and add them to the shop


ElectronicGame eg1 = new ElectronicGame("Shrek", "PS2", 1, 79.50);
myShop.addItem(eg1);
ElectronicGame eg2 = new ElectronicGame("Doom", "PC", 2, 30.20);
myShop.addItem(eg2);
ElectronicGame eg3 = new ElectronicGame("AFL", "PS2", 2, 49.95);
myShop.addItem(eg3);
//order and get stock
cd1.receiveStock(3);
game1.receiveStock(5);
eg1.receiveStock(10);
eg2.receiveStock(1);
cd1.receiveStock(7); // another 7 Abba CDs
//sell some items
cd1.sellCopy();
cd1.sellCopy(); //sell a second copy of Abba gold
eg2.sellCopy();
//print information about shop
myShop.listItems();
myShop.listLowStockToFile(8);
myShop.listGamesByPlatform("PS2");
myShop.calcTotalSales();
//test error conditions
Game game2 = new Game("Chess", 2, 39.95);
myShop.addItem(game2); //should fail as a Chess item is already in the shop
eg2.sellCopy(); //should fail as there are no Doom games left
}
}
To run the test right click on the TestShop class and choose public void main and then just click OK when it
offers you the opportunity to supply parameters. The output should be something like the following (you should
check to make sure you get similar results and if you dont then work out why & fix before submitting):
The output that your boss expects the running of the test class is something like the following:
*** Amy Smith Superstore contains the following items: ***
CD Abba Gold price $15.0 stock:8 sold:2 Artist:Abba
Game Chess price $39.95 stock:5 sold:0 Max Players:2
ElectronicGame Shrek price $79.5 stock:10 sold:0 Max Players:1 Platform:PS2
ElectronicGame Doom price $30.2 stock:0 sold:1 Max Players:2 Platform:PC
ElectronicGame AFL price $49.95 stock:0 sold:0 Max Players:2 Platform:PS2
*** End of item listing
*** Low stock listing (less than 8 products) written to file
*** Amy Smith Superstore has the following games for PS2: ***
ElectronicGame Shrek price $79.5 stock:10 sold:0 Max Players:1 Platform:PS2
ElectronicGame AFL price $49.95 stock:0 sold:0 Max Players:2 Platform:PS2
*** End of listing of games for PS2
*** Amy Smith Superstore has sold 3 items for a total of $60.2
Error - item Chess is already in the stock list

Canberra Institute of Technology (Version 1.6)

Java 1 Assignment 1

Subject Name: Java 1

Sorry there are no copies of Doom in stock

Canberra Institute of Technology (Version 1.6)

Java 1 Assignment 1

Subject Name: Java 1

Expected report to be written out to the file by above system test (where Amy Smith is replaced
by your name):
Low Stock (less than 8) Report for Amy Smith Superstore
*** The shop has low stock (less than 8) of the following items: ***
Game Chess price $39.95 stock:5 sold:0 Max Players:2
ElectronicGame Doom price $30.2 stock:0 sold:1 Max Players:2 Platform:PC
ElectronicGame AFL price $49.95 stock:0 sold:0 Max Players:2 Platform:PS2

3. Hints
Details are provided below for non-straightforward methods:
Item
receiveStock() takes the number of copies received as a parameter and adds it to numInStock
sellCopy() checks that numinStock is greater than zero and if adds 1 to the number sold, decreases the
number in stock & returns true; otherwise writes an error message & returns false
toString() returns the class name and attribute values
Shop
addItem() takes an item as a parameter, calls findItem() passing the item name as a parameter to see if there
is already an item by that name in the Shop ArrayList (name must be unique), and either adds the item to the
ArrayList returning true or writes an error message and returns false
findItem() takes an item name as a parameter and loops through the ArrayList looking for an item with that
name
listItems() loops through the ArrayList calling the toString() method for each item and writing it out
listLowStockToFile() takes a threshold as a parameter; loops through the ArrayList and prints out any item
that has less stock than the threshold amount. The printing should be to a file c:\LowStock.txt and should print
as the first line Low Stock (less than x) Report for YYY where x is the threshold parameter supplied when the
method is run and YYY is your name.
listGamesByPlatform() loops through the ArrayList and for any item that is an ElectronicGame prints it out if it
is for the same platform as the parameter

4. Submission Format
You are required to code all the classes in a BlueJ project. Also include the TestShop class with no
changes made to the code except to change the name of the shop from Amy smith Superstore to your
name. After successfully testing you should zip up the whole folder in which your BlueJ project is
stored and submit it on eLearn.

5. Requirements
Some requirements to successfully pass the assignment are:

1. Classes match class diagrams & all attributes are declared private
2. Code is well structured, uses camel case naming standards & is commented
including javadoc comments (the /** comments generated by default at the
top of each class where you can enter your name and the date)
3. Put your name as the name of the shop in the test script and ensure that it
works and produces the expected results

Canberra Institute of Technology (Version 1.6)

Java 1 Assignment 1

Subject Name: Java 1

6. Assessment
Your assignment will be assessed against the following performance, knowledge & evidence criteria & all must
be passed. The corresponding requirement is shown in brackets after each one.
ICTPRG406

1.7 Use the facilities of the language to read and write data, from and to, text files, and record the
outcomes
2.4 Use the facilities of the language to implement inheritance, to at least two levels
2.5 Use polymorphism at a simple level through inheritance, to enable the easy extension of the code
5.1 Create and conduct simple tests, to confirm that the code meets the design
specification
5.2 Document the tests performed and the results achieved
ICTPRG404

2.1 Gather requirements to develop test plan


2.2 Analyse and identify test data using various test-case design techniques
2.3 Define and design test cases
3.1 Choose and adopt a unit test framework
3.2 Design and implement algorithm in test procedures
3.3 Perform test executions
4.1 Record test results
4.2 Analyse test results
4.3 Produce test progress reports
4.4 Manage defects
P1 - apply test case design techniques to develop a test plan, and to test cases that adequately cover
specific test requirements
P2 - design, implement and execute test procedures, or scripts, by using a unit test framework and an
integrated development environment (IDE)
P3 - create test progress reports based on recorded test results.

Canberra Institute of Technology (Version 1.6)

Java 1 Assignment 1