You are on page 1of 9

The University of Sheffield

Assignment 2
COM6471 Foundations of Object Oriented
Programming (AUTUM 2!1"#14$
%e&ort
ame' (dmundo A)berto Cande)as *asurto
Professor' +os,i -ot,o
The University of Sheffield
Assignment 2
Pur&ose'
Creation of a ,as, tab)e .ia a /in0ed1)ist and a ,as, function in order to be used to
count 2ords from a te3t fi)e and dis&)a4 t,em on screen5
The University of Sheffield
Tas0 1' Linked-list
Purpose:
Creation of a linked-list in order to be used in the hash table implementation.
In a linked list, objects are arranged in a linear order, determined by a reference in each
object, providing a fleible representation for dynamic sets.
!he recursi.it4 in the program "orks by invoking the method: #set6ord($ method$ putting the
"ords inside the linked list as "ell counting each one of them.
%irst, the method compares the "ord that "as fed into the method if the "ord already eists
&count ' (& )keeps track of repeated "ords* other"ise go to the net object, if an object eists
that is: &not null& then calls again )in a recursi.e "ay* the &set+ord)*& method in order to count
it do"n again and put it into the net position inside the Linked-list, on the other hand if the
net object )element* in the Linked-list is the last element &net -- null&, then creates a ne"
object inside the Linked-list.
.ere&s the code of the method:
//put method, increments 012count013 if 012"013 matches 012"ord013. If they are
different and if the net object eists, 012"013 is passed on to the net object. 4ther"ise, it
creates a ne" object for 012"013

public void set+ord)5tring "* 6

if )".e7uals)"ord**6
count'',

8else
if )net9- null*6
net.set+ord)"*,

8else
if )net--null* 6
net-ne" :e"LinkedList)",inde'(*,
8
8
The University of Sheffield
increments #count$ if #"$ matches #"ord$. If they are different and if the net object
eists, #"$ is passed on to the net object. 4ther"ise, it creates a ne" object for #"$.
is6ord($ method: !his method returns #true$ if #"$ matches #"ord$. If they are different and if
the net object eists, #"$ is passed to the net object. !he method eventually returns #false$
only "hen #"$ does not match any of this and the follo"ing objects.
public boolean is+ord)5tring "* 6
boolean flag - false,
if )".e7uals)"ord** 6
flag - true,
8
else if )net9-null* 6
flag - net.is+ord)"*,
8

return)flag*,
8
getCount($ method: Counts "ords in the Linked-list. If the variable ;"; matches a "ord the
counter is &count ' (& else goes to the net object to count it out. !he method eventually
returns #<$ if #"$ does not match any of this and the follo"ing objects.
public int getCount)5tring "* 6
int returncount-<,
if )".e7uals)"ord**6
returncount-count,
8
else
if )net9-null*6
if)net.e7uals)"**6
returncount- )net.count*,
8 else
returncount-<,
8
return returncount,
8
get/eng,t($ method: =eturns the length of the Linked-list. > variable &>& is set to ?ero, if the
net object in the Linked-list is e7ual to &null& then the si?e of the Linked-list is <, other"ise if
The University of Sheffield
the net element is different to null compares the actual element to the net one
and assign it the variable &>&
get6ord($ method: =eturns a "ord string specified by an inde in the list. +e feed the
method "ith an &number& )the inde of the "ord "e are looking for* if finds it in the actual
position then retuns the "ord other"ise jump to the net posistion.
public 5tring get+ord)int j* 6
5tring C-;;,
if )j--inde*6
C-"ord,
else if)j--net.inde*6
C-net."ord,
8
return C,
8
to5tring)* method: @isplays the attributes of the objects.
public 5tring to5tring)* 6
return );An; /B'inde '; ;B/' "ord '; );' count ';* ; ' net *,
8
ote: If you "ant to test each one of the tasks )programs* individually refers to the folder
named: !est!asks, those programs are built to be tested individually.
The University of Sheffield
Pur&ose'
=eading data from eternal files being invoke through the java program and manipulation of
graphical interface via CasyDraphics package form !he Eniversity of 5heffield.
%iles city(.tt, cityF.tt, cityG.tt, and cityH.tt contain monthly rainfalls )ordered from Ianuary
to @ecember* of four cities. !he program =ain%alls.java reads monthly data from the files,
and dra"s multiple graphs sho"ing rainfalls in various aspects: Jonthly rainfalls for each city
and/or month, statistics such as the maimum, the average and the minimum rainfalls for
each city and/or month.
%or the representation of the graphs "as chosen a line graph and bar charts.
The University of Sheffield
(3ecution of t,e &rogram'
Kjavac =ain%alls.java
Kjava =ain%alls
%ig(.( !he total amount of rainfall during the year in city(.
ote' !he style of the graphs for cityF, cityG and cityH are the same therefore omitted.
The University of Sheffield
A.erage of rainfa)) &er cit4'
%ig (.F It "as found that the average of rainfall in city( is of (L< in cityF L(, cityG (HM and
cityH NL during the year.
The University of Sheffield
Ma3imum 7 Minimum

%ig (.G It "as found that the maimum rainfall in city( "as G<M the minimum (FF, for cityF
maimum (OG P minimum G<, for city G maimum GGN minimum N<, for cityH maimum (((
minimum G

You might also like