Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA My code compiles and works, however my calculations are incorrect for the output. I have done 3 different setups for the math and I

JAVA My code compiles and works, however my calculations are incorrect for the output. I have done 3 different setups for the math and I still cannot get it right. The help is appreciated

My code:

import java.io.*; // I/O import java.util.*; // Scanner class

public class Lab1 { public static void main( String args[] ) { final double MILES_PER_MARATHON = 26.21875; // i.e 26 miles 285 yards

Scanner kbd = new Scanner (System.in);

// THE FOLLOWING THREE VARIABLES ARE PRINTED OUT AT THE END OF THE PROGRAM double aveMPH=0, aveMinsPerMile=0, aveSecsPerMile=0;

// YOUR JOB IS TO DO WHAT YOU HAVE TO TO TO PUT THE CORRECT VALUES INTO THEM // BEFORE THEY GET PRINTED OUT AT THE BOTTOM

System.out.print("Enter marathon time in hrs minutes seconds: "); // i.e. 3 49 37 // DO NOT WRITE OR MODIFY ANYTHING ABOVE THIS LINE int hour = kbd.nextInt(); int minute = kbd.nextInt(); int seconds = kbd.nextInt(); int secsMinutes = 60; int secsHours = 3600; int secsMarathon, hourMarathon; secsMarathon = (hour * secsHours) + (minute * secsMinutes) + seconds; hourMarathon = hour * secsMarathon/secsHours; aveMPH = (MILES_PER_MARATHON/hourMarathon); aveSecsPerMile = (secsMarathon % 60.0); aveMinsPerMile = (secsMarathon/60.0);

// DO NOT WRITE OR MODIFY ANYTHING BELOW THIS LINE. JUST LET MY CODE PRINT THE VALUES YOU PUT INTO THE 3 VARS System.out.println(); System.out.format("Average MPH was: %.2f mph ", aveMPH ); System.out.format("Average mile split was %.0f mins %.1f seconds per mile", aveMinsPerMile, aveSecsPerMile ); System.out.println();

} // END MAIN METHOD } // EOF

Sample output:

image text in transcribed

C. Command Prompt C: \Users\tim\Desktop\lab-01\solution>java Lab1 Enter marathon time in hrs minutes seconds: 2 8 44 Average MPH was: 12.22 mph Average mile split was 4 mins 54.6 seconds per mile C: \Users\tim\Desktop\lab-01\solution>

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

More Books

Students also viewed these Databases questions

Question

What are the characteristics of a virtual organization?

Answered: 1 week ago