(Count entire words, not parts of words. For example rate and rated would be different counts. Say rate is there 10 times and rated is there 5 times, that should be the count not rate 15, rated 5. Don't count parts of words.)
A Map is an interface that maps keys to values. The keys are unique and thus, no duplicate keys are allowed. A map can provide three views, which allow the contents of the map to be viewed as a set of keys, collection of values, or set of key-value mappings. In addition, the order of the map is defined as the order in which, the elements of a map are returned during iteration.
The Map interface is implemented by different Java classes, including HashMap, HashTable, and TreeMap. Each class provides different functionality and can be either synchronized or not. Also, some implementations prohibit null keys and values, and some have restrictions on the types of their keys.
A map has the form Map <k,v> where:
K: specifies the type of keys maintained in this map.
V: defines the type of mapped values.
Furthermore, the Map interface provides a set of methods that must be implemented. In this section, we will discuss about the most famous methods:
clear: Removes all the elements from the map.
containsKey: Returns true if the map contains the requested key.
containsValue: Returns true if the map contains the requested value.
equals: Compares an Object with the map for equality.
get: Retrieve the value of the requested key.
entrySet: Returns a Set view of the mappings contained in this map.
keySet: Returns a Set that contains all keys of the map.
put: Adds the requested key-value pair in the map.
remove: Removes the requested key and its value from the map, if the key exists.
size: Returns the number of key-value pairs currently in the map.
Of interest to us is the TreeMap. Here is an example of TreeMap with a Map:
import java.util.Map;
import java.util.TreeMap;
public class TreeMapExample {
public static void main(String[] args) {
Map<String, Integer> vehicles = new TreeMap<>();
// Add some vehicles.
vehicles.put("BMW", 5);
vehicles.put("Mercedes", 3);
vehicles.put("Audi", 4);
vehicles.put("Ford", 10);
System.out.println("Total vehicles: " + vehicles.size());
// Iterate over all vehicles, using the keySet method.
for (String key : vehicles.keySet())
System.out.println(key + " - " + vehicles.get(key));
System.out.println();
System.out.println("Highest key: " + ((TreeMap) vehicles).lastKey());
System.out.println("Lowest key: " + ((TreeMap) vehicles).firstKey());
System.out.println("\nPrinting all values:");
for (Integer val : vehicles.values())
System.out.println(val);
System.out.println();
// Clear all values.
vehicles.clear();
// Equals to zero.
System.out.println("After clear operation, size: " + vehicles.size());
}
}
The suspected output looks like this:
Total vehicles: 4
Audi - 4
BMW - 5
Ford - 10
Mercedes - 3
Highest key: Mercedes
Lowest key: Audi
Printing all values:
4
5
10
3
After clear operation, size: 0
Press any key to continue . . .
Assume that we have an actual FactBook2008.txt which you need to read. We want to create a wordcount map made out of K=String, and V=Integer. The program is to count the frequency of words in the above file. Basically, if the word shows up for the first time we count it as being 1. If we have encountered already we increment the word count by 1.
We would like to print the words in the files and count how many of them we read.Hint: Use the following loop to print the output as follows:
for(String word : wordCount.keySet())
System.out.println(word + " " + wordCount.get(word));
Step by stepSolved in 3 steps with 1 images
I need to print the map size also. Any idea how to do that?
I need to print the map size also. Any idea how to do that?
- In the Card1 class, the compareTo() method orders cards by first comparing the card’s suitsand then ranks if needed (when there is a tie). The suits and ranks are ordered as follows:suits: The suits will be ordereddiamonds © < clubs ® < hearts ™ < spades ́ranks: The ranks will be ordered (READ CAREFULLY)2 < 3 < · · · < 9 < 10 < Jack < King < Queen < Ace In the Card2 class, the compareTo() method orders cards solely by rank as follows:ranks: The ranks will be ordered (READ CAREFULLY)Ace < 2 < 3 < · · · < 9 < 10 < Jack = King = Queen︸ ︷︷ ︸considered equalarrow_forwardAssume there exists a website that sells tools that includes a search feature. We want to implement a feature that returns the total price of all the items that match a search, that is, the sum of the prices of everythingthat matched the search called searchTotal.Write a controller for the website that implements the method searchTotal(). The searchTotal() method accepts a single argument: the string to match. It will use the string to query the product database to find the matching entries. searchTotal() will sum the prices of all the returned items of the search.Use model->search () to query the database; it returns the matches found with the search term. Assume that the table schema includes a Price column.arrow_forwardHi, I am making a elevator simulation and I need help in making the passenger classes using polymorphism, I am not sure what to implement in the comment that says logic. Any help is appreciated. There are 4 types of passengers in the system:Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements.VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators.Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators.Glass: This type of passenger has a request percentage of 5%. Glass passengers have fragile items that need to be transported and are more likely to be picked up by glass elevators. This is what i have so far public abstract class Passenger { protected String type; protected int…arrow_forward
- You are to create a solution for a Pharmaceutical company. Entities to be represented are: Drugs, Sales Representatives, Bills and Vouchers. • A Drug is characterized by its name (string), its price (int) and its manufacturer (a manufacturer ===> composition). A Manufacturer is characterized by his name (string) and the list of drugs they sell (array of drugs) => composition. • A Sales Representative (sometimes referred to as rep) is characterized by his/her name(string), the total amount sold (double), his/her salary (int). o Sales Representatives can be of two types (inheritance): Reps with a fixed income and a commission Reps with a commission only A Voucher is characterized by its number (int), a client name (a customer), and the quantity sold of each drug. All reps and vouchers and bills are payable. As such, students need to implement an interface called Payable and implement it in the aforementioned classes. 1. You need then to create GUI interfaces where the user can manage all…arrow_forwardFor any element in keysList with a value greater than 100, print the corresponding value in itemsList, followed by a space. Ex: If keysList = {42, 105, 101, 100} and itemsList = {10, 20, 30, 40}, print: 20 30 Since keysList.at(1) and keysList.at(2) have values greater than 100, the value of itemsList.at(1) and itemsList.at(2) are printed. #include <iostream>#include <vector>using namespace std; int main() {const int SIZE_LIST = 4;vector<int> keysList(SIZE_LIST);vector<int> itemsList(SIZE_LIST);unsigned int i; for (i = 0; i < keysList.size(); ++i) {cin >> keysList.at(i);} for (i = 0; i < itemsList.size(); ++i) {cin >> itemsList.at(i);} /* Your solution goes here */ cout << endl; return 0;} Please help me with this problem using c++.arrow_forwardThe code given below represents a saveTransaction() method which is used to save data to a database from the Java program. Given the classes in the image as well as an image of the screen which will call the function, modify the given code so that it loops through the items again, this time as it loops through you are to insert the data into the salesdetails table, note that the SalesNumber from the AUTO-INCREMENT field from above is to be inserted here with each record being placed into the salesdetails table. Finally, as you loop through the items the product table must be update because as products are sold the onhand field in the products table must be updated. When multiple tables are to be updated with related data, you should wrap it into a DMBS transaction. The schema for the database is also depicted. public class PosDAO { private Connection connection; public PosDAO(Connection connection) { this.connection = connection; } public void…arrow_forward
- How do you check how many entries are contained in a map?arrow_forwardThe goal of this coding exercise is to create two classes BookstoreBook and LibraryBook. Both classes have these attributes: author: Stringtiltle: Stringisbn : String- The BookstoreBook has an additional data member to store the price of the book, and whether the book is on sale or not. If a bookstore book is on sale, we need to add the reduction percentage (like 20% off...etc). For a LibraryBook, we add the call number (that tells you where the book is in the library) as a string. The call number is automatically generated by the following procedure:The call number is a string with the format xx.yyy.c, where xx is the floor number that is randomly assigned (our library has 99 floors), yyy are the first three letters of the author’s name (we assume that all names are at least three letters long), and c is the last character of the isbn.- In each of the classes, add the setters, the getters, at least three constructors (of your choosing) and override the toString method (see samplerun…arrow_forwardCreate a Point class to hold x and y values for a point. Create methods show(), add() and subtract() to display the Point x and y values, and add and subtract point coordinates. Create another class Shape, which will form the basis of a set of shapes. The Shape class will contain default functions to calculate area and circumference of the shape, and provide the coordinates (Points) of a rectangle that encloses the shape (a bounding box). These will be overloaded by the derived classes; therefore, the default methods for Shape will only print a simple message to standard output. Create a display() function for Shape, which will display the name of the class and all stored information about the class (including area, circumference and bounding box). Build the hierarchy by creating the Shape classes Circle, Rectangle and Triangle. Search the Internet for the rules governing these shapes, if necessary. For these three Shape classes, create default constructors, as well as constructors…arrow_forward
- This is for pygame Text Class The Text class inherits from Drawable and it will be used to display the player's score. You must implement at the very least the required methods of the base class (draw and get_rect), as well as a constructor. You may need to implement other methods as part of the public interface. This is the Drawable Class import pygame import abc import random class Drawable(metaclass - abc. ABCMeta): def --init(self, x- 0, y -0): self.x - x self.y - y self.position - (self.x, self.y) self.visible - False def setloc(self, p): self.x - p[0] self.y - p[1] def getloc(self): return(self.x, self.y) def getX(self): return self.x def getY(self): return self.y eabc.abstractmethod def draw(self, surface): pass eabc.abstractmethod def get_rect(self): passarrow_forwardCreate a UML diagram to document the Cuboid class. You can model this class after the Rectangle class we covered in this chapter. It should have 3 data fields: width, length, height. It should have 3 accessors and 3 mutators. It should have a method that calculates the volume of the cuboid. Save your file in MS Word or PDF format. Hint: In MS Word, you can create a table of 1 column and 3 rows. What is a cuboid? You can consider a cuboid as a cube whose length, width, and height may not be equal to each other.arrow_forwardA getPaycheck method that implements the same method in the Employee class. Itcalculates the paycheck amount (m_hours × m_hourlyWage) and returns the studentworker’s paycheck as a string in the following format (Note that the three fields areseparated by a hyphen, represented by the minus character. Do NOT add spaces beforeor after each hyphen. There are no commas in the number.):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