A simple console‑based Java application that demonstrates Object‑Oriented Programming principles through a university transport management simulation.
- 📁 Project Structure
- 🧠 OOP Concepts Demonstrated
- 🚀 How to Compile and Run
- 🛠️ Using VS Code
- 📝 Notes on the Code
- 🧪 Extending the Project
- 📄 License
After applying the package vu.utms, the source files are organised as follows:
TransportSystem/
├── src/
│ └── vu/
│ └── utms/
│ ├── User.java
│ ├── Student.java
│ ├── Lecturer.java
│ ├── TransportOfficer.java
│ └── TransportDemo.java
├── nbproject/ (NetBeans metadata – optional)
├── build.xml (Ant build file – optional)
├── manifest.mf
└── README.md (this file)
| Concept | Implementation in this project |
|---|---|
| Inheritance | Student, Lecturer, and TransportOfficer extend the base class User. |
| Method Overriding (Polymorphism) | Each subclass overrides the requestTransport() method to provide role‑specific behaviour. |
| Polymorphism | The main() method treats all objects as User references, yet the correct overridden method is called at runtime. |
| Abstraction | The User class defines a common interface; the concrete subclasses hide implementation details. |
| Encapsulation | Fields are private and accessed via getters/setters (implied). |
- Java JDK (version 8 or higher) – Download
- A terminal / command prompt
-
Navigate to the
srcfolder:cd TransportSystem/src -
Compile all Java files (the package structure is automatically recognised):
javac vu/utms/*.java -
Run the main class:
java vu.utms.TransportDemo
You should see output similar to:
Student Alice requests transport to attend classes for Computer Science.
Lecturer Dr. James requests transport for a departmental field visit.
Transport Officer Mr. Alex is scheduling transport for other users.
If you prefer Visual Studio Code:
- Ensure the "Extension Pack for Java" is installed.
- Open the project root folder in VS Code.
- The Java language server will automatically detect the package structure.
- Open
TransportDemo.javaand click the "Run" triangle above the main method – or pressCtrl+F5.
(No manual compilation needed – the extension compiles all sources on the fly.)
- All classes reside in the package
vu.utms. Useris the base class; it may be abstract or concrete (depending on your implementation) – but it must provide a methodrequestTransport()that subclasses override.TransportDemocreates one instance of each user type and invokesrequestTransport()on each, demonstrating polymorphic behaviour.
You can easily add new user roles:
- Create a new class, e.g.,
Visitor.java, that extendsUser. - Override
requestTransport()with custom logic. - Instantiate it in
TransportDemo– the existing code will handle it polymorphically without any changes.
This project is for educational purposes only. Feel free to use and modify it for learning Java OOP.