Question
Java program: Create a CarTrip class that includes the following: Instance Variables/Attributes (NOTE: they should all be of the double datatype) myStartOdometer myEndOdometer myTime myGallonsUsed
Java program:
Create a CarTrip class that includes the following:
Instance Variables/Attributes (NOTE: they should all be of the double datatype) myStartOdometer myEndOdometer myTime myGallonsUsed Static Variable numOfCarTrips (keeps track of number of objects created)
Constructor CarTrip with parameters for all the instance variables
Methods All getter methods that return the appropriate instance variable getMyStartOdometer() getMyEndOdometer() getMyTime() getMyGallonsUsed()
All setter methods that set the instance variables to new values setMyStartOdometer(double newStart) setMyEndOdometer(double newEnd) setMyTime(double newTime) setMyGallonsUsed(double newGal)
A toString() method to represent a CarTrip Object
A method called getTripDistance() that finds total distance (hint: use start and end odometer values)
A method called getAverageSpeed() that finds the average speed (hint: speed is distance over time)
A method called getGasMileage() that calculates the miles per gallon used
A method called getTotalGasPrice(double pricePerGallon) that calculates the total price of gas the trip required (hint: take the price per gallon and multiply by total gallons used)
A method called hasGreaterAvgSpeed(CarTrip anotherCarTrip) that compares the average speed of 2 CarTrip objects and returns true or false if the calling object has a greater average speed than the parameter object.
Create a CarTripTester main class. Have the following: Create an object called car1 using the constructor Using appropriate methods, output the following to the screen: Start Odometer: and the value End Odometer: and the value Time: and the value Gallons Used: and the value
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started