Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 raceTimes = new HashMap(); Scanner scnr = new Scanner(System.in); int userDistKm; raceTimes.put(5, 23.14); raceTimes.put(15, 78.5); raceTimes.put(25, 120.75); System.out.println("Enter race distance in km (0 to exit): "); userDistKm = scnr.nextInt();

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

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

Database Theory Icdt 99 7th International Conference Jerusalem Israel January 10 12 1999 Proceedings Lncs 1540

Authors: Catriel Beeri ,Peter Buneman

1st Edition

3540654526, 978-3540654520

More Books

Students also viewed these Databases questions

Question

b. Why were these values considered important?

Answered: 1 week ago