Você está na página 1de 5

CI5100 Software Development in Java Individual Programming Workshop Tutorial 5

Individual Programming: Tutorial 5 - Starting the 2nd Iteration


(Stage) of Development
1. Introduction
This Tutorial covers tasks and approaches that may be useful when you begin
the second Stage of development (2nd iteration or phase) of your application
starting with User Story 5. You will complete this individually beginning from
the work you completed in Phase 1. To do this you will need to have finished the
first phase, ideally having completed the first four user stories. This should
include reading in your core data into objects from a file and then displaying
them in a JTextArea or another Swing component.
To begin the 2nd Phase you will need to extend the Data Model with the data
provided under Studyspace->Data for Desktop Application->Stage 2
The aim of this tutorial is to read the new data into a new list of objects, print
these out and then relate them to the core data objects from Stage 1 to calculate
something. For example:
Pet Shops: Calculate the average cost of the pets in a particular shop
Talent Agency: Calculate the average daily rate of the clients in a
particular agency
Football Team: Calculate average attendance at home matches for a
particular team

2. Tutorial Tasks
The table summarises the tasks covered by this tutorial. The relevant class
diagrams and examples from the lecture notes are shown in Section 3.
Note that this tutorial is about the relationship between the two files. You
may find it easier to create a new class and main method for your testing,
and do your testing on the console with System.out.println rather than
trying to expand your GUI (yet!) to accommodate the new data. You should
only consider expanding your GUI as an extra task for this workshop, if you
complete everything else! The video for Lecture 7 should help you to do
this.
Task
W5.1 Create a new Data Model
Class with Getter and Setter
Methods, a Parameterised
Constructor and a toString()
method for your related data
W5.2 Create a new ReadFile
method in your DataFiles class

Notes
This follows the same pattern as your Data
Model class in Phase 1 but should reflect the
new data you have.
You may wish to test this before moving onto
W5.2
Use the NetBeans Generate Code.... function
where possible to speed this up.
Again this is very similar what you did in
Phase 1 (W3.2). You may wish to test this by

CI5100 Software Development in Java Individual Programming Workshop Tutorial 5

to return an ArrayList of your


new related Data objects

printing out the data you have read in, using


a for each loop and the toString( ) method.

W5.3 Add a new static


attribute to your main
ApplicationModel in order to
store your new ArrayList of the
related data Objects
W5.4 Find out all related data
Objects that match the name of
a core data object

Set this attribute from the output of your


new ReadFile method (in W5.2) See Figures
1 a,b,c,d below

W5.5 Calculate an average


value for all the related data
Objects found in W5.4

For example, input the name of a shop, team


or agency. Produce an ArrayList of the
matching pets, clients or matches. Then
printout all the matching records.
Hint: You should create a method to find the
matching objects e.g. On your
ApplicationModel Class
A method to produce a String version of an
ArrayList of each type of data object might
also be useful
For example: average cost of pet, average rate
of clients or average attendance at home
matches. Hint: Again a suitable method can
be used to do this

Suggested Extra Tasks:


Can you expand your GUI to show the new data?
Can you use JOptionPane as a way of entering the inputs for the datafiles?
(see last years notes)
How could you handle a non-matching item being input?
How could you create an explicit relationship between a objects of one
Type or Class (e.g. Shops, Agencies or Teams) and the specific related
objects of another Type or Class (e.g. Pets, Clients or Matches) see
Figures 2 a,b,c,d

3. Class Diagrams

CI5100 Software Development in Java Individual Programming Workshop Tutorial 5

Figure 1a Using the Application Model Class to Establish Implicit


Relationships between 2 sets of objects (Student Data Viewer Example)

CI5100 Software Development in Java Individual Programming Workshop Tutorial 5

Figure 1b,c,d Using the Application Model Class to Establish Implicit


Relationships between 2 sets of objects (Desktop Application Examples)

<-> assessments: ArrayList<Assessment>

Figure 2a Creating an Explicit Relationship between Objects of 2 Types [Note the


attribute in one class that creates the explicit relationship]

CI5100 Software Development in Java Individual Programming Workshop Tutorial 5

<-> clients : ArrayList<Client>


<-> pets : ArrayList<Pet>

<-> matches : ArrayList<Match>

Figure 1b,c,d Pet Shop, Talent Agency and Footbal Team project : Explicit Relationship
between Objects of 2 Types