Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

package ch08.apps;
import ch08.maps.*;

public class HMapDriver 
{
  public static void main(String[] args)
  {
    boolean result;
    HMap<String, String> test;
    test = new HMap<String, String>(10,0.75);

/*
String s = null;
test.put(s,"value");
test.put("s",null);
System.out.println("Expect 'null':\t" + test.get("s"));
System.out.println("Expect 'true':\t" + test.contains("s"));
test = new ArrayListMap<String, String>();
*/

 

    System.out.println("Expect 'true':\t" + test.isEmpty());   
    System.out.println("Expect '0':\t" + test.size());  

    System.out.println("Expect 'null':\t" + test.put("1", "One"));
    System.out.println("Expect 'false':\t" + test.isEmpty());   
    System.out.println("Expect '1':\t" + test.size());  

    System.out.println("Expect 'One':\t" + test.put("1", "One"));
    System.out.println("Expect 'false':\t" + test.isEmpty());   
    System.out.println("Expect '1':\t" + test.size());  


    test.put("2", "Two");    
    test.put("3", "Three");    
    test.put("4", "Four");    
    test.put("5", "Five");    
    System.out.println("Expect '5':\t" + test.size());  

    System.out.println("Expect 'Three':\t" + test.put("3", "Three XXX"));
    System.out.println("Expect 'Three XXX':\t" + test.put("3", "Three"));
    System.out.println("Expect '5':\t" + test.size());  

    System.out.println("Expect 'true':\t" + test.contains("5"));
    System.out.println("Expect 'false':\t" + test.contains("6"));

    System.out.println(test);
   
    test.put("d","d");
     
    System.out.println(test);
    System.out.println("Expect 'true':\t" + test.contains("d"));
    System.out.println("Expect 'false':\t" + test.contains("e"));

 

    System.out.println("Expect 'One':\t" + test.get("1"));
    System.out.println("Expect 'One':\t" + test.get("1"));
    System.out.println("Expect 'Two':\t" + test.get("2"));
    System.out.println("Expect 'Three':\t" + test.get("3"));
    System.out.println("Expect 'Four':\t" + test.get("4"));
    System.out.println("Expect 'Five':\t" + test.get("5"));
    System.out.println("Expect 'null':\t" + test.get("6"));

    test.put("e","e");

    System.out.println(test);

    System.out.println("\nThe Map is:\n");
    for (MapEntry<String,String> m: test)
      System.out.println(m + "\n");

System.out.println(1);
    test.put("f","f");
System.out.println(2);
    System.out.println(test);
System.out.println(3);
    System.out.println("\nThe Map is:\n");
    for (MapEntry<String,String> m: test)
      System.out.println(m + "\n");
System.out.println(4);

 

  }
}

**Exercise 3: Detecting Repeated Words using HMap**

**Objective:**

Create an application that utilizes the `HMap` from Chapter 8 sample codes (located in the `bookFiles` folder). This application will read a list of words from a provided file and determine whether any word repeats.

**Instructions:**

1. **Implement the Application:**
   - Use the `HMap` data structure to track the words as they are read from the file.

2. **Input Handling:**
   - Read the list of words from the provided file.

3. **Output Requirements:**
   - The application should check for repeated words.
   - As soon as the application identifies at least one word that repeats, it should display the message:
     ```
     <such and such word> repeats
     ```
     and then terminate the execution.
   - If all words in the list are unique and no repetition is found, the application should display:
     ```
     No words repeat
     ```
     and terminate.

By following these steps, you will ensure that the application efficiently reads an input file and promptly identifies any repeated words. If no repeats are found, the application will appropriately indicate this outcome.
Transcribed Image Text:**Exercise 3: Detecting Repeated Words using HMap** **Objective:** Create an application that utilizes the `HMap` from Chapter 8 sample codes (located in the `bookFiles` folder). This application will read a list of words from a provided file and determine whether any word repeats. **Instructions:** 1. **Implement the Application:** - Use the `HMap` data structure to track the words as they are read from the file. 2. **Input Handling:** - Read the list of words from the provided file. 3. **Output Requirements:** - The application should check for repeated words. - As soon as the application identifies at least one word that repeats, it should display the message: ``` <such and such word> repeats ``` and then terminate the execution. - If all words in the list are unique and no repetition is found, the application should display: ``` No words repeat ``` and terminate. By following these steps, you will ensure that the application efficiently reads an input file and promptly identifies any repeated words. If no repeats are found, the application will appropriately indicate this outcome.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Database Environment
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education