Question
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:
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started