Assignment 2 - Travel Simulation

Due - Sunday, October 6, 2024

This is a group project of 2 or 3 students per group. The groups can be found in the document Assignment2_Groups.docx.

Introduction

A travel simulator simulates the travel of many types of vehicles. The simulator uses certain function calls that all vehicles have to adapt to. The simulator adds fuel to the vehicles and has them travel. The distance, time, fuel level and fuel costs are then reported.

Legacy code exists for three types of vehicles: the boat, the car, and the airplane. Each vehicle has its own functions for adding fuel, travelling, and reporting information. The travel simulator therefore should be able to extract or set information for each of these types of vehicles. The problem is to set and get information in a unified way for all types of vehicles.

Design Considerations

You must decide if you are going to use one of the standard design patterns that you have learned so for, or create a custom one. Either way, you must provide a UML diagram of your implementation.
You can write your code in one of the following four languages: C++, C#, Java or Python. Explain your choice, keeping in mind the principles of software engineering regarding reusability and extentibility. Also keep in mind that at least one of your assignments has to be written in Java and at least one in C#.

The Travel Simulator

The contemporary travel simulation for a boat, car and airplane assumes each vehicle has a full tank of fuel, and has the boat travelling 100km, the car 1,000km, and the airplane 10,000km. Information is then printed for each. Each vehicle then has fuel added. The boat has 120L of fuel added, the car 40L, and the airplane 50,000L of fuel. Each travels again. The boat travels 100km, the car 1,000km and the airplane 10,000km. Information is then printed for each. Note that although each vehicle uses different function names for getting and setting information, the travel simulator assumes a unified interface.

Code for the travel simulator (which is incomplete) can be found at:
C++: TravelSimulation.cpp,
C#: TravelSimulation.cs,
Java: TravelSimulation.java,
Python: TravelSimulation.py.

Code that contains a vehicle class (which is incomplete) and a function that prints information for each vehicle (which is incomplete) can be found at:
C++: Vehicle.h and Vehicle.cpp,
C#: Vehicle.cs,
Java: Vehicle.java,
Python: Vehicle.py.

The travel simulator's main function and the print information function represents the contemporary code. The code for the boat, car, and airplane represent the legacy code.

The Boat

As you can see from the below code, the legacy boat class has a constant fuel capacity, a constant fuel consumption rate, a constant fuel cost, and a constant speed. It has a variable fuel level and total distance travelled. There are functions for adding fuel, for getting the total distance, getting the time travelled, getting the fuel level, getting the fuel cost, and a function for travelling. Note that the boat travels at a constant speed and fuel consumption is determined in litres/hour. The travel simulator will have to get and set values for the boat somehow.
C++: Boat.h and Boat.cpp,
C#: Boat.cs,
Java: Boat.java,
Python: Boat.py.

The Car

As you can see from the below code, the legacy car class has a constant fuel capacity, a constant fuel efficiency, a constant fuel cost, and a constant speed. It has a variable fuel level and total distance travelled. There are functions for adding fuel, for getting the total distance, getting the time travelled, getting the fuel level, getting the fuel cost, and a function for travelling. Note that the car travels at a constant speed and fuel efficiency is determined in litres/100km. The travel simulator will have to get and set values for the car somehow.
C++: Car.h and Car.cpp,
C#: Car.cs,
Java: Car.java,
Python: Car.py.

The Airplane

As you can see from the below code, the legacy airplane class has a constant fuel capacity, a constant fuel consumption rate, a constant fuel cost, and a constant speed. It has a variable fuel level and total distance travelled. There are functions for adding fuel, for getting the total distance, getting the time travelled, getting the fuel level, getting the fuel cost, and a function for travelling. Note that the airplane travels at a constant speed and fuel consumption is determined in litres/hour. The travel simulator will have to get and set values for the airplane somehow.
C++: Airplane.h and Airplane.cpp,
C#: Airplane.cs,
Java: Airplane.java,
Python: Airplane.py.

Test Program

Once the travel simulator code has been completed and the different vehicle types adapted to the travel simulator, a sample run should look as follows:

    Vehicle Type: Boat
    Travel Distance: 100km
    Travel Time: 5 hours
    Current Fuel Level: 50L
    Fuel Cost: $169
    
    Not enough fuel to travel 1000km. Travelling 561.798km instead.
    Vehicle Type: Car
    Travel Distance: 561.798km
    Travel Time: 9.3633 hours
    Current Fuel Level: 0L
    Fuel Cost: $79.5
    
    Vehicle Type: Airplane
    Travel Distance: 10000km
    Travel Time: 12.5 hours
    Current Fuel Level: 32500L
    Fuel Cost: $50625
    
    
    Adding fuel...
    
    
    Fuel overflow, capping at 150L.
    Vehicle Type: Boat
    Travel Distance: 200km
    Travel Time: 10 hours
    Current Fuel Level: 50L
    Fuel Cost: $338
    
    Not enough fuel to travel 1000km. Travelling 449.438km instead.
    Vehicle Type: Car
    Travel Distance: 1011.24km
    Travel Time: 16.8539 hours
    Current Fuel Level: 0L
    Fuel Cost: $143.1
    
    Vehicle Type: Airplane
    Travel Distance: 20000km
    Travel Time: 25 hours
    Current Fuel Level: 15000L
    Fuel Cost: $101250

Questions

  1. What type of a design pattern (creational, structural, behavioural, custom) did you employ in this assignment? Why?
  2. Describe a software design pattern that you have used before this course, even if you were not aware of it.
  3. Do you feel standard design patterns are of great assistance, or great hindrance, in software design? Give advantages and disadvantages.
  4. What are some major drawbacks of the Singleton design pattern?

Marking Rubric

You will be marked out of 10 according to the following:

Does not meet expectationsSatisfactoryGoodExceeds Expectations

UML Diagram
(2 marks)
Does not meet requirementsMeets the most important requirementsMeets all requirements with minor errorsMeets all requirements with no errors

Travel Simulator
(2 marks)
Does not meet requirementsMeets the most important requirementsMeets all requirements with minor errorsMeets all requirements with no errors

Boat
(1 mark)
Does not meet requirementsMeets the most important requirementsMeets all requirements with minor errorsMeets all requirements with no errors

Car
(1 mark)
Does not meet requirementsMeets the most important requirementsMeets all requirements with minor errorsMeets all requirements with no errors

Airplane
(1 mark)
Does not meet requirementsMeets the most important requirementsMeets all requirements with minor errorsMeets all requirements with no errors
Code Documentation
(1 mark)
Does not contain documentationContains header documentation for either all files or for all functions within each file Contains header documentation for all files and for most functions within each fileContains header documentation for all files and for all functions within each file. Documents unclear code.
Questions
(2 marks)
Answers no question correctlyAnswers some questions correctlyAnswers most questions correctlyAnswers all Questions correctly

Submission

Please email all source code and answers to questions to: miguel.watler@senecapolytechnic.ca

Your answers to questions can be submitted in a separate document or embedded within your source code.

Late Policy

You will be docked 10% if your assignment is submitted 1-2 days late.
You will be docked 20% if your assignment is submitted 3-4 days late.
You will be docked 30% if your assignment is submitted 5-6 days late.
You will be docked 40% if your assignment is submitted 7 days late.
You will be docked 50% if your assignment is submitted over 7 days late.