Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

1 CSC72002 Assignment 2 Weight: 40% of your final mark Due: Midnight on # of Week 6 Specifications Your task is to complete various exercises in IntelliJ, using the Java language (OpenJDK 18), and to...

1 answer below »

1

CSC72002 Assignment 2
Weight: 40% of your final mark
Due: Midnight on # of Week 6
Specifications
Your task is to complete various exercises in IntelliJ, using the Java language (OpenJDK 18),
and to submit these via the MySCU link created for this purpose.
Marking criteria includes:
• Code compiles with OpenJDK 18
• Use of co
ect coding style, including the use of comments;
• Accuracy of coding;
• Use of suitable coding structures;
• Co
ect submission and naming conventions of assessment items as required.
Getting Help
This assignment is to be completed individually. It is the opportunity to gain an
understanding of the concepts of object-oriented programming and coding syntax. It is
important that you master these concepts yourself. You are permitted to work from the
examples in the study guide or textbook but you must acknowledge assistance from other
textbooks or classmates. In particular, you must not use online material or help from others,
as this would prevent you from mastering these concepts.
Who can you get help from? Use this diagram to determine from whom you may seek help
with your program.
Encouraged
Attribution Required
Ask tutor
Not acceptable
Lecturer Tutors
Online
Forums
Relatives
Students
outside unit
Hired
coders
Classmates
Private
Tutors
Othe
2

Getting started
In this assignment we will write the code that could form part of a student management
system.
To get started
• Create a new Java project called username-assignment2 in IntelliJ using OpenJDK
version 18 as the project SDK. In my case the project would be called ahendr10-
assignment2.
• In the src directory create five classes called:
o Person
o Staff
o Student
o Unit
o AssessmentTwo
• Copy the code for each class at the end of the assignment (see page 7-11) into the
classes you just created.
Please note:
• Your assignment will be marked using IntelliJ. If your project files for your
assignment were created in another IDE or do not open in IntelliJ, then your
assignment will not be marked.
• Your assignment must compile using OpenJDK version 18 or it will not be marked.
Module 3 - Advanced collections
The following part of the assessment covers the content in Module 3
Part 1 - Lists
The Unit class is missing the ability to store a collection of students who are enrolled in the
unit. For this part of the assignment:
1. Using a LinkedList, update the Unit class so that a unit can store a collection of
Students (i.e. datatype Student class) who are enrolled in the unit.
In addition to adding a LinkedList, you need to add the following methods to the Unit class
that work with the LinkedList:
1. A method called addStudent to add a student to the unit.
2. A method called removeStudent to remove a student from the unit.
3. A method called numberOfStudents that returns the number of students in the unit.
3

4. A method called printStudents that prints the details of all students enrolled in the
unit (you must use an Iterator or you will get no marks).
5. A method called allStudents that returns the LinkedList.
Demonstration
In the partOne method in the AssessmentTwo class:
1. Create a new Unit object.
2. Add a minimum of 5 students to the unit using the addStudent method.
3. Remove a student using the removeStudent method.
4. Print the number of students in the unit to the terminal using the numberOfStudents
method.
5. Print all student details in the unit using the printStudents method.
Part 2 – Collections Class
At the moment there is no way to sort the students who are enrolled in a unit. For this part
of the assignment:
1. Create a class (you can choose the name) that implements the Comparator interface.
When you implement the compare method from the Comparator interface you must
use a minimum of two of the instance variables in your comparison.
2. Now create a method in the Unit class called sortStudents that sorts the LinkedList
using the sort(List list, Comparator c) method in the Collections class.
Demonstration
In the partTwo method in the AssessmentTwo class:
1. Create a new unit.
2. Add a minimum of 5 students to the unit using the addStudent method.
3. Print all student details using the printStudents method to show the order of the
LinkedList before it is sorted.
4. Sort the LinkedList using the sortStudents method.
5. Print the students again using the printStudents method to show that the LinkedList
has been sorted.
Part 3 – HashMap class
The Unit class is also missing the ability to store staff members who are teaching the unit
and what their role in the unit is. For this part of the assignment:
4

1. Using a HashMap, update the Unit class so that a unit can store staff members (i.e.
staff objects) who are teaching in the unit and their associated role (i.e. a String). The
ole should be used as the key and the staff object should be used as the value.
In addition to adding a HashMap, you need to add the following methods to the Unit class
that work with the HashMap:
1. A method called addStaff to add a staff member and their role to the HashMap.
2. A method called removeStaff to remove a staff member and their role from the
HashMap.
3. A method called printStaff that prints the details (key and all staff details) for all staff
working in the unit (you cannot just print the HashMap, you must loop through it or
you will get no marks).
Demonstration
In the partThree method in the AssessmentTwo class:
1. Create a new unit.
2. Add a minimum of 5 staff to the unit using the addStaff method.
3. Remove a staff member using the removeStaff method.
4. Print all staff details in the unit using the printStaff method.
Hint
Remember that in a HashMap the key must be unique. You can add a number on the end of
the key to facilitate this. For example:
• One staff member may have the key UA
• One staff member may have the key Lecturer
• One staff member may have the key TutorOne
• One staff member may have the key TutorTwo
• One staff member may have the key TutorThree
Module 4 – Advanced exception handling
The following part of the assessment covers the content in Module 4
Part 4 – Implementing exception handling
At the moment we have not implemented any exception handling in our program. For this
part of the assignment:
5

1. Where applicable, make sure that your setters confirm that the values they are
writing to your instance variables are valid. If they are not, throw an
IllegalArgumentException and print an appropriate e
or message.
2. Add any other exception handling that you feel is appropriate to your program.
Demonstration
In the partFour method in the AssessmentTwo class:
1. Create an object and:
a. Pass a valid value to one of your setters that you modified to confirm that it
does not throw an IllegalArgumentException.
. Pass a non-valid value to one of your setters that you modified to confirm
that it throws an IllegalArgumentException.
Module 5 – Input/output
The following part of the assessment covers the content in Module 5.
An important part of many programs is the ability to back up data to a file then restore it as
needed. In this section of the assignment we will add this ability to our program.
Hint for exporting and importing data
A common way to store data in a file that needs to be imported at a later date is to use
comma separated values (csv).
This means that we store a record on a single line and we separate values using a comma (,).
For example, imagine a student has the following information:
• name – Alex Hendry
• email – XXXXXXXXXX
• age – 48
• studentNumber – 123456
• degree – BIT
• GPA – 5.9
You could store the student in the file on a single line like:
Alex Hendry, XXXXXXXXXX, 48, 123456, BIT, 5.9
When you read the file each line in the file will contain the details for a single student.
You can then use the split() method from the String class to split the line into the individual
values, and then use the values to create a new Student and add it to the LinkedList.
6
Part 5 – Writing to a file
The Unit class is missing the ability to back up the students who are enrolled in the unit. For
this part of the assignment:
1. Add a method to the Unit class called exportStudents.
2. The exportStudents method should write the details of all of the students that are
enrolled in a unit (i.e. stored in the LinkedList) to a file. The details for each student
should be written on their own line.
3. You must make sure to add all appropriate exception handling and e
or messages.
Demonstration
In the partFive method in the AssessmentTwo class:
1. Create a new unit.
2. Add a minimum of 5 students to the unit using the addStudent method.
3. Export the students to a file.
Part 6 – Reading from a file
The Unit class is also missing the ability to restore the students who are enrolled in the unit.
For this part of the assignment:
1. Add a method to the Unit class called importStudents.
2. The importStudents method should read the file
Answered Same Day Jul 25, 2022

Solution

Ajay answered on Jul 25 2022
64 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here