Concept explainers
Hello. I am having a bit of trouble with this code. Its about making a running log using O(n) (linear) notation but I keep having problems figuring it out. I would appreciate the help for figuring out this code. Can you pleae paste it in eclipse format since that is the software I am using. Thanks.
This is the problem:
Write a program that:
- Asks the user for number of runs
- For each run, ask the user
- What the distance was in miles (in decimal format, e.g. 3.1 miles is acceptable)
- What the time was in minutes (in decimal format, e.g. 23.9 minutes is acceptable)
- Output the average pace (in minutes per mile) of all runs.
Please paste the code down below. Thanks.
1. Start the program.
2. Initialize variables:
- totalDistance to 0.0 (total distance of all runs)
- totalTime to 0.0 (total time of all runs)
3. Prompt the user for the number of runs:
- Read and store the number of runs in numberOfRuns.
4. Loop for each run from 1 to numberOfRuns:
a. Display "Run i:" where i is the current run number.
b. Prompt the user for the distance in miles for the current run:
- Read and store the distance in the distance variable.
c. Prompt the user for the time in minutes for the current run:
- Read and store the time in the time variable.
d. Add the distance to totalDistance.
e. Add the time to totalTime.
5. Calculate the average pace:
- Divide totalTime by totalDistance and store it in averagePace.
6. Extract minutes and seconds from averagePace:
- minutes = integer part of averagePace
- seconds = (averagePace - minutes) * 60
7. Format seconds with two decimal places.
8. Display the average pace:
- "Average Pace: minutes minutes formattedSeconds seconds per mile."
9. End the program.
10. The program finishes.
Step by stepSolved in 4 steps with 3 images
- In Java Only: My program is not working correctly, The history teacher at your school needs help grading a true/false test.The student's IDs and test answers are stored ina file, The first entry in the file contains the answers to the test in the following form: TFFTFFTTTTFFTFTFTFTT Every other entry in the file is the student;s ID, followed by a blank, followed by the student;s response. For example, the entry: ABC54301 TFTFTFTT TFTFTFFTTFT indicstes that the student;s ID is ABC54301 and the answer to question 1 is True, the answer to question 2 is false, and so on. This student did not answer question 9. he exam has 20 questions, and the class has more than 150 students. Each correct answer is awarded 2 points, each wrong answer gets -1 point, and no answer gets 0 points. Write a program that processes the test data. The output should be the student's ID, followed by the student's answers, followed by the test score, and then followed by the test grade. Here is my code, I keep…arrow_forwardin java Integer valueIn is read from input. Write a while loop that iterates until valueIn is negative. In each iteration: Update integer result as follows: If valueIn is divisible by 5, output "win" and increment result. Otherwise, output "lose" and do not update result. Then, read an integer from input into variable valueIn. End each output with a newline. Click here for exampleEx: If the input is 5 15 11 -5, then the output is: win win lose Result is 2 Note: x % 5 == 0 returns true if x is divisible by 5. import java.util.Scanner; public class ResultCalculator { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int valueIn; int result; result = 0; valueIn = scnr.nextInt(); /your code here/ System.out.println("Result is " + result); }}arrow_forwardWrite a java program called Fibonacci.java that prints the first n numbers of the Fibonacci sequence (starting with 0), where n is an integer entered by the user. Use a for loop. Some of the program has been provided below. More info about Fibonacci can be found here:https://www.mathsisfun.com/numbers/fibonacci-sequence.htmlhttps://www.youtube.com/watch?v=wTlw7fNcO-0 import java.util.Scanner;public class Fibonacci { public static void main(String[] args) { Scanner in = new Scanner(System.in); // Setting up scanner System.out.print("Enter an integer: "); int num = in.nextInt(); in.close(); // Close scanner when done using it long current = 1; long previous = 0; // Add for loop logic here }}arrow_forward
- Using javascript Simulate rolling two dice by getting two random integers from 1 to 6.a. Count how many rolls it takes to get doubles. Show each roll of the dice (both dice on the same line).b. Separately, i.e. using a separate loop from part (a), count how many rolls it takes to get values that add up to 7. Show each roll of the dice (both dice on the same line).arrow_forwardWrite a Python program that will generate 1000 random numbers between 1 and 100 inclusive from the random generator. For each value returned from the random generator, keep a count of the number of even numbers generated and the number of odd numbers generated. Use the following functions within this program: - getRandom(): this function will call the random generator and return the generated integer value. - isOdd(): this function will return true or false depending on whether the number generated is odd or even. - update(): this function will update the counters for odd or even. - display(): once the program has completed 1000 random numbers, the counters for the number of odd and even will be displayed. REQUIREMENTS: - Add a beginning statement when the program starts to execute. - Add an ending statement when the program is complete. - Call the random generator 1000 times for a randomly generated number between…arrow_forwardA program in javaarrow_forward
- Java program I need help creating a program that creates a Christmas tree. It has a method that accepts two parameters (one for the number of segments and one for the height of each segment). The left tree has 3 segments with a height of 4 and the right one has two segments with a height of 5. Can you explain how the for loops would work?arrow_forwardHow to write a program in java that ask the user for an input word(use the String method toUpperCase to convert the word to all upper-case characters), then have the program keep looping, generating random strings until the random string matches the user word and keep track of how many loops were required to match. Each time through the loop, your program should output the user’s word, the random string, and the difference score. The difference score is the sum of the absolute value of the difference between each character in the random string and the user’s input string. For example, if the random string was “ABC” and the target string was “AAA”, then the difference score is 3 (abs(A-A) + abs(A-B) + abs(A-C) = 0 + 1 + 2 = 3). You can get at the characters of a string, using the String charAt and absolute value is the abs method of the java.lang.Math class. To generate random strings, in a loop, generate random characters to build up a random string the same length as the user word. To…arrow_forwardSo for my project program in Python I'm suppose to code a BankApp in which the user is suppose to input their username and password to access their balance details and withdraw or deposit money. The program works though there is a small issue. See when testing I notice a problem with the withdraw and deposit function, see if I put a negative value rather than saying "invalid" and looping back to the menu it will do the opposite which I'll provide a screenshot to explain it better. Can you fix and explain how you did it(also show a sceenshot on where you fix/added code)&(UserInfo will also be provided for code to work)-Thank you. Code def read_user_information(filename): usernames = [] passwords = [] balances = [] try: with open(filename, "r") as file: lines = file.readlines() for line in lines[2:]: data = line.strip().split() if len(data) == 3: usernames.append(data[0])…arrow_forward
- I am trying to write a java code to see if the number entered by the user is a factor of the random number generated from the import java.util.Random. When I run it it keeps saying the number entered by the user is not a factor of the random number. Another thing is the output is suppose to look like this... The value <number entered by user> is a / not a factor of <random number> how would I fix what i have to look like that?arrow_forwardin Java eclipse ide Read from console a 2-digit integer number, save it in variable vz. Check this number: if the digit at 10’s place is greater than the digit at 1’s place, swap these 2 digits to construct a new number, then save this new number to vz. For example, if the original number in vz is 65, swap 2 digits and vz will change to 56; if the original number is 34, vz will not change. (Clue: extract digits at 10’s place and 1’s place, compare these 2 digits to determine if these 2 digits need to be swapped or not)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education