Concept explainers
Given a HashMap pre-filled with student names as keys and grades as values, complete main() by reading in the name of a student, outputting their original grade, and then reading in and outputting their new grade.
Ex: If the input is:
Quincy Wraight 73.1
the output is:
Quincy Wraight's original grade: 65.4 Quincy Wraight's new grade: 73.1
import java.util.Scanner;
import java.util.HashMap;
public class StudentGrades {
public static void main (String[] args) {
Scanner scnr = new Scanner(System.in);
String studentName;
double studentGrade;
HashMap<String, Double> studentGrades = new HashMap<String, Double>();
// Students's grades (pre-entered)
studentGrades.put("Harry Rawlins", 84.3);
studentGrades.put("Stephanie Kong", 91.0);
studentGrades.put("Shailen Tennyson", 78.6);
studentGrades.put("Quincy Wraight", 65.4);
studentGrades.put("Janine Antinori", 98.2);
// TODO: Read in new grade for a student, output initial
// grade, replace with new grade in HashMap,
// output new grade
}
}
java please
Step by stepSolved in 2 steps with 1 images
- JAVA Create a new class HashMapManipulation with a main method. Import the necessary classes from the java.util package, including the HashMap class. Create a HashMap object, named mapand use the put() method to add key-value pairs to the map. The keys are strings "A", "B", and "C", and the values are integers 1, 2, and 3 respectively. Use the size() method to print the size of the map. Use a for loop to print the key-value pairs in the map. The loop should iterate over the entries in the map using the entrySet() method, which will return a set of Map.Entry objects representing the key-value pairs in the map. The key and value of each entry are printed using the getKey() and getValue() methods, respectively. Use theget() method to get the value of key "A", and assigns it to a variable value. The value is then printed. Use the put() method to add a new key-value pair to the map. The key is "D" and the value is 4. The map is then printed again, to show the added key-value…arrow_forwardPlease CODE in java ! Keep the code neat. Add comments. No need for long comments. If you have answered this question before please dont copy and paste the same answer you did for the other person. Need this tonight before 11 pm EST. Thanks !arrow_forwardJAVA Create a new class HashSetManipulation with a main method. Create a new HashSet set and populate it with initial values "A", "B", and "C" using the add method. Print the size of the set using set.size(). Use a for loop to print the values in the set. Use the add method to add a new value "D" to the set and print the result of the set to show that the value has been added. Use the remove method to remove value "A" from the set and print the result of the set to show that the value has been removed. Use the contains method to check if the value "C" exists in the set and print the result.arrow_forward
- Java Code: Look through the Language Description and build a list of keywords. Add a HashMap to your Lexer class and initialize all the keywords. Change your lexer so that it checks each string before making the WORD token and creates a token of the appropriate type if the work is a key word. When the exact type of a token is known (like “WHILE”), you should NOT fill in the value string, the type is enough. For tokens with no exact type (like “hello”), we still need to fill in the token’s string. Finally, rename “WORD” to “IDENTIFIER”. Similarly, look through the Language Description for the list of punctuation. A hash map is not necessary or helpful for these – they need to be added to your state machine. Be particularly careful about the multi-character operators like := or >=. These require a little more complexity in your state machine. Strings and characters will require some additions to your state machine. Create “STRINGLITERAL” and “CHARACTERLITERAL” token types. These…arrow_forwardJava Code: Add a HashMap to your Lexer class and initialize all the keywords. Change your lexer so that it checks each string before making the WORD token and creates a token of the appropriate type if the work is a key word. When the exact type of a token is known, you should NOT fill in the value string, the type is enough. For tokens with no exact type we still need to fill in the token’s string. Rename “WORD” to “IDENTIFIER”. Strings and characters will require some additions to your state machine. Create “STRINGLITERAL” and “CHARACTERLITERAL” token types. These cannot cross line boundaries. Your lexer should throw an exception if it encounters a character that it doesn’t expect outside of a comment, string literal or character literal. Create a new exception type that includes a good error message and the token that failed. Ensure that the ToString method prints nicely. Add “line number” to your Token class. Keep track of the current line number in your lexer and populate each…arrow_forwardpackage comp1110.exam; /** * COMP1110 Exam, Question 5 */ public class Q5StringHash { /** * Return a hash of the given string as an integer in the range 0 ... buckets - 1. * * @param value The string to be hashed * @param buckets The number of buckets into which the hash should be made (defining its range) * @return An integer hash of value in the range 0 ... buckets - 1. */ public static int hash(String value, int buckets) { // FIXME complete this method, without using Java's built-in hashCode() method return -1; } } ///////////// DO NOT USE ANY INBUILT HASHING FUNCTIONS IN JAVA! //////////////////////arrow_forward
- JAVAarrow_forwardBuiltInFunctionDefinitionNode.java has an error so make sure to fix it. BuiltInFunctionDefinitionNode.java import java.util.HashMap; import java.util.function.Function; public class BuiltInFunctionDefinitionNode extends FunctionDefinitionNode { private Function<HashMap<String, InterpreterDataType>, String> execute; private boolean isVariadic; public BuiltInFunctionDefinitionNode(Function<HashMap<String, InterpreterDataType>, String> execute, boolean isVariadic) { this.execute = execute; this.isVariadic = isVariadic; } public String execute(HashMap<String, InterpreterDataType> parameters) { return this.execute.apply(parameters); } }arrow_forwardJava (HashMap) - Student Gradesarrow_forward
- In JAVA, use a HashMap to count and store the frequency counts for all the words from a large text document. Using file util, please. Then, display the contents of this HashMap with words and frequency count. Next, please create a set view of the Map and store the contents in an array. Sort this array based on key value and display it. Finally, sort the array in decreasing order by frequency and display it as well. Please label your explanation in the code Thank youarrow_forwardBelow is the code for a Time class that has both an equals method and a hashCode method; however, the body of the hashCode method is missing. In the text box, write the code you would put inside the body of the hashCode method. Remember that a hashCode with no collisions is better than a hashCode that has collisions and a hashCode with no gaps in the values is better than a hashCode that has gaps. public class Time { private int hour; // A number between 1 and 12 private int min; // A number between 0 and 59 private boolean pm; // True if the time is pm. public Time(int hour, int min, boolean pm) { this.hour = hour; this .min = min; this.pm = pm; } public int getHour() { return hour; } public int getMin() { return min; } public boolean isPM() { return pm == true; } public boolean isAM() { return pm == false; } public boolean equals(Object obj) { if (this == obj) return true; if (obj ==…arrow_forwardWrite a program in Java that performs the following tasks: Create an ArrayList, HashMap and HashSet Objects. Add 2 entries to each one of them using an appropriate method.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education