Write code to determine if a user's input information has them
qualify to run a marathon. They will enter their name, following
their gender (they must input male or female otherwise the system
will produce a println statement and end the program.), then their
age (must be within 40-49 and input their best marathon
time (they must be able to run between 1:59:00 to 6:59:59 to
qualify). The input time must convert from hours:minutes: seconds
to only minutes as a double primitive type. We test the line
of code to see if it works and so far I have put together this
code:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner console = new
Scanner(System.in);
System.out.println("What is your first
name? ");
String name = console.next();
System.out.println("What's your
gender? ");
String gender = console.next();
{
if
(!gender.equalsIgnoreCase("male") &&
!gender.equalsIgnoreCase("female")) {
System.out.println("Unfortunately, there are no qualifying times
for that gender yet.");
}
else {
System.out.println("What's your age? ");
int age =
console.nextInt();
{
if (age < 40 || age > 49) {
System.out.println(
"Unfortunately,
the system cannot make a determination based on your age
group");
} else {
System.out.println("What's your best marathon
time? hh:mm:ss ");
System.out.println("Hours");
int hours = console.nextInt();
System.out.println("Minutes");
int minutes = console.nextInt();
System.out.println("Seconds");
int seconds = console.nextInt();
System.out.print(hours + ":" + minutes + ":" +
seconds);
}
}
}
}
}
}
. Read and write Java code containing the various sequence, selection and iteration control structures. Your Task: This assignment builds on the M4 Assignment. Note the changes/modifications will be in bold. To run in the Boston Marathon, a runner must either qualify, but running a marathon faster than the "qualifying time" or by raising money for charity. In this program, we are going to create a program in which a runner enters their age, gender and finish time in hours, minutes and seconds. The program will then tell them whether or not they qualify for the Boston Marathon Plan, implement and test a program that asks the user for the name of a runner, a gender (M/F)*, the age and the time it took them to finish a marathon. The program should display whether or not the runner has earned a Boston marathon qualifying time. Here is a table of qualifying times: Age Group MEN WOMEN 18-34 3hrs 00min 00sec 3hrs 30min 00sec 35-39 3hrs 05min 00sec 3hrs 35min 00sec 40-44 3hrs 10min 00sec 3hrs 40min 00sec 45-49 3hrs 20min 00sec 3hrs 50min 00sec 50-54 3hrs 25min 00sec 3hrs 55min 00sec 55-59 3hrs 35min 00sec 4hrs 05min 00sec 60-64 3hrs 50min 00sec 4hrs 20min 00sec 65-69 4hrs 05min 00sec 4hrs 35min 00sec 70-74 4hrs 20min 00sec 4hrs 50min 00sec 75-79 4hrs 35min 00sec 5hrs 05min 00sec 80 and over 4hrs 50min 00sec 5hrs 20min 00sec You can see this is a LOT of qualifying times. Because this could take a lot of code if we did every age group, we are going to just evaluate times for the age groups 40-44 and 45-49. If the user enters an age outside that range, display a message stating that the program cannot make a determination for their age group. Validate the input. If any gender other than M/F has been entered, please respond with a kind message, such as "Unfortunately, there are no qualifying times for that gender yet." Only accept times between 1:59:00 and 6:59:59, where 1:59:00 is 1 hour, 59 minutes and 00 seconds. Consequently, the hours input can be in the range 1 to 6, inclusive. Minutes and seconds each in the range 0 to 59. If any of the input is outside the given range, display a message and prompt the user for the value again. Do not continue the program until the user enters valid input. Convert the hours, minutes and seconds to a time in total minutes - including a decimal value for the seconds. This will make it easier to compare against the qualifying times. Before beginning to write the code, use a program planning tool - either flowcharts or pseudocode - to plan what you are going to do. Be as detailed as possible. Include your program plan in a separate file in your REPL. *At this time there are no published qualifying standards for non-binary athletes.
Write code to determine if a user's input information has them qualify to run a marathon. They will enter their name, fo
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Write code to determine if a user's input information has them qualify to run a marathon. They will enter their name, fo
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!