Skip to content

Instantly share code, notes, and snippets.

@raghavddps2
Created February 5, 2022 06:38
Show Gist options
  • Select an option

  • Save raghavddps2/98f5465b0048da9c25b2d054167c751f to your computer and use it in GitHub Desktop.

Select an option

Save raghavddps2/98f5465b0048da9c25b2d054167c751f to your computer and use it in GitHub Desktop.
interface Vehicle
- double calculateCo2Emission(Trip t)
class Car implements Vehicle
- double calculateCo2Emission(Trip t)
* valueFromHashMap * t.distanceInKm
class Train implements Vehicle
- double calculateCo2Emission(Trip t)
* valueFromHashMap * t.distanceInKm
class Bus implements Vehicle
- double calculateCo2Emission(Trip t)
* valueFromHashMap * t.distanceInKm
Trip
basic variables
- String transportationMethod;
- double distance
- String unitOfDistance
- String preferredCo2Unit
formed variables
- Vehicle vehicle
- double distanceInKm
method
- calculateCo2Emission()
- vehicle.calculateCo2Emission(this)
- if preferredCo2Unit is g, multiply 1000
- return the amount
Main
- String input
- send parameters to trip class
- Based on the transportationMethod, it sets the
vehicle required.
- trip.calculateCo2Emission()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment