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
There are two cons to an OLTP database. Which of the following are a solution of these cons?​
Delicious77 [7]

Answer:

The answer is below

Explanation:

An OLTP (Online transaction processing) database is a database that allows for quick transaction processing. It involves inserting, deleting, updating data in the database.

OLTP has many drawbacks like if the system fails, all transactions are going to have problems. Also, since multiple users are allowed to access the data, it makes it prone to hackers.

The solution to the problems associated to the OLTP database is the OLAP (online analytical processing) database.

The OLAP systems allow users to analyze database information from multiple database systems at one time thereby allowing analysis for business decisions.

6 0
4 years ago
Convert the following hexadecimal numbers to decimal numbers. (Show your work) a. 0xE3 b. 0x4A c. 0xF9
MAVERICK [17]

Answer:

a. 227 , b. 74 , c. 249

Explanation:

a. 0x E3 = 227

Hexadecimal Digit E corresponds to decimal number 14.

So decimal representation = 14 * 16 + 3 = 224 + 3 = 227

b. 0x 4A = 74

Hexadecimal Digit A corresponds to decimal number 10.

So decimal representation = 4 * 16 + 10 = 74

c. 0x F9 =

Hexadecimal Digit F corresponds to decimal number 15.

So decimal representation = 15 * 16 + 9 = 240 + 9 = 249

3 0
4 years ago
Which setting indents all but the first line of a paragraph by the selected length?
Phoenix [80]

Answer:

Hanging

Explanation:

5 0
3 years ago
What piece of hardware directs traffic between the connected devices when two LAN's are communicating across the Internet?
luda_lava [24]

Answer:

The correct answer is "Router".

Explanation:

In networking, routers is one of the main hardware which is used to direct the data traffic on a LAN system.

The router also works as an interconnection system for two or more than two networks. Routers mostly work between the internet and computer which directs the data to its right path.

It works between the computer system in a premise to make the networking possible through a LAN by using switches for communication between two or more than two devices in a LAN across the internet.

Hence, the most appropriate answer is the router.

3 0
3 years ago
In every programming language, when you access data stored in an array, you must use a ____ containing a value that accesses mem
Juli2301 [7.4K]

Answer: this app allow  u to have answers made for students 5 star ap but there are some ads that get  in the way

Explanation:

but it is good

7 0
3 years ago
Other questions:
  • Forensic professional able modify and reconstruct images of a missing child, predicting the appearance even twenty years later?
    13·1 answer
  • Your ASP.NET page contains a page-level variable of Customer type. You want to preserve the value of this variable across page p
    11·1 answer
  • Whats the relationship between cpu memory and disk​
    10·1 answer
  • Where can you access the property sheet
    8·1 answer
  • 1. Text that is located between and appears in the browser's
    13·1 answer
  • Unanswered questionl
    12·1 answer
  • Use of the Internet for e-government has increased. Identify the benefits by checking all of the boxes that apply.
    8·1 answer
  • Keli is unable to find a shape that meets her needs. Which feature in Power Point should she use to create shapes that are compl
    6·1 answer
  • Provide TWO reasons to explain why humans and animals need clean wat​
    9·2 answers
  • What ethical concerns might arise from applying new IT to law enforcement?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!