Create a class ShuffleCipher that implements the interface MessageEncoder, as described in Exercise 15. The constructor should have one parameter caned n. Define the method encode so that the message is snuffled n times. To perform one shuffle, split the message in hair and then take characters from each half alternately. For example, if the message is abcdefghi, the halves are abcde and fghi. The shuffled message is afbgchcie. (Hint. You may wish to define a private method that performs one shuffle.)
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (8th Edition)
Software Engineering (10th Edition)
Concepts of Programming Languages (11th Edition)
Experiencing MIS
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Objects (6th Edition)
- What is the solution for this question (using java language)arrow_forwardImplement the above system using inheritance in the best possible way. Keep every object size as small as possible. Implement all methods (setter/getter/constructors and destructors) Note that the region area is 0 while the city is len*width and the country is the sum of their cities. Create array of countries called Arab of 22 countries. Write a function fill that fills the array Arab Write a method that finds the city that has the max area in a country Write a method that sorts the cities in a country from the largest to the smallest area Write a function that returns array of countries of the same area of Arab Write a function that compares between two countries. It returns true if country1 area greater than country2 area. Write a function to move a city from one country to another.arrow_forwardImplement the above system using inheritance in the best possible way. Keep every object size as small as possible. Implement all methods (setter/getter/constructors and destructors) Note that the region area is 0 while the city is len*width and the country is the sum of their cities. Create array of countries called Arab of 22 countries. Write a function fill that fills the array Arab Write a method that finds the city that has the max area in a country Write a method that sorts the cities in a country from the largest to the smallest area Write a function that returns array of countries of the same area of Arab Write a function that compares between two countries. It returns true if country1 area greater than country2 area. Write a function to move a city from one country to another.arrow_forward
- Create a class with a method. The method has to decide whether a given year is a leap year or not. Note- A year is a leap year if: • It has an extra day i.e. 366 instead of 365. It occurs in every 4 year e.g. 2008, 2012 are leap years. For every 100 years a special rule applies-1900 is not a leap year but 2000 is a leap year. In those cases, we need to check whether it is divisible by 400 or not. > > ClassAssignmentEx2 ©LeapYearDecider javaclassnotes.assignments javaclassnotes.assignments ClassAssignmentEx2() LeapYearDecider() main(String):void A isLeapYear(int):booleanarrow_forward1.A) The median of a set of integers is the middle-most integer in size. That is, half the integers in the set are less than or equal to the median, and half the integers are greater than or equal to the median. For example, the median of {99, 1, 10, 6, 2} is 6 since 1 and 2 are smaller than 6 and 10 and 99 are larger than 6. Implement a method median( ) with no parameters that finds and returns the median of the integers in a data array. Use this keyword in meaningfully. Assume that the data array is an instance variable of Data class. Write a parameterized constructor to allocate and assign values to data array. Assume that the array has odd length. Write main () in a separate class constructor to use the Data class.arrow_forwardMethods in Java Write a program that accepts three strings: first name, last name, age, and nationality. Create an object of the class Person and assign the inputs to their respective attributes. In the class, create a method greeting() that prints the attributes. Inputs 1. Input Cody Chum 20 Filipino Sample Output Enter first name: Cody Enter last name: Chum Enter age: 20 Enter nationality: Filipino Hello, I am Cody Chum, 20 years old and a Filipino!arrow_forward
- JAVA and use the code at the bottom 28.7 LAB: Acronyms An acronym is a word formed from the initial letters of words in a set phrase. Define a method named createAcronym that takes a string parameter and returns the acronym of the string parameter. Append a period (.) after each letter in the acronym. If a word begins with a lower case letter, don't include that letter in the acronym. Then write a main program that reads a phrase from input, calls createAcronym() with the input phrase as argument, and outputs the returned acronym. Assume the input has at least one upper case letter. Ex: If the input is: Institute of Electrical and Electronics Engineers the output should be: I.E.E.E. Ex: If the input is: Association for computing MACHINERY the output should be: A.M. Although the letters ACHINERY in MACHINERY are upper case, those letters are omitted for being a part of the word MACHINERY. The program must define and call a method:public static String createAcronym(String…arrow_forwardLet's get some more practice with algorithms by escaping from a maze! Implement a public class Maze Escape that provides a single public class method named escape. escape accepts a single parameter, a Maze object with methods explained below. Your goal is to manipulate the maze until you reach the exit, and then return it when you are finished. If the passed maze is null, throw an IllegalArgumentException. To navigate the maze, using the following Maze methods: • isFinished (): returns true when you have reached the exit of the maze • turnRight () rotates your character 90 degrees to the right • turnLeft() rotates your character 90 degrees to the left • canMove () returns true if you can move one cell forward, false otherwise. Your path may be blocked by a wall! • move () moves your character one cell forward and increases the step counter The passed Maze object represents a simply-connected or perfect maze: one that contains no loops. As a result, we suggest that you pursue a classic…arrow_forwardPYTHON CLASSES AND OBJECTarrow_forward
- write a c++ program Write a class Date that represents a date consisting of a year, month, and day. A Date classshould have the following methods:# Date(int year, int month, int day)Constructs a new Date object to represent the given date.# void add(int &days)Moves this Date object forward by the given number of days. hint:* you should decideon the basis of month and year that given month ends 30,31,28,29 days.# void add(int &month , int &days) Moves this Date object forward by the given number of months and days. Monthsshould be within 1 to 12 and days in 1 to 31. For Example Date 2003/12/31andadd(1,29) =>Date will be 2004/02/29# void add(Date & other)Moves this Date object forward by the given Date.# void addWeeks(int &weeks)Moves this Date object forward by the given number of seven-day weeks.# int daysTo(Date & other)Returns the number of days that this Date must be adjusted to make it equal to the givenother Date.# void subtract(int &days)Moves this…arrow_forward1. Modify the method beginsWithVowel. Use a different way to implement the method (try method indexOf() from the String class). 2. Modify the driver class to iteratively ask the user to enter a sentence, and then translate the sentence, until the user decides to quit the program. import java.util.Scanner;public class Translator { //instance variables //constructors //methods public static String translate(String sentence)// My name is Patrick Casseus { String result = ""; sentence = sentence.toLowerCase(); Scanner scan = new Scanner(sentence); while(scan.hasNext()) { result = result += translateWord(scan.next()) + " "; } return result; } private static String translateWord(String word) { String result = ""; if(startWithVowel(word)) result = word + "yay"; else if(startWithBlend(word)) // chair -> air + ch + ay result = word.substring(2) +…arrow_forwardKingdom of Trolls is celebrating their Kingdom Day and one of the activities that is taking place is a game where a player rolls a magic ball down the hill on a path with spikes. As the ball rolls down, it strikes a spike and bursts open to release a number of smaller balls (in our simulated game, the number of smaller balls is a randomly generated integer between 2 and 6, inclusive). As the smaller balls further roll down, when one strikes a spike, that ball and all its sibling balls burst and each generates another set of smaller balls (using the same random number already generated for the first roll). The balls keep rolling downhill and striking spikes and bursting into smaller balls until a golden ball is released by one of the bursts. At this time, the game is over and the player is told how many balls were generated during the last burst (including the golden ball). The game is played by two players at a time and the player who had the lowest number of balls generated on the…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