1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MAVERICK [17]
3 years ago
5

Create an interface MessageDecoder that has a single abstract method decode(cipherText), where cipherText is the message to be d

ecoded. The method will return the decoded message. Modify the classes SubstitutionCipher and ShuffleCipher, as described in Programming Problem 2, above, so that they implement MessageDecoder as well as the interface MessageEncoder described above. Finally, write a program that allows a user to encode and decode messages entered on the keyboard.

Computers and Technology
1 answer:
Nastasia [14]3 years ago
3 0

Answer:

Check the explanation

Explanation:

MessageEncoder. java

public interface MessageEncoder

{

  //single abstract method encode(plainText) where plainText is the message to be encoded.

  public String encode(String plainText);

}//end interface

SubstitutionCipher. java

import java.util.Scanner;

public class SubstitutionCipher implements MessageEncoder, MessageDecoder

{

   /**

     The constructor should have 1 parameter called shift

   */

   private int shift;

 

   /**

     Non-default constructor with one parameter    

   */

   public SubstitutionCipher(int numberSpaces)

   {

       shift = numberSpaces;

   }//end non default constructor

 

   /**

     Define the method encode so that each letter is shifted by the value in shift

   */

   public String encode(String plainText)

   {

       String cipherText = "";

       for(int i = 0; i < plainText. length(); i++)

       {

           Character encodeLetter = plainText.charAt(i);

           cipherText = cipherText + shift1Character(encodeLetter);

       }//end for loop

       return cipherText;

   }//end encode method

 

   /**

     Define the method decode so that each letter is shifted by minus the value in shift

   */

   public String decode(String cipherText)

   {

       String plainText = "";

       for(int i = 0; i < cipherText. length(); i++)

       {

           Character decodeLetter = cipherText.charAt(i);

           plainText = plainText + shift1CharacterBack(decodeLetter);

       }//end for loop

       return plainText;

   }//end encode method

   /**

     Hint: You may wish to define a private method that shifts a single character

   */

   private Character shift1Character(Character oneLetter)

   {

       return (char)(oneLetter + shift);

   }//end method

 

   /**

     Hint: You may wish to define a private method that shifts a single character

           back to its original position

   */

   private Character shift1CharacterBack(Character oneLetter)

   {

       return (char)(oneLetter - shift);

   }//end method

 

////////////////////////////////////////////////////////////////////////////////////////////////////////

   public static void main(String[] args)

   {

       Scanner keyboard = new Scanner(System.in);

       SubstitutionCipher shift3Places = new SubstitutionCipher(3);

       System.out.println("Substituation method using caesar shift: \n");

       String plainText = "I think I am finally back on track\n";

       System.out.println("Plain text to be encoded: " + plainText);

     

       String cipher = shift3Places.encode(plainText);

       System.out.println("Cipher text after encoding: " + cipher);

     

       SubstitutionCipher shiftMinus3 = new SubstitutionCipher(-3);

       System.out.println("\n\nTime to decode the cipher now.\n");

     

       String decoded = shiftMinus3. encode(cipher);

       System.out.println("Decoded text after removing cipher: " + decoded);

   

       ////////////////////////////////////////////////////////////////////////////System.out.println("Testing the decode method.");

       ////////////////////////////////////////////////////////////////////////////decoded = shift3Places. decode(cipher);

       ////////////////////////////////////////////////////////////////////////////System.out.println("Text after decoding: " + decoded);

   }//end main

}//end class

MessageDecoder. java

public interface MessageDecoder

{

  //single abstract method decode(cipherText) where cipherText is the message to be decoded.

  public String decode(String cipherText);

}//end interface

You might be interested in
When he takes a picture, Simon freezes an action without blurring it, to show movement. Which type of photographer is he?
Jlenok [28]

Answer:

freezing action photographer i think this is the type.... i don't know much about photography yet

Explanation:

6 0
3 years ago
Read 2 more answers
Imagine that you've properly connected your multimeter into an operating circuit, and the meter's function/range switch is set t
Free_Kalibri [48]
If the meter is set to  read DC voltage in the 20 volt range and it displays a 1 then it should mean 1 volt assuming that the maximum reading would be 20 volts at that setting. But if it is only around 1 volt is might be more accurate to set it at say 2V range to get say 1.6 actual volts.
8 0
3 years ago
Read 2 more answers
What percentage of business are using social media today
Kitty [74]

100% because social media is use for every news or business

5 0
3 years ago
What is the process viewing files in chrome web browser cache?
Andreyy89

Step 1. Click the address bar at the top of your Google Chrome window, type "About: cache" into the box and press "Enter." A page will appear with a list of cached files and their addresses.

Step 2. Press the "Ctrl" and "F" keys on your keyboard at the same time to open the find bar.

Step 3. Type part of the name or address of a cached file into the find box and press "Enter" to find it. Continue pressing "Enter" to page through any matching results.

Step 4. Select the full address of the cached file on the page with your mouse and press "Ctrl" and "C" at the same time to copy the address.

Step 5. Click the address bar, press "Ctrl" and "V" at the same time to paste the address and press "Enter" to load the file. Chrome loads the file from the cache.

Step 6. Right-click the image, page or script and select "Save As" to save the cached file to your computer.

6 0
3 years ago
30 POINTS! ANSWER ASAP:
Monica [59]

Answer:

roof

Explanation:

6 0
3 years ago
Other questions:
  • matlab Write a function that iteratively appends random 1's and 0's to an array to form a binary number. The function returns th
    9·1 answer
  • Which of the following best describes Vivofit’s purpose?
    9·1 answer
  • What is the Web of Trust?
    12·1 answer
  • What type of scientists studies tree rings to determine the history of an area?
    9·2 answers
  • The technique of ________ uses three columns that allows the entrepreneur to weigh both the advantages and the disadvantages of
    13·1 answer
  • write the structure of an email message ques.2 what do you mean by search engine? write its component .ques. 3 what are the adva
    9·1 answer
  • _______For the C programming language, files containing the code you write are named with a file extension of .g. (T/F)
    8·1 answer
  • Evaluate the expression. Be sure to list a value of appropriate type (e.g., 7.0 rather than 7 for a double, Strings in quotes).
    7·1 answer
  • You are managing an FTP server installed in Ubuntu Server. The server has created a very large log le, vsftpd.log. Which command
    14·1 answer
  • An option already selected by windows is called____ ( default option/ default selection)​.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!