Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help filling in the code with JAVA, ONLY update the parts in between the bolded parts, do not touch anything else. import java.util.TreeMap; import
Need help filling in the code with JAVA, ONLY update the parts in between the bolded parts, do not touch anything else.
import java.util.TreeMap; import java.util.Map; import java.util.Set; /** * Grades - Write a program that uses a TreeMap to store a set of * names and their corresponding grades. Based upon P16.7 in Big Java */ public class Grades { private Mapgrades; //-----------Start below here. To do: approximate lines of code = 2 // 1. Write a default constructor for the Grades class ; //2. use a TreeMap for the grades map. //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. /** * Adds a name and its corresponding grade. * @param name the name, which will be the key * @param grade the grade, which will be the value */ public void add(String name, String grade) { //-----------Start below here. To do: approximate lines of code = 1 // put this key value pair into grades //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } /** * Returns the grade for a given name. * @param name the name. * @return the grade corresponding to the specified name. */ public String getGrade(String name) { //-----------Start below here. To do: approximate lines of code = 1 // use the map to fetch the value given the key //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } /** * Removes a name and it's corresponding grade. * @param name the name to remove. */ public void remove(String name) { //-----------Start below here. To do: approximate lines of code = 1 // use the map to remove the key name //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } /** * Returns a String containing all of the names and their * corresponding grades formatted as: * name1: grade * name2: grade * @return all the names and their corresponding grades as a String */ public String toString() { //-----------Start below here. To do: approximate lines of code = 5 // initialize the result string //let names be the set of keys //for each name //append the key: value pair followed by a newline //return the result string //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } }
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