Lab 2
[valid 2025-2026]
Starting from this week...:
- Comment and properly format the source code of your programs (otherwise: -0.5 points)
- Use the naming conventions for writing Java code.
"Naming conventions make programs more understandable by making them easier to read." (otherwise: -0.5 points)
- Use the API documentation: Java Platform, Standard Edition API Specification (otherwise...)
Objects and Classes
An instance of the "Best Route Problem" consists of locations and roads. Locations may be cities, airports, gas stations, etc.
Two locations may be connected by a road, or not. Roads may be highways, express, country, etc.
- Each location has a name, type and x, y coordinates (assume that the locations are placed in a cartesian coordinate system).
- Each road has a type, length and a speed limit. The length of a road should not be less than the euclidian distance between the location coordinates.
We consider the problem of determining the "best" route from one location to another.
The main specifications of the application are:
Compulsory (1p)
- Create an object-oriented model of the problem. You should have (at least) the following classes: Location, Road.
- Each class should have appropriate constructors, getters and setters.
Use the IDE features for code generation: constructors, getters or/and setters.
- The toString method form the Object class must be properly overridden for all the classes.
- Create and print on the screen various objects of the two classes.
Homework (2p)
- Implement the road types using an enum.
- Override the Object.equals method for the Location and Road classes.
The problem should not allow adding the same location or road twice.
- Create dedicated classes for locations: cities, air ports, gas stations etc.
Each concrete location class may have additional specific propertes (population, number of terminals, gas price, etc.)
Location must be an abstract, sealed classs.
- Create a class that describes an instance of the problem.
- Implement a method that determines if a problem's instance is valid.
- Implement an algorithm for determining if it is possible to go from one location to another using the given roads.
- Write doc comments in your source code
and generate the class documentation using javadoc.
Advanced (2p)
- Create a class to describe the solution.
- Implement an algorithm to find the best route from one location to another, either as the shortest route, or the fastest route.
- Generate large random instances of the problem and analyze the performance of your algorithm (running times, memory consumption).
Identify the hot-spots in your code using a profiler.
(Warning: No points are awarded unless the implementation can be clearly explained).
Resources
Objectives
- Create a project containing multiple classes.
- Instantiate classes and manipulate objects.
- Understand the concepts of: object identity, object state, encapsulation, property, accessors/mutators.
- Override methods of the Object class.
- Understand uni- and bi-directional relations among objects.
- Understand the notion of multiplicity (one-to-one, one-to-many, many-to-many).
- Implement instance-level relationships among objects (association).
- Implement class-level relationships (generalization)
- Work with abstract classes.
- Get used to the naming conventions of the Java language.
- Generate documentation using javadoc.