[ad_1]
Objectives:
Define the generic LinkedList class.
Define the generic Node class nested in the LinkedList class.
Define the generic ListIterator class nested in the LinkedList class.
Implement the Iterable interface for LinkedList .
Practice traversing your list via iterator() and an enhanced for loop (i.e. for-each loop).
Define the new class type: GraphView.
Practice pair programming.
Discuss your approach with your teammate and briefly describe each pair’s task.
Material from:
Program Guidelines, Reference: Lab Homework Requirements from Module.
Class TestGenericList as the test file for Part 1 in your assigned GitHub repository.
The class ChartGraph as the test file for Part 2 in your assigned GitHub repository.
Class CountrySelector under the view package and class DataModel under
the model package.
The csv package where you will place your previously implemented CSVParser class
and InvalidFileFormatException class.
Example data files (included under the resources folder) in your assigned GitHub repository.
Application Overview
We will expand upon the previous programming assignment so that we no longer rely on a fixed array
size for the Indicator objects. Instead we will rename the CountryList class and update it so it can
handle any data type. We will take advantage of generics to create a LinkedList of Country objects
and Indicator objects.
Similar to your previous project, the data will be in Comma-Seperated Value (CSV) format. The
format of the CSV file is as follows:
Data Source,World Development Indicators,
Indicator,[indicator]
Last Updated Date,[Date in MM/DD/YY format]
Number of countries [N number of countries]
Country Name,[year 1],[year 2]..[year M]
[country name 1],[data for year 1],[data for year 2]…[data for year M]
[country name 2],[data for year 1],[data for year 2]…[data for year M]
…
[country name N],[data for year 1],[data for year 2]…[data for year M]
Note: Despite using a list structure we still need to know N for the Number of countries. Similar to
previous assignments we will parse the input file first before selecting a random number of countries
to store in our list.
6/18/2019 Programming Assignment #9
https://foothillcollege.instructure.com/courses/9422/assignments/233976 2/8
To ease the transition of developing an application which visualizes the list of Indicator objects for a
given Country object, the assignment has been divided into Part 1 and Part 2. Part 2 builds on top of
Part 1. You only need to provide one source src folder with your final product for Part 2.
Practice Pair Programming:
In this class, we will practice Ping-Pong style of pair programming in all
aspects of the programming project.
This means that as you and your team progresses in the programming project,
make sure that you discuss each feature of the project with your teammate. Your
team repository must show contribution from each person for both parts of the
project.
Part 1: The Program Spec
Create the container class LinkedList such that it contains a collection of generic Node objects.
Define the nested ListIterator class to enable the user to iterate over the elements.
The test class TestGenericList will test the parameterized LinkedList class by creating
a LinkedList of Country objects. In turn each Country object holds
a LinkedList of Indicator objects.
class Node
Modify the class Node class to be nested within the class LinkedList. The purpose of this class is to
contain the data of interest. Similar to before the Node class will link the different elements into a
singly linked list structure.
Attributes:
Instance variable data which is of a generic type.
Instance variable next which is of type Node.
Methods:
A constructor that initializes one instance variable.
Receives one arguments:
a generic type for the data of the current instance.
Set the next instance variable to null.
A constructor that initializes both instance variables.
Receives two arguments:
6/18/2019 Programming Assignment #9
https://foothillcollege.instructure.com/courses/9422/assignments/233976 3/8
a generic type for the data of the current instance.
a Node object for another node we want to connect to. Connect the two nodes such that
the current next instance points to there other Node object.
The method getData() which does not receive any arguments and returns a generic type data.
The method getNext() which does not receive any arguments and returns a Node type for
the nextobject.
The method setNext() which receives one argument of type generic Node type and does not
return anything. Use the argument to update the next instance variable.
The method toString() which returns the String representation of the data instance variable.
class ListIterator
Define the class ListIterator to be nested within the class LinkedList. The class ListIterator should
implemented the generic interface Iterator. The purpose of this class is to traverse the collection of
objects within the list.
Attributes:
Instance variable current which is of type Node.
Methods:
A constructor that receives no argument. Calling the constructor initializes the instance
variable currentto the beginning of the list.
The method hasNext() which does not receive any arguments and returns boolean value. If the
list has another element this method should return true.
The method next() which does not receive any arguments and saves and returns
the data that currentis pointing to. Then moves current to the next available reference.
The method remove() which does not receive any arguments and does not return anything. For
now a call to this method should throw an UnsupportedOperationException() to indicate that
the operation is not supported.
class LinkedList
Modify the LinkedList to implement the generic Iterable interface and to contain at minimum the
following attributes and methods:
Attributes:
6/18/2019 Programming Assignment #9
https://foothillcollege.instructure.com/courses/9422/assignments/233976 4/8
Instance variable head of type Node which points to the beginning of the list.
Instance variable size of type int which keeps track of the number of elements in the list.
Methods:
A constructor which receives no arguments and creates an empty list by:
initializing head to null to indicate the list is empty.
initializing size to 0 since by default we have zero elements in the list.
The method add() that adds that new object to the end of the list.
Receives one argument:
a generic object as parameter. This is the new data to be added to the list.
Note: Consider adding an instance variable which points to the tail of the lis t.
Does not return anything.
The method contains() whether the list has the data of interest.
Receives one argument:
a generic object for the object we want to search for.
Returns a generic object if the object is found in the linked list. If the object is not found
return null.
Note: Make sure to override the equals() method of all classes which you will use for
the data portion of the class Node.
The method getIndex() which returns the generic object at the requested index*.
Receives one argument:
an int value for the requested index.
Returns the specific generic object located at the requested index.
The method insertAtIndex() which enables the user to add a generic object to a chosen location.
Receives two arguments:
a generic object for the object we want to insert in the list.
an int value for the index of the location we want add our new element.
*Note: The user may request an index that is out of bounds:
If the requested index < 0, then throw an IndexOutOfBoundsException . If the user requests an index > the size of the list, then we will assume the user
misjudges the number of elements in the list. So, add the element to the end of the list.
Does not return anything.
The method iterator() that returns an object of type ListIterator.
Note: You must demonstrate the correct implementation of your i terator.
For example, by traversing your LinkedList of Indicator objects. Remind er to create
an Iterator object:
Iterator iterator = indicators.iterator();
The method size() which returns the instance variable size to indicate the number of elements in
the list.
6/18/2019 Programming Assignment #9
https://foothillcollege.instructure.com/courses/9422/assignments/233976 5/8
The method toString() which returns a String object containing the text representation of every
element in the list.
class Country
Once you have successfully tested your implementation with a generic LinkedList that accepts
a Countryas type parameter. Modify your Country class as follows:
Attributes
A linked list of Indicator objects called indicators (previously of type array).
Note: Do not create a new LinkedList class.
(optional) Two fields of type int called minYear and maxYear.
Methods
A constructor with the name of the country as the only parameter.
Note: previously your constructor received two parameters: the na me of a country and the number
of years. We no longer need the second parameter as we are storing the Indicator data in
a LinkedListstructure.
Define the method addIndicator() which adds an Indicator object to the end of years list.
Receives one argument:
An Indicator object for the new data to add.
Does not return anything.
Update the equals() method so that it checks whether the Object argument is
an instanceof a Stringobject as well as a Country object. If the argument is an instanceOf:
a String type, then cast the argument to a String and check that the name attribute
of this instance is equal() to the casted reference.
a Country type than casts the argument to a Country object and checks whether
the name attribute equals() to the name attribute of the casted object.
Update the method getIndicatorForPeriod() method, use an iterator() of
type Iterator to traverse your linked list of Indicator elements.
Update the method toString() method such that it uses the enhanced for loop (for-each loop) to
traverse your linked list of Indicator objects.
Suggestion
To determine the range of valid years for the list Indicator objects:
6/18/2019 Programming Assignment #9
https://foothillcollege.instructure.com/courses/9422/assignments/233976 6/8
In the Country constructor:
set minYear to a large number. For example set minYear to
the static value Integer.MAX_VALUEwhich is a constant holding the maximum value
an int can have.
set maxYear to a small number such as 0 (zero). For our purposes we can assume
that Indicatorvalue will always be zero or a positive value.
Whenever an Indicator value is added to the list, check if you need to
update minYear and maxYear.
Later use minYear and maxYear to check if the requested period is valid.
Part 2: The Program Spec
By now you will have several classes defined under one package. Let’s reorganize so that it is easier
to understand the role of the different classes. We will be using a modified Model View Controller
(MVC) design pattern .
Package Structure
Modify the java classes in your src folder into three packages.
Suggestion: For example place your java classes in the three packages described below.
csv, which includes utility classes such as our previously defined CSVParser class
and InvalidFileFormatException class.
model, which includes the provided DataModel class.
view, which includes the provided ChartGraph class and CountrySelector class and the newly
defined GraphView class.
Note: You are welcome to organize your implementation differently. If you choose a different structure
(to receive full credit) you must describe your approach in the README.txt file.
IndicatorType
You previously designed and implemented the enum IndicatorType. We will update the type so that
depending on the constant, the caller can specify a different label. Modify the IndicatorType as
follows:
Attributes:
Instance variable label which is of type String which the caller will use to get a description of the
constant.
Add a field to each constant. Example fields are:
INVALID (“Invalid Data”)
GDP_PER_CAPITA (“GDP per capita (current US$)”)
6/18/2019 Programming Assignment #9
https://foothillcollege.instructure.com/courses/9422/assignments/233976 7/8
SCHOOL_ENROLLMENT_PRIMARY(“School Enrollment In Primary (% net)”)
SCHOOL_ENROLLMENT_SECONDARY(“School Enrollment In Secondary (% net)”)
SCHOOL_ENROLLMENT(“School Enrollment In Primary and Secondary”)
Note: As long as the fields are descriptive, you are welcome to modify the fields which we will
use to provide description to the axis labels of GraphView class.
Methods
The accessor method getLabel() which receives no arguments and returns the instance
variable label. Call this when you are setting the xAxis and yAxis instance variables of
the GraphView class.
GraphView
You previously designed and implemented a parameterized linked list from a random selection of
countries read from the CSV file. Now you are to write the class GraphView which extends
the parameterized LineChart from javafx.scene package. GraphView will create a data series for
each Country object.
Attributes:
Instance variable called xAxis and yAxis of type NumberAxis, which are the axis for the chart.
Instance variable called model of type DataModel, which provides access to the data read from
the CSV file(s).
Methods:
A constructor which initializes the axis and data model of the current instance.
Receives one argument:
a DataModel object and sets it to the model instance variable.
Initialize the xAxis and yAxis by calling the super class NumberAxis() constructor as follows:
super(new NumberAxis(), new NumberAxis());
Set the label of each axis to the appropriate description by referring to the IndicatorType.
The method seriesFromCountry() which create a Series object with all the years and
corresponding data of the current Country object.
Receives one argument:
a Country object whose data is to be converted to a series.
Returns a Series object. The series should be based on
the Indicator data of the Country object.
Example approach:
First create a new s eries for the current Country object:
XYChart.Series series = new XYChart.Series<>();
6/18/2019 Programming Assignment #9
https://foothillcollege.instructure.com/courses/9422/assignments/233976 8/8
Then set the name of the series:
First create a new series for the c urrent Country object:
series.setName(currentCountry.getName());
Then for each Indicator create a new XYChart.data:
First create a new series for the current Country obje ct:
series.getData().add(new XYChart.Data<>(someYear, someValue));
The update() method described next will use the return value to add the series to the LineChart.
Recall that the chart is the current instance of GraphView. The series you create will be
represented by a line in the chart.
The method update() which goes through the list of Country objects and creates a series from
each element. Use the getData() method to add a series to this LineChart object:
XYChart.Series someSeries = this.seriesFromCountry(currentCountry);
this.getData().add(someSeries);
Task Description:
Note: For this portion, late submissions are not accepted.
A. One or two paragraphs describing how you will divide your work when you are not pair
programming. Include a list of what features each person is responsible for.
Note: The goal is to clarify what each teammate is responsible to complete w hen you are not
working side-by-side.
Part A of Task Description and initial commit due by the Sunday of project opening.
B. One or two paragraphs describing how you ended up dividing your work when you were not pair
programming. Include a list of what features each person worked on.
Note: If you’re working together synchronously side-by-side then you are pair programming.
Otherwise, you are doing traditional asynchronous programming.
Include all classes and major methods such as the GraphView constructor.
Include whether you used git Branches to commit your work.
Include how you decided when to synchronize (or merge) your work iteratively.
Part B of Task Description due at project due date.
[Button id=”1″]
[ad_2]
Source link
"96% of our customers have reported a 90% and above score. You might want to place an order with us."
