CS3231
OBJECT ORIENTED PROGRAMMING I
Name:__________________________
Date: ______________
PROGRAMMING ASSIGNMENT PART 2
Date issued: T2W2 4th Apr 2025
30 Marks
Date Due: T2W6 30th Apr 2025, 2100hrs
ACADEMIC INTEGRITY
Plagiarism, the unattributed copying of ideas, pictures, program code, or any product of
others (including AI tools), is forbidden. If you use anything that you did not produce
yourself, you are expected to cite it.
Use of ChatGPT and/or related AI tools are not allowed in the assignment.
You must cite all resources that have been used in the process of completing this part of your
project. This includes:
• Software – Name each and every software tool used, and write a brief explanation of
what you have used it for.
• Web pages, tutorials, videos and other resources – Provide a direct link to the resource
that, when clicked, goes to the page you have used.
• People – For any collaborator you have spoken to or discussed your project, list their
name, class (if applicable), and write a brief explanation of what you have discussed
with them and what you have learnt.
Failure to correctly cite sources will be taken as an attempt to cheat. Students who are caught
plagiarizing will face academic and disciplinary consequences.
ALL codes will be thoroughly checked and compared for any plagiarism. Any act of dishonesty
will render zero marks for both the originator and the “copy-cat”. Remember: Complete the
assignment using only your own work. Your originality not only upholds academic integrity, it also
builds character and brings genuine pride.
LATE WORK
A deduction of 2% of original assignment marks will be deducted per day you are late.
Please plan your time wisely.
INSTRUCTIONS
• This assignment is broken down into 6 tasks. Tasks 4 and 5 are optional bonus tasks.
•
Refer to Coursemology > Programming Assignment > Programming Assignment 2 for
downloads of resources and a video guide for expected program behavior.
•
Create a new JavaFX project in your IntelliJ IDE. Name your project PAPart2.
• You are to use the given Station, Line, Train, and Simulation classes in the zip file for
this part of the PA.
• You are reminded to organize your files in the JavaFX project using the MVC structure.
• Do not modify the classes given except where instructed to do so
•
Ensure that you thoroughly test your code. Uncompilable programs will only be marked
based on ONLY the FXML files (ie. No marks will be given for program functionality)
© NUS High School of Math & Science
Page 1 of 9
CS3231 Object Oriented Programming I
•
Assignment Part 2
You are to upload the following into Coursemology:
1. Zip up your entire JavaFX project folder. Name your zip file PAPart2_<your name>.zip
• This file should contain all .java and .fxml files, media, and resources. Ensure that the
folder / package structure you have created is captured in the ZIP folder.
• In other words, we should be able to copy your folder structure and files into IntelliJ
and run your code without moving, renaming or editing any file.
2. A screencast video (< 1 minute) to show that your program works and runs.
• Name your screencast PAPart2_<your name>.mp4 (or any other suitable format)
• Ensure that the screencast shows that the JavaFX program compiles and runs
• Showcase a "valid" flow of your program from start to finish
• Showcase an error message due to invalid input
• Use this opportunity to showcase your bonus visualization feature (described below)
• No narration or slides are required.
3. [BONUS] An executable JAR. Name it PAPart2_<your name>.jar
•
Your JavaFX program must work with ANY valid .csv data files, not just the samples given.
▪
Marks will be deducted for poor programming style. Things to look out for include:
o Meaningful identifiers and comments to explain your code
o Modularity of program
o Functional user interface design
o Good class design
o Robustness of program
Overview
Your teammates at NUSHLink were very satisfied with the text-based prototype you developed
and decided to engage you to enhance the features of the application. To improve user
experience, they would like you to convert the console-based system to a GUI-based application
where the staff can more easily simulate and visualize the train services in real-time. The
appearance of the program is as follows:
© NUS High School of Math & Science
Page 2 of 9
CS3231 Object Oriented Programming I
Assignment Part 2
The features of the program are as follows:
1. Users start by can load up a train line by typing the name of the file (without the ".csv"
extension) in the "File name" box and clicking "Load".
a. The contents of the line is displayed in the MRT line column
b. The simulation view under "Line Monitor" is loaded up
2. Users can add trains to the simulation. They do so by typing the Train ID into the Train
ID field and clicking "Add Train".
a. The train appears under the trains list
3. Users can tick the simulation forward by clicking "Tick"
a. The time counts up and the trains move forward on the Line Monitor
4. Users can search for trains in the simulation. They do so by typing in the search box,
which filters the train list as they type
a. When there is one train left on the list, they can click on "Monitor" or "Remove"
b. Monitoring a train shows its ID and status
c. When the simulation is ticked forward, the status automatically updates
d. You can stop monitoring a train by clicking "x"
e. Removing a train removes it from both the train list and the Line Monitor
5. Users can click on "Reset Simulation" to reset the timing and remove all trains
a. They will first be prompted for confirmation
6. The above GUI is robust against erroneous input, ie The following conditions will lead
to a pop-up box indicating the error
a. Invalid file name input
b. Trying to "monitor" or "remove" when there isn't exactly one train filtered in the list
c. Trying to add a train with an invalid ID
7. A page introducing the programmer is shown when the "About Programmer" text is
clicked
Refer to the video guide included on Coursemology for a full demonstration of the GUI features.
© NUS High School of Math & Science
Page 3 of 9
CS3231 Object Oriented Programming I
Assignment Part 2
Task Description
Setup Instructions
1. Configure IntelliJ to work with SceneBuilder.
2. Create a new JavaFX Project in IntelliJ.
3. Create packages within your project file structure, which should reside in
/src/main/java, according to the MVC structure.
4. Template controller, application, and FXML files are created for you by IntelliJ. Move the
provided files into the relevant package folders.
5. Modify the first line of each given source file to conform to your package structure.
6. Copy the provided .csv data files into the root folder of your project
Changes from PA1
Observe that the template code files given include solutions for PA1. However, some slight
changes have been made to better facilitate the requirements for PA2.
File
Method
Description
Line.java
Removed Method:
To avoid having to separately
loadFromFile()
construct the Line class and load
Added Constructor:
data from the file, file loading is
Line(String filename)
now combined with object
construction. You'll need to
complete this method.
Simulation.java
Added Constructor:
Simulation(String filename)
Helps instantiate the Line object by
loading from a file. This has been
written for you.
Added Method:
removeTrain(String trainID)
To access or delete trains by ID.
These have been written for you.
Added Method:
getTrain(String trainID)
Tester Files
Adapted based on the updated syntax above.
Task 1: Load MRT Lines from File
To facilitate easier populating of information, complete the Line constructor that takes in a
filename as a String, and loads the data from the file. The method has been marked as "TODO"
in Line.java. The format of accepted CSV files for this assignment is as follows:
Line
1
Format
[Line Name],[Code],[NumStops]
2
[Station Code],[Name]
3
[Station Code],[Name],[Time]
onwards
Description
Gives general information about the line – Its
name, code and total number of stops
Gives the station name and code of the first
stop.
Gives the station name and code for
subsequent stops, in addition to a number
which indicates the travel time from the
previous station to this station.
Consider the sample file shown on the right. The
way to interpret Line 3 is that it takes 3 minutes to
travel from NE1 Harborfront to NE3 Outram Park.
© NUS High School of Math & Science
1
2
3
North East Line,NE,17
NE1,Harborfront
NE3,Outram Park,3
(15 more lines follow…)
Page 4 of 9
CS3231 Object Oriented Programming I
Assignment Part 2
Method Summary
Type
Method
Description
void
Line(String filename)
Opens the file with the filename stated by the
argument filename.
(Constructor)
Use the information from the file to construct a
Line and populate all required information,
namely the name, code, stations and
travelTime.
For other concerns like exception handling,
check the tester files for more details.
We have provided you with only NEL.csv. However, your code should work with any valid
CSV file per the specifications above. You are encouraged to create your own files to test on.
Task 2: Design the GUI
Using Scene Builder, create the GUI as shown on Page 2 and in the video guide. You will need
2 FXML files, one for the main program and one for the About window.
Some important features you should take note (and you need to implement):
• The train logo must be clearly seen both within the program and as the application icon.
Both use the same file, Train.png, which is provided within the template files.
•
•
The TextAreas are not editable
All form elements other than the ones used to load a file are disabled to start with
•
About Programmer page should be a "pop up" with a "close" button
Refer to the video guide provided on Coursemology for a clear look at the features
described.
The GUI you create does not need to be an exact copy of what is shown, eg. Minor differences
in spacing, slight difference in color shades, or inexact wording in error messages will not be
penalized.
You should instead focus on using the correct types of controls, placing them in correct locations
within the GUI, and (in the next part), having them function as expected. Ensure that all required
elements are present.
© NUS High School of Math & Science
Page 5 of 9
CS3231 Object Oriented Programming I
Assignment Part 2
Task 3: Implement the Controller
Create a controller class and set up fx:ids and
event handler methods as required. Relevant
data validation and error checking needs to be
done accordingly. For error messages, use an
Alert Dialog to notify the user, eg.
The full list of required functionalities is as follows:
Your controller class should contain methods to handle each of the following:
• To handle request to load a file
• To handle typing in the train search box, filtering the list of trains in real time and
displaying the results immediately as the user types their search term
• To handle marking the selected train for monitoring
• To handle removing the selected train
• To handle removing the monitoring status of the current train
• To handle adding a train to the simulation
• To handle ticking the simulation forwards
• To handle resetting the simulation
• To open the About Programmer page
Some of these functions overlap in terms of their implementation. You are encouraged to reuse
code as much as possible in the form of methods, to reduce code length and prevent code
duplication.
The errors you are required to handle are as follows:
• Attempting to load a non-existent file
• Trying to "Monitor" or "Remove" a train when multiple candidates are possible,
based on the user's search term
• Trying to "Monitor" or "Remove" a train when no candidates are listed, based on
the user's search term
• Trying to add a Train with an invalid Train ID. A valid Train ID has exactly four
characters.
• Trying to add more than one Train on the same tick
Where possible, reuse error handling mechanisms already implemented in the given classes.
You are to create another controller class for the About Programmer page, which should
contain one method to close the window, in response to the "Close" button.
You are free to add your own attributes and methods to the Controller classes. Remember to
follow Object Oriented Programming best practices at all times.
Refer to the video guide for a clear look at all the functionality described above.
© NUS High School of Math & Science
Page 6 of 9
CS3231 Object Oriented Programming I
Assignment Part 2
Task 4: [BONUS] Implement a Graphical Visualization
For up to 3 bonus marks, create a graphical visualization of the MRT line based on the state
of the simulation. To do this, add an additional button to the bottom right corner of your program.
When clicked, your program pop up a separate window showing your visualization.
Note that in attempting this bonus question, you must not replace or remove any of the
functionality described in the previous pages, except the addition of the button to open up the
visualization. Your code for this part should not compromise or reduce the other functionality
of your program. You may add more methods to your code to support your visualization, but you
must not change or remove any code already given, or code that is required to solve the prior
tasks. You will lose marks if any of the program's requirements are not met exactly as described
in the previous pages.
Attempting this question will require you to read and research beyond what you have been taught
in class. Up to 3 bonus marks may be awarded for visualizations that are creative, aesthetically
appealing and/or of technical interest. It will get exponentially harder to get more marks out of the
3, so please finish the rest of the PA first, and only do this if you have the time and want to explore
more. Note that bonus marks are capped by the maximum mark of this assignment, ie. You will
not receive more than 100% marks.
Task 5: [BONUS] Create an Executable JAR File
For 2 bonus marks (awarded on an all-or-nothing basis), create an executable JAR file for
your program. This executable JAR should be able to launch your program when double clicked
on a computer with Java installed correctly. You are to submit your JAR file, name it
PAPart2_<your name>.jar, alongside your project zip file.
How to Create an Executable JAR File
1. JAR Files require an "entry point" containing the main() function that is not also a
JavaFX Application. Hence, create a new Launcher class in the same folder as your
Application, containing the following code:
public class Launcher {
public static void main(String[] args){MainApplication.main(args);}
}
Change "MainApplication" if required to reflect the name of your Application class.
2. Go to File → Project Structure → Artifacts, and add (+) a JAR. Then select “from Module
with dependencies”, selecting Launcher as the main class:
© NUS High School of Math & Science
Page 7 of 9
CS3231 Object Oriented Programming I
Assignment Part 2
3. To allow File I/O to continue to work, some modifications must be made to how file
paths are discovered by your JAR file. To achieve this, every reference to a file path
must be modified as follows:
Instead of:
String filename = "myFileName.csv";
Replace it with:
String filename = System.getProperty("user.dir") + "/myFileName.csv";
Note that this only changes how your program searches for files. The rest of what you
have learnt in File I/O continues to apply, without change. If this change is done
correctly, your code should still continue to work properly regardless of whether it is run
within IntelliJ or as a JAR file.
4. We can finally build our JAR file. Go to Build → Build Artifacts → (Your JAR file name)
→ Build.
After the build process is complete, observe that an "out"
folder is created for you in your project folder. Right-click
on your JAR file, select Open In → Explorer.
Then, copy the JAR file to another location on your computer. In
that folder, place the required data files. Then, double click on the
JAR file to run it!
If your JAR file does not run (eg. No response when doubleclicked), it could indicate several issues. First, ensure that your code works within
IntelliJ, any errors will cause your JAR file to simply not open, and runtime errors may
also lead to unexpected behavior.
Your computer may also need the correct version of Java (matching or newer than what
you used to build your program) installed and set up, outside of IntelliJ.
To receive your bonus 2M, your JAR file MUST be able to run correctly upon double-click as
long as it is put into the same folder as the CSV files on any machine with the latest version of
Java correctly installed.
Any requirements stated above not met will not qualify you for the bonus mark. Note that bonus
marks are capped by the maximum mark of this assignment, ie. You will not receive more than
100% marks.
© NUS High School of Math & Science
Page 8 of 9
CS3231 Object Oriented Programming I
Assignment Part 2
Task 6: Create a Screencast Video
Create a screen recording showing all of the following:
• Demonstrate that your program compiles and runs
• Showcase a "valid" flow of your program from start to finish by loading up a line, then
adding trains as you tick the simulation forwards.
• Showcase an error message due to invalid input
• Use this opportunity to showcase your bonus visualization feature (Task 4 above, if you
have attempted it)
Screencasts which are NOT submitted will be marked as though the program is
uncompilable.
You may use Microsoft PowerPoint’s “Screen Recording” feature to capture your screen.
1. Start your JavaFX application, then launch PowerPoint.
2. Click on the “Record” tab in PowerPoint, then click “Screen Recording”
3. Click “Select Area”, then drag to select the area around your JavaFX application. Click
“Audio” to disable audio recording, then click “Record”
4. Demo your application
5. When done, press the Windows Logo Key + Shift + Q on your keyboard to stop the
Recording
6. Your recording appears embedded in the PowerPoint slide. Right click it, click “Save
Media As”, and save your file for submission to Coursemology.
You may also use alternative screen recording tools, like OBS. Ensure that your video is saved
as an H.264-encoded MP4 file with sufficient compression.
Please review your video before submission. Ensure that the correct window is captured, and
that the file size is reasonable – A 1-minute screencapture is unlikely to exceed 50MB with correct
compression.
© NUS High School of Math & Science
Page 9 of 9
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )