0% found this document useful (0 votes)
86 views11 pages

Unit 1 - Final Exercise

This document outlines the requirements for a JavaFX application to manage a list of flights at an airport. It describes: 1. Setting up the project structure with packages for the model, utilities, and JavaFX components. 2. Key classes like Flight to store flight details, and FileUtils to load/save flights from a text file. 3. The main JavaFX view containing a table of flights, filters, and a form to add/delete flights. When run, it loads flights from a file and populates the table. Filters can be applied to update the table contents. 4. Optional improvements like adding charts to visualize flight data or updating the stored flight list on application close. Strict
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views11 pages

Unit 1 - Final Exercise

This document outlines the requirements for a JavaFX application to manage a list of flights at an airport. It describes: 1. Setting up the project structure with packages for the model, utilities, and JavaFX components. 2. Key classes like Flight to store flight details, and FileUtils to load/save flights from a text file. 3. The main JavaFX view containing a table of flights, filters, and a form to add/delete flights. When run, it loads flights from a file and populates the table. Filters can be applied to update the table contents. 4. Optional improvements like adding charts to visualize flight data or updating the stored flight list on application close. Strict
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Unit 1.

Final exercise
FlightsFX

Service and Process Programming

Arturo Bernal
Nacho Iborra

IES San Vicente

This work is licensed under the Creative Commons Attribution-


NonCommercial-ShareAlike 4.0 International License. To view
a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/4.0/
Index of contents
Unit 1. Final exercise.....................................................................................1

1.Introduction and first steps..............................................................................................3


1.1.Setting up the project..............................................................................................3
2.Class structure................................................................................................................5
2.1.The Flight class.......................................................................................................5
2.2.FileUtils class..........................................................................................................5
2.3.Other useful classes................................................................................................6
3.The JavaFX application..................................................................................................7
3.1.Designing the main view.........................................................................................7
3.2.How should it work?................................................................................................8
4.Optional improvements.................................................................................................10
4.1.Adding charts........................................................................................................10
4.2.Adding CSS styles................................................................................................10
4.3.Update flights........................................................................................................10
5.Evaluation rules.............................................................................................................11
5.1.Compulsory part....................................................................................................11
5.2.About the optional improvements..........................................................................11

Service and Process Programming Unit 1. Final exercise 2


1. Introduction and first steps
In the final exercise of this unit we are going to implement a JavaFX application to manage
a list of flights of an airport. With this application, we will be able to filter flights according to
some criteria. The appearance of the application will be more or less like this:

1.1. Setting up the project


We are going to create a JavaFX project (a FXML application, to be more precise), called
FlightsFX:

Once the project is created, inside the Source Packages section, create the following
packages and subpackages:

Service and Process Programming Unit 1. Final exercise 3


flightsfx package, which will be our main package with the JavaFX main class and
controllers
flightsfx.model package, to store our model (Flight class, as explained later)
flightsfx.utils package, to store some useful classes

Service and Process Programming Unit 1. Final exercise 4


2. Class structure
Besides the JavaFX main application with the FXML file and controller (we will see them in
next section), we are going to need some additional classes to store the information about
the flights, and help us do some basic operations.

2.1. The Flight class


Add a new class inside the flightsfx.model package called Flight. This class will have the
following attributes:
The flight number (a String, such as "IB601N")
The destination (a city name)
The departure time and date (use a LocalDateTime object)
The flight duration, in hours and minutes (for instance: 2:30 will mean 2 hours and
30 minutes). Us a LocalTime object to store this information.
Besides, we will add two constructors:
A constructor with the flight number
A constructor with all the attributes
Add the getters and setters for each attribute.

2.2. FileUtils class


In order to get and save the information from / to text files, we are going to create a class
called FileUtils in the flightsfx.utils package. This class will have a set of useful static
methods, such as:
static List<Flight> loadFlights() to load flights from a given text file
static void saveFlights(List<Flight>) to save a list of flights in a text
file.
For both operations, there will be a file called flights.txt in the project's root folder.
2.2.1. Flights file structure
The structure of the text file containing the flight information (flights.txt) will be as follows:
flight_number;destination;departure;duration
For instance:
IB601N;Oviedo;28/10/2017 11:33;0:50
RY112A;Edinburgh;31/10/2017 16:05;2:35
...
where the attributes are separated by ';'

Service and Process Programming Unit 1. Final exercise 5


2.3. Other useful classes
Although it is not compulsory, it may be useful to add some other classes. For instance, a
class called MessageUtils (in the flightsfx.utils package) to show different Alert messages.
It could have these static methods:
static void showError(String message) to show error messages
static void showMessage(String message) to show information
messages
...
You can add as many classes as you need inside this package.

