Info
Warning
Danger
/ Homework Answers / Computer Science / Question Description: I would like you to create a Java Application

Question : Question Description: I would like you to create a Java Application

Question

Description: I would like you to create a Java Application "YourCarTrip" that will help you calculate the total distance from one point (point A) to a second point (point B), how long it will take you to get there, and if you need gas for the return trip. You must use a while loop with a sentinel for this application. You may use a single class, or earn an extra five points for using two classes with a car class (MyCar class) to create car-objects.

YourCarTrip should define the necessary variables to hold the number of gallons in the tank (must collect input at some point), the number of miles in the trip (starts at zero), current speed (starts at zero). YourCar will travel a consistent speed for each leg of a trip, but should change speeds for each leg (increase, decrease), and finally, determine if you need gas to complete the trip. Needs gas, implies you will need to calculate your fuel consumption, so assume your car averages 20 MPG at any speed. You must input a start fuel level.

Example Output (you can be more creative): Are you going on a trip (1 = Yes or 0 = No)? 1 How many gallons of gas in your tank (Integer 1-15)? 2 Enter Leg 1 Distance (miles): 3.5 Enter Leg 1 Speed (MPH Integer): 30

Is there another Leg to your trip (1 = Yes or 0 = No)? 1 Enter Leg 2 Distance (miles): 26.3 Enter Leg 2 Speed (MPH Integer): 65

Is there another Leg to your trip (1 = Yes or 0 = No)? 1 Enter Leg 3 Distance (miles): 2.0 Enter Leg 3 Speed (MPH Integer): 30

Is there another Leg to your trip (1 = Yes or 0 = No)? 1 Enter Leg 4 Distance (miles): 4.3 Enter Leg 4 Speed (MPH Integer): 45

Is there another Leg to your trip (1 = Yes or 0 = No)? 0 You traveled about 36.1 miles in about 41.4 minutes. Your car will need more gas to return.

 

Solution
5 (1 Ratings )

Solved
Computer Science 11 Months Ago 12 Views
This Question has Been Answered!
Premium Content -

Unlimited Access

Explore More than 2 Million+
  • Textbook Solutions
  • Flashcards
  • Homework Answers
  • Documents
Signup for Better Grades!

Ask an Expert

Our Experts can answer your tough homework and study questions
154049 Computer Science Questions Answered!
Post a Question