Challenge: Store and Retrieve User Scores
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.
-
In the
addUser(String name, int score)method:- Add the
nameandscorepair to theuserMap.
- Add the
-
In the
getUserScore(String name)method:- Return the score associated with the given
name.
- Return the score associated with the given
-
In the
removeUser(String name)method:- Remove the entry for the given
namefrom theuserMap.
- Remove the entry for the given
-
In the
printAllUsers()method:- For each entry in
userMap.entrySet(), get the key (user name) and value (score).
- For each entry in
Lösning
Tack för dina kommentarer!
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Fantastiskt!
Completion betyg förbättrat till 6.25
Challenge: Store and Retrieve User Scores
Svep för att visa menyn
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.
-
In the
addUser(String name, int score)method:- Add the
nameandscorepair to theuserMap.
- Add the
-
In the
getUserScore(String name)method:- Return the score associated with the given
name.
- Return the score associated with the given
-
In the
removeUser(String name)method:- Remove the entry for the given
namefrom theuserMap.
- Remove the entry for the given
-
In the
printAllUsers()method:- For each entry in
userMap.entrySet(), get the key (user name) and value (score).
- For each entry in
Lösning
Tack för dina kommentarer!
single