Service and Process Programming Unit 1. Final exercise 6


3. The JavaFX application
Let's create the JavaFX application classes. Follow these steps:
1. The JavaFX Main Application will be called FlightsFX inside flightsfx package.
2. There will be an FXML file called FXMLMainView.fxml with its associated controller
(FXMLMainViewController.java). Both files can be placed in the flightsfx package,
as you did with the main application.
3. Make sure that your FlightsFX main class loads the contents from the FXML file.

3.1. Designing the main view


Use now Scene Builder to design the main scene and get an appearance similar to this:

You can, for instance, use a vertical SplitPane as the main container, and then:
Place a TableView with its corresponding TableColumns in the upper section
Place the form controls below the table view in the lower section (use the
appropriate(s) container(s) to display these controls).
Remember to set an fx:id to each element that may need to be accessed from the
controller.

Service and Process Programming Unit 1. Final exercise 7


3.2. How should it work?
As soon as the application starts, it will need to load the file flights.txt from the root path of
the project into a list of Flight objects, and then associate this list with the TableView, so
that it will show a flight in each row:

3.2.1. Insert/Delete operations


Once the list is loaded, we can do the following operations:
If we fill the Flight number, Destination, Date and Duration fields in the bottom form
(none can be empty), and click on the Add button, a new flight will be added to the
flight list (and to the table)
Delete button must be disabled at the beginning (use the setDisable method to do
this). When we click on any flight from the table, then it will turn enable and we will
be able to remove the flight from the list.
3.2.2. Applying filters
Below the flight form, there is a choice box (or combo box, if you prefer), with a list of
filters:
Show all flights: it will show every flight from the list in the table
Show flights to currently selected city: it will show all the flights to the city of the
currently selected flight in the table. If no flight is selected, then this choice will
cause an error alert.
Show long flights: it will show all the flights whose duration is longer than 3 hours.

Service and Process Programming Unit 1. Final exercise 8


Show next 5 flights: it will show only the next 5 flights that will depart from the
airport. To do this, you must exclude all the past flights, order the filtered list by
departure date and time, and then limit the result to 5 flights (use filter to do all this
stuff).
Show flight duration average: it will calculate the duration average of all the
flights, and show the result in an Alert with the format hh:mm.
All these filters must be implemented using streams and lambda expressions whenever
they are needed.
3.2.3. Saving changes
Whenever we try to close the application, we must capture this event and save in the
flights file the current flight list (not the one shown in the table, since it may be filtered).

Service and Process Programming Unit 1. Final exercise 9


4. Optional improvements
Besides the compulsory part of this exercise, you can try to implement these optional
improvements to get a better mark.

4.1. Adding charts


In the left section of Scene Builder there is a subsection called Charts, with a list of charts
that can be added to JavaFX application. Try to add an option to show a pie chart with the
number of flights per destination. You must show it in a separate scene within the same
stage (see in Annex VI how to create applications with multiple views).

4.2. Adding CSS styles


Add a CSS stylesheet with some default styles for the main view, such as:
Background color: choose among any color other than gray, black or white
Font color: according to the background chosen, it can be either white or gray
Every button must have a black background with white text color
Other styles that you may want to add

4.3. Update flights


Add a new option to the form below that lets you update a flight data without having to
delete and add it again to the list.

Service and Process Programming Unit 1. Final exercise 10


5. Evaluation rules
5.1. Compulsory part
To get your final mark, the following rules will be applied:
Class structure (model and utils packages), with the Flight and FileUtils classes with
the corresponding code, and every other additional useful class that you may need:
1 point.
JavaFX application layout, similar to the one shown in previous figures: 1 point. You
must use the appropriate layout containers to arrange the controls properly in the
view (HBox and/or VBox are very helpful).
Loading flights into the list and table, and adding/removing flights from the list and
table (disabling delete button when this operation can't be done): 3 points
Applying filters from the bottom list: 0,75 point each filter (apart from Show all
flights)
Showing error messages whenever something can't be done (for instance, deleting
a flight without selecting one from the table, or adding a new flight with some empty
field): 1 point
Code documentation (Javadoc comments for every class and public method or
constructor), cleanliness and efficiency: 1 point

5.2. About the optional improvements


If you decide to implement any optional improvement for this exercise, keep in mind that:
If your compulsory part is lower than 10, you can get up to 10 points by
implementing one (or many) of the optional improvements (up to 1 point per
improvement)
If your compulsory part is perfect (10 points), you can get up to 11 points by
implementing ALL the optional improvements.

Service and Process Programming Unit 1. Final exercise 11

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy