Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Store and Retrieve User Scores | Section
Practice
Projects
Quizzes & Challenges
Quizzer
Challenges
/
Fundamental Data Structures in Java

bookChallenge: Store and Retrieve User Scores

Opgave

Swipe to start coding

In this task, you need to complete the UserScores class by filling in the missing parts. The goal is to manage a collection of users and their scores using a HashMap. You will implement adding a user, retrieving a user’s score, removing a user, and printing all users with their scores.

  1. In the addUser(String name, int score) method:

    • Add the name and score pair to the userMap.
  2. In the getUserScore(String name) method:

    • Return the score associated with the given name.
  3. In the removeUser(String name) method:

    • Remove the entry for the given name from the userMap.
  4. In the printAllUsers() method:

    • For each entry in userMap.entrySet(), get the key (user name) and value (score).

Løsning

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 15
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

close

bookChallenge: Store and Retrieve User Scores

Stryg for at vise menuen

Opgave

Swipe to start coding

In this task, you need to complete the UserScores class by filling in the missing parts. The goal is to manage a collection of users and their scores using a HashMap. You will implement adding a user, retrieving a user’s score, removing a user, and printing all users with their scores.

  1. In the addUser(String name, int score) method:

    • Add the name and score pair to the userMap.
  2. In the getUserScore(String name) method:

    • Return the score associated with the given name.
  3. In the removeUser(String name) method:

    • Remove the entry for the given name from the userMap.
  4. In the printAllUsers() method:

    • For each entry in userMap.entrySet(), get the key (user name) and value (score).

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 15
single

single

some-alt