Write a
5
12
3
5
5
3
21
−1
then the program should output the following (not necessarily in this order):
The number 5 occurs 2 times.
The number 5 occurs 3 times.
The number 12 occurs 1 times.
The number 21 occcrs 1 times.
Want to see the full answer?
Check out a sample textbook solutionChapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Introduction to Programming Using Visual Basic (10th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Python (3rd Edition)
- write a program in java which add 2 polynomial using hashmap<integer, double> with inputs from textfieldarrow_forwardI'm developing a card game that requires one deck of 52 cards using Java. Based on the code below, it outputs the total point chosen from the sorted suit out of the 5 cards that gives the highest point. I used hashmaps to program this code. Instead, I want the program to perform the same as before but using comparable/comparator instead of hashmaps. import java.util.HashMap; import java.io.*; public class CardPointsList { static HashMap<String,Integer> Code = new HashMap<>(); static HashMap<Character,Integer> Order = new HashMap<>(); static String[][] hand= {{ "c5","s6","sK","dK","dA"},{"s7","s4","dJ","sA","h5"},{"sQ","d3","c9","hK","d5"}}; static int[] scores={0,0,0}; public static void sortHand() { String temp; for (int h=0;h<3;h++) {for (int i=0;i<5;i++) { for (int j=i+1;j<5;j++) { if (hand[h][j].charAt(0) < hand[h][i].charAt(0)) {temp = hand[h][j]; hand[h][j] = hand[h][i];…arrow_forwardusing mid square method, write a program that tells a user to input a string, then store it in an hashtable of size 100arrow_forward
- Write a Python program to print a hollow square pattern of stars (*) with a hash (#) symbol at the center of the square. The side length n of the square shall be entered by the user as an odd integer number greater than 4.arrow_forwardGiven 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…arrow_forwardIn 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_forward
- Stack CreateStack(S) push (S, 10) push (S, 15) push (S, 20) x = top (S) push (S, x + 5) x = pop (S) + top (S) push (S, x – pop (S)) push (S, pop (pop (S))) push (S, x – top (S)) push (S, push(S, x) – top (S)) After executing the given codes above, answer the questions and explain. Thanksarrow_forwardModify the given programs by adding two methods in HashTableClass: Show Full code with output Find and return the item with the maximum key; Find and return average of the keys in the hash table. import java.util.*;public class hashTableClass { public int tableSize; Node[] T; public hashTableClass() { System.out.println("Give the hash table size"); tableSize = Integer.parseInt(new Scanner(System.in).nextLine()); T = new Node[tableSize]; for (int i = 0; i < tableSize; i++) T[i] = null; } public int hashFunction(int Key) { return Key % tableSize; } public Node Search(int Key) { int h = hashFunction(Key); Node current = T[h]; while (current != null && current.item != Key) current = current.link; return current; } public void Insert(int newItem) { int h = hashFunction(newItem); Node current = T[h]; Node newNode = new Node(newItem);…arrow_forwardWrite a program that prompts the user to enter apositive integer and displays all its smallest factors in decreasing order. Forexample, if the integer is 120, the smallest factors are displayed as 5, 3, 2, 2,2. Use the StackOfIntegers class to store the factors (e.g., 2, 2, 2, 3, 5) andretrieve and display them in reverse order.arrow_forward
- Write a java program that enables the user to enter a string and an index,then cuts the letter in the given index(only cuts the single letter). Then prints the new string without that letterarrow_forwardModify the given programs by adding two methods in HashTableClass: Find and return the item with the maximum key; Find and return average of the keys in the hash table. import java.util.*;public class hashTableClass { public int tableSize; Node[] T; public hashTableClass() { System.out.println("Give the hash table size"); tableSize = Integer.parseInt(new Scanner(System.in).nextLine()); T = new Node[tableSize]; for (int i = 0; i < tableSize; i++) T[i] = null; } public int hashFunction(int Key) { return Key % tableSize; } public Node Search(int Key) { int h = hashFunction(Key); Node current = T[h]; while (current != null && current.item != Key) current = current.link; return current; } public void Insert(int newItem) { int h = hashFunction(newItem); Node current = T[h]; Node newNode = new Node(newItem); newNode.link = T[h];…arrow_forwardIn this task, two hash tables should should be implemented. You can follow the followinginstructions:- In class HashTable implement a hash table and consider the following:(i) Keys are integers (therefore also negative!) and should be stored in the tableint[] data.(ii) As a hash function take h(x) = (x · 701) mod 2000. The size of the table istherefore 2000. Be careful when computing the index of a negative key. Forexample, the index of the key x = −10 ish(−10) = (−7010) mod 2000 = (2000(−4) + 990) mod 2000 = 990.Hence, indices should be non-negative integers between 0 and 1999!(iii) Implement insert, which takes an integer and inserts it into a table. Themethod returns true, if the insertion is successful. If an element is already inthe table, the function insert should return false.(iv) Implement search, which takes an integer and finds it in the table. The methodreturns true, if the search is successful and false otherwise.(v) Implement delete, which takes an integer and deletes it…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