Question: Introduction: We have completed chapter 6 (on methods). It included very important material on the scope of class members (which will be on the exam)
Introduction:
We have completed chapter 6 (on methods). It included very important material on the scope of class members (which will be on the exam) and introduced some helpful features like enumerations. Also noted were the use and purpose of static fields and methods in a class as well as how to declare symbolic constants with the final keyword. Another important concept was that of overloading methods.
Overview:
This lab has you design a system to calculate the distance between points and is based on Exercise 6.32 in the textbook. Of course, I am modifying it to make it work very much more like a real GPS system (below).
Note of Clarification:
In this assignment, you enter points on a Cartesian grid that is linear in both dimensions (i.e., a Euclidean plain) for simplicity just like in a typical Algebra class. A real GPS system works with coordinates of longitude and latitude, which do not maintain a linear relationship with respect to equal distances on the surface of a sphere (i.e., the Earth). But don't let that be of any concern to us, here.
Description:
In my version of this problem, you need to ask the user for a LIST of points (not just simply two points) as well as a speed to be associated with each point (that will be used to travel to the next point). The last speed will be entered as a zero to indicate the end of the list (since it won't be used to travel to another point as there are no more points to be visited). Enter the x and Y coordinates as well as the speed as type double literals at the console. Each prompt for a new point will receive 3 numeric entries from the user: 2 doubles for the x and y coordinates (on the Cartesian grid) and 1 double for the speed (to the next point). When the speed is entered as 0, user input mode is terminated and the program calculates and displays the overall distance, time and average speed to the final destination.
Note that you do not need to specify the units of measure, as that has no effect on the results (as long as the same units are applied for each point specified). That is, if you enter coordinates as miles or kilometers; or speeds in either measure as rates per hour (we will assume all speeds are in units per hour), it makes no difference as long as they are always measured with the same scale so don't ask for or report any units of measure. However, as speeds are always entered as rates per hour, when reporting the travel time, always convert to hours and minutes (not simply decimal hours).
There is no reason for you to have any limit on the number of points you can accept. I will always enter 3 values at each prompt when I test your work. I will always end with a final speed of 0 (i.e., you can trust the user will enter good data values - you don't have to try to account for bad data entries). The coordinates for the points can be positive or negative, but the speed must always be positive, the last and only the last of which will always be zero (I will not enter a negative speed so you do not need to check for this in your program).
How to calculate the distances between points:
You calculate distances between points using the Pythagorean Theorem:
If X1 and Y1 are the coordinates for waypoint #1 and X2 and Y2 are the coordinates for waypoint #2, then the distance between them is calculated as follows:
distance = ((X2 - X1)2 + (Y2 - Y1)2)
and if S1 and S2 are the speeds associated with waypoint 1 and waypoint 2, then the time to travel from waypoint 1 to waypoint 2 is calculated as follows:
time = distance / S1
Make a main method that prompts the user (in a loop) for each way point (as in the example) until the user enters a 0 as the speed. Each time through the loop, update the total distance and time. At the end, when you print the overall time, be sure to use the remainder (modulus) division to convert your decimal time to hours and minutes (as in the example).
I'm looking for the following features in your class:
Two non-static fields of type double for the (overall) time and distance (named time and distance).
One non-static field of type double to store the calculated average speed (named speed).
Do not create any other instance variables.
A constructor that takes no parameters but initializes the fields to zero values.
The get- and set- methods (properly named) for all fields.
A report method (that takes no parameters) but displays the results (last lines in the example, below, after all the way points have been entered).
The main method should be the only static member.
The prompts and output should look exactly as in my example if you use the same data.
Proper naming, style and indentation (as developed in the textbook examples).
Open the System.in object as a new Scanner only once and all user input is to be performed in the main method. Only the main method prompts for and accepts the way point data. After the data is entered in the main method, only the report method outputs the time and distance totals and the average speed to the console. Your output format must look exactly like mine (given the same or comparable data).
Name your solution TravelReport.java it must compile and run for any credit at all (only attach the source code - no other files). Needless to say, only attach a correctly named Java plain text file. Note that after you write the prompt to the console's monitor, you can read the way point values from the console's keyboard with consecutive calls to the Scanner's nextDouble() method (three calls will read all three items, in sequence, entered on the line following the prompt).
Example Run:
java TravelPlan
Way point 01: 1.0 1.0 40.0
Way point 02: 4.0 5.0 40.0
Way point 03: 7.0 9.0 00.0
Total distance to destination: 10.0 units
Total time to the destination: 0h 15m
Average speed over this route: 40.0 units/hour
Explanation of Example Run:
The text in black is what the program prints or prompts, the text is red are what the user types or enters and the text in blue is what the program has to calculate.
Please note: If you deliver the solution to a previously posted problem (as from an earlier semester) you will receive no assignment credit or online attendance value. It's a shame that I need to post this paragraph, and most don't need it, but be warned. This mistake cannot be made accidentally.
I need java code for this problem
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
