Question
This program uses a HashMap to associate a race distance in kilometers with a runner's race time. If a race distance does not exist, the
This program uses a HashMap to associate a race distance in kilometers with a runner's race time. If a race distance does not exist, the program prints "null". Modify the program to use the containsKey() method to check if the runner has run a race of the specified distance, and display a message of "No race of the specified distance exists."
import java.util.HashMap; import java.util.Scanner;
public class RunDistTimeMap { public static void main (String[] args) { HashMap
while(userDistKm != 0) {
System.out.print("Best time for " + userDistKm + " km race is: "); System.out.print(raceTimes.get(userDistKm)); System.out.println(" minutes."); System.out.println(); System.out.println("Enter race distance in km (0 to exit): "); userDistKm = scnr.nextInt(); } } }
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