Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago

Question

Which form of proof do you find least persuasive? Why?

Answered: 1 week ago