Here is the code for the above assignment.
Feel free to comment on any doubt and give thumbs up!
Code:
import java.util.HashMap;
public class Lab7b
{
public static void main(String[] args) {
// Create a new HashMap called "songsStarts"
HashMap<String, Integer> songStars = new HashMap<>();
// Yes, you should listen to all these on Youtube
songStars.put("The balled of Bilbo Baggins", 5);
songStars.put("A still more glorious dawn", 4);
songStars.put("A finite simple group of order two", 4);
songStars.put("Code monkey", 2);
songStars.put("Fish heads", 2);
songStars.put("I;ll form the head", 3);
songStars.put("Honeybee", 5);
songStars.put("Silver apples of the moon", 4);
// Get the number of stars for "Code monkey", and print the # of stars
int numberOfStars = songStars.get("Code monkey");
System.out.println("Number of stars for the song Code monkey on Youtube are : " + numberOfStars);
// Remove the song "Honeybee"
songStars.remove("Honeybee");
// Determine if "Honeybee" is still in the table.
if(songStars.containsKey("Honeybee")){
System.out.println("Honeybee still in table");
}else{
System.out.println("Successfully removed Honeybee");
}
}
}
Screenshot
Thank You!
__________________________________________________________________________________________ HashMaps A hashtable is a data structure that allows the user to look up things...
Use Java language You may assume that you always map strings to integers, and therefore you need not worry about using generics. Here are the methods that your map must implement. void put (String key, Integer value); insert this key-value pair into the map under the following rules: If key already exists in the map, change its value to value, overwriting what was there If key is not already there, insert this key-value pair into the map. boolean containsKey(String key);...
Please answer this problem in C++, Thank you! Read and study the sample program: "hashing with chaining using singly linked lists", as well as "hashing with chaining using doubly linked lists". Notice this program is complete except it doesn't include the remove function. Write the remove function and test it with the rest of the program including the given main program. Upload your C++ source file. ---Here is the referenced program: "hashing with chaining using singly linked lists". Below this...
Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can be solved in one post so I posted the other on another question so please check them out as well :) Here is the questions in this assignment: Note: Two helper functions Some of the testing codes for the functions in this assignment makes use of the print_dict in_key_order (a dict) function which prints dictionary keyvalue pairs...
Write a program that allows the user to enter an unsigned integer (the maximum value of an unsigned 4-byte int is 232 = 4,294,967,296) and reverses its format (from little to big endian, or vice versa). Print out the user-entered number in hexadecimal and binary, reverse the endianness, and print the reverse in hexadecimal and binary. Integers in most machine architectures are represented in little endian format: the least significant byte is stored in the smallest address; for instance, the...
Read a file called populations.txt and populate a php associative array with the values read from the file. Here is an example populations.txt file: Dhaka, 23 million Bangaluru, 21 million New York, 9 million Emporia, 23 thousand Here's some pseudo code: open the file loop through the lines in the file read a line into a string variable explode (or is it split, or something else) the string into key value pairs save the key value pair into your associative...
Q16-Decoder (0.5 points) Write a code block to decode strings from secret encodings back to readable messages. To do so: Initialize a variable called decoded as an empty string . Use a for loop to loop across all characters of a presumed string variable called encoded Inside the loop, convert the character to another character o Get the unicode code point for the character (using ord o Subtract the value of key to that code point (which should be an...
This should be in Java Create a simple hash table You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time. You should create a class to hold the data, which will be a key, value pair You should use an integer for you key, and a String for your value. For this lab assignment, we will keep it simple Use...
Hash Tables. (Hint: Diagrams might be helpful for parts a) and b). ) When inserting into hash table we insert at an index calculated by the key modulo the array size, what would happen if we instead did key mod (array_size*2), or key mod (array_size/2)? (Describe both cases). Theory answer Here Change your hashtable from the labs/assignments to be an array of linkedlists – so now insertion is done into a linkedlist at that index. Implement insertion and search. This...
Write a program that allows the user to enter a series of exam scores. The number of scores the user can enter is not fixed; they can enter any number of scores they want. The exam scores can be either integers or floats. Then, once the user has entered all the scores they want, your program will calculate and print the average of those scores. After printing the average, the program should terminate. You need to use a while loop...
You will create a class to keep student's information: name, student ID, and grade. The program will have the following functionality: - The record is persistent, that is, the whole registry should be saved on file upon exiting the program, and after any major change. - The program should provide the option to create a new entry with a student's name, ID, and grade. - There should be an option to lookup a student from his student ID (this will...