Question: Write an application that implements a trip-time calculator. Define and use a class TripComputer to compute the time of a trip. TripComputer should have the

Write an application that implements a trip-time calculator. Define and use a class TripComputer to compute the time of a trip. TripComputer should have the private attributes

  • totalTime—the total time for the trip
  • restStopTaken—a boolean flag that indicates whether a rest stop has been taken at the end of the current leg and the following methods:
  • computeLegTime(distance, speed)—computes the time for a leg of the trip having a given distance in miles and speed in miles per hour. If either the distance or the speed is negative, throws an exception.
  • takeRestStop(time)—takes a rest stop for the given amount of time. If the time is negative, throws an exception. Also throws an exception if the client code attempts to take two rest stops in a row.
  • getTripTime—returns the current total time for the trip.
  • Here is one possible configuration of the labels, buttons, and text fields required by the triptime calculator:

TRIP TIME CALCULATOR ADO STOP ADD LEG STOP TIME DISTANCE YOUR TRIP TIME SO FAR: SPEED

TRIP TIME CALCULATOR ADO STOP ADD LEG STOP TIME DISTANCE YOUR TRIP TIME SO FAR: SPEED

Step by Step Solution

3.47 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public class TripComputerException extends Exception Creates a new instance of TripComputerExcep... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java An Introduction to Problem Solving and Progra Questions!