Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Question
Chapter 3, Problem 40P
Program Plan Intro
Substitution Cipher
Program plan:
- Import the required java packages.
- Create the class SubstitutionCipher.
- Create object “pac” for the class SubstitutionCipher1.
- Declare the constructor.
- Create the nested class SubstitutionCipher1.
- Declare and initialize the string.
- Declare one character array.
- Declare the constructor.
- Define the method encoding() to encode the given string.
- Define the main() method,
- Create the object for SubstitutionCipher class.
- Gets the input string from the user using the scanner.
- Pass the values for parameters using the object and call the constructor to perform the defined function.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Implement the Plates class buildMap function so that it populates the HashMap with the state abbreviations as keys and the counts of how many each appear in the file as values.
Sometimes, the parking attendant will add special notation to help her remember something about a specific entry. There are just non alphabetic characters that she adds to the state - your program should ignore these characters so that an entry like NY* still counts toward the NY plate count.
She is also very inconsistent with how she enters the plates. Sometimes she uses upper case, sometimes lowercase, and sometimes she even uses a mix. Be sure to account for this in your program.
Only add information for plates in New England (Maine, New Hampshire, Vermont, Massachusetts, Rhode Island, and Connecticut).
Plates.java
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class Plates {
private Map<String, Integer> plateMap;…
Imagine you are reading in a stream of integers. Periodically, you wishto be able to look up the rank of a number x (the number of values less than or equal to x). Implement the data structures and algorithms to support these operations. That is, implement the method track(int x), which is called when each number is generated, and the method getRankOfNumber(int x), which returns the number of values less than or equal to x (not including x itself).EXAMPLEStream(in order of appearance):5, 1, 4, 4, 5, 9, 7, 13, 3getRankOfNumber(l) 0getRankOfNumber(3) 1getRankOfNumber(4) 3
Imagine you are reading in a stream of integers. Periodically, you wishto be able to look up the rank of a number x (the number of values less than or equal to x). Implement the data structures and algorithms to support these operations. That is, implement the method track(int x), which is called when each number is generated, and the method getRankOfNumber(int x), which returns the number of values less than or equal to x (notincluding x itself).EXAMPLEStream(in order of appearance):5, 1, 4, 4, 5, 9, 7, 13, 3getRankOfNumber(l) 0getRankOfNumber(3) 1getRankOfNumber(4) 3
Chapter 3 Solutions
Data Structures and Algorithms in Java
Ch. 3 - Prob. 1RCh. 3 - Write a Java method that repeatedly selects and...Ch. 3 - Prob. 3RCh. 3 - The TicTacToe class of Code Fragments 3.9 and 3.10...Ch. 3 - Prob. 5RCh. 3 - Prob. 6RCh. 3 - Prob. 7RCh. 3 - Prob. 8RCh. 3 - Prob. 9RCh. 3 - Prob. 10R
Ch. 3 - Prob. 11RCh. 3 - Prob. 12RCh. 3 - Prob. 13RCh. 3 - Prob. 14RCh. 3 - Prob. 15RCh. 3 - Prob. 16RCh. 3 - Prob. 17CCh. 3 - Prob. 18CCh. 3 - Prob. 19CCh. 3 - Give examples of values for a and b in the...Ch. 3 - Suppose you are given an array, A, containing 100...Ch. 3 - Write a method, shuffle(A), that rearranges the...Ch. 3 - Suppose you are designing a multiplayer game that...Ch. 3 - Write a Java method that takes two...Ch. 3 - Prob. 25CCh. 3 - Prob. 26CCh. 3 - Prob. 27CCh. 3 - Prob. 28CCh. 3 - Prob. 29CCh. 3 - Prob. 30CCh. 3 - Prob. 31CCh. 3 - Prob. 32CCh. 3 - Prob. 33CCh. 3 - Prob. 34CCh. 3 - Prob. 35CCh. 3 - Write a Java program for a matrix class that can...Ch. 3 - Write a class that maintains the top ten scores...Ch. 3 - Prob. 38PCh. 3 - Write a program that can perform the Caesar cipher...Ch. 3 - Prob. 40PCh. 3 - Prob. 41PCh. 3 - Prob. 42PCh. 3 - Prob. 43P
Knowledge Booster
Similar questions
- Import the HashMap and Map classes from the java.util package. Within the main method, a sentence is declared as a string variable and assigned the value "This is a test sentence with no repeating words". Split the sentence into words using the split method and store the result in a String array called "words". Create a new Map called "wordFrequency" that stores each word as a key and the frequency of the word in the sentence as the corresponding value using the HashMap implementation. Use a for loop to iterate through each word in the "words" array. Within the for loop, the code should use the containsKey method to check if the word is already in the Map. If the word is already in the Map, its frequency should be incremented by 1. Use the put method to add the word as the key and the incremented frequency as the value to increment it. If the word is not in the map, add it as a new key with a frequency of 1 as its value. Outside of the for loop, use System.out.println to…arrow_forwardImplement the interface DictionaryInterface<string, string> to create a class of glossaries. A glossary is a dictionary of specialized terms and their corresponding definitions. Represent the glossary as a collection of 26 sorted lists, one list for each letter of the alphabet. Each entry—which consists of a term and its definition—in a glossary is stored in the sorted list corresponding to the term’s first letter. Thoroughly test your class using a text file of terms and definitions as data for your glossary. Java programarrow_forwardImplement the FindText() function, which has two strings as parameters. The first parameter is the text to be found in the user provided sample text, and the second parameter is the user provided sample text. The function returns the number of instances a word or phrase is found in the string. In the PrintMenu() function, prompt the user for a word or phrase to be found and then call FindText() in the PrintMenu() function. Before the prompt, call cin.ignore() to allow the user to input a new string.Ex: Enter a word or phrase to be found: more "more" instances: 5arrow_forward
- Write a Java program that prompts a user for vehicle data and stores it in a linked list, and then sorts the list in ascending order based on miles-per-gallon and writes the sorted data to a text file, you can follow these steps: Create a class named Vehicle with private fields: make (String), model (String), and milesPerGallon (double). Include getters and setters for these fields. Implement the Comparable interface for Vehicle class and override the compareTo() method to compare vehicles based on their milesPerGallon. Create a main class (for example, VehicleDriver.java) to handle user input and perform the necessary operations. Inside the main method, create a BufferedReader object for user input. Prompt the user to enter the number of vehicle data they want to enter and store it in a variable (for example, nVehicles). Use a loop to iterate nVehicles times and prompt the user to enter make, model, and miles per gallon for each vehicle. Create Vehicle objects using the input data…arrow_forwardThere is a class Country that has methods getContinent() and getPopulation(). Write a function int getPopulation(List countries, String continent) that computes the total population of a given continent, given a list of all countries and the name of a continent.arrow_forwardJava. Implement a method that will return a String with an array's elements separated by spaces. The mehod will recieve three parameters: the integer array, a start index, and an end index. Both start and end are includive. The method's signature is as follows: public static String printRange(int [], int, int) - make the method public to faciliate testing - If the indexes are outside the bounds of the array, the method should return "Invalid Range." Otherwise, the method will return a String containing one integer after the other on the same line separated by one space. Example 1: Given {4,1,2,36,6}, 1, 3 as the parameters; the method should return "1 2 36" Example 2: Given {4,1,2,36,6}, 0, 7 as the parameters; the method should return "Invalid Range"arrow_forward
- Implement a mechanism for performing basic string compression using repeated character counts. The string aabccccaaa, for example, would become a2blc5a3. Your method should return the original string if the "compressed" string does not grow smaller than the original string. You can assume that the string only contains uppercase and lowercase letters (a-z).arrow_forwardJAVA 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_forwardImplement the fix_capitalization() function. fix_capitalization() has a string parameter and returns an updated string, where lowercase letters at the beginning of sentences are replaced with uppercase letters. fix_capitalization() also returns the number of letters that have been capitalized. Call fix_capitalization() in the print_menu() function, and then output the edited string followed by the number of letters capitalized. Hint 1: Look up and use Python functions .islower() and .upper() to complete this task. Hint 2: Create an empty string and use string concatenation to make edits to the string. Ex: Number of letters capitalized: 2arrow_forward
- implement a c# program that tests our implementation of the CSet class by creating two sets, performing a union of the two sets, an intersection of the two sets, finding the subset of the two sets, and the difference of the two sets.arrow_forwardWrite the programme with Java Programming lang.arrow_forwardUsing the picture, ultilize Java to design a container class and implement the class PascalTriangle that will generate a Pascal Triangle from a given number of rows. Please represent each row in a triangle as a list and the entire triangle as a list of these lists, implement the class ArrayList for these lists. Inside this Java container class, develop a method called getChoice that takes in two parameters n and k (where n is the number for row and k is the position) and returns the integer value of C(n, k). For example, getChoices (5, 2) will return 7.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education