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
mylen [45]
3 years ago
15

This project involves writing a program that encodes and decodes messages. The program should prompt the user to select whether

a message is to be encoded or decoded, and then prompts the user to enter the message. A blank space is used to separate each word in the message, and a period (.) is used to denote the end of a sentence. Separate methods must be used to encode and decode the input message. The coding scheme is very simple: the code
Computers and Technology
1 answer:
Lilit [14]3 years ago
8 0

Answer:

See explaination

Explanation:

import java.util.Scanner;

public class EncodeDecodeMessage {

public static String encode(String str) {

String result = "";

char ch;

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

ch = str.charAt(i);

if(Character.isLowerCase(ch)) {

result += (char)('a' + (25-ch+'a'));

} else if(Character.isUpperCase(ch)) {

result += (char)('A' + (25-ch+'A'));

} else {

result += ch;

}

}

return result;

}

public static String decode(String str) {

return encode(str); // since the scheme is same, we can use encode for decode

}

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.print("1. Encode, 2. Decode. Enter your choice: ");

int choice = in.nextInt();

in.nextLine();

if(choice == 1) {

System.out.print("Enter sentence to encode: ");

String line = in.nextLine();

System.out.println("Encoded string is: " + encode(line));

} else if(choice == 2) {

System.out.print("Enter sentence to decode: ");

String line = in.nextLine();

System.out.println("Decoded string is: " + decode(line));

}

}

}

You might be interested in
What is the impedance mismatch problem? Which of the three programming
kykrilka [37]

Answer:

The problem that created due to the difference in the model of programming language and the database model.

Explanation:

The practical relational model has three components which are as follows

1. Attributes

2. Datatypes

3. Tuples

To minimize this problem  

1. We switch low pass L-Network to high pass L-network

2. We switch high pass L-Network to low pass L-network

3. We use the impedence matching transformer

3 0
3 years ago
Given the following method definitions: void mystery(double a) { System.out.print("double! "); } void mystery(int a) { System.ou
kicyunya [14]

Answer:

The correct answer to the following question is option "b".  

Explanation:

The method having the same name but the arguments have different so it is called method overloading. It is a part of the object-oriented programming language (oops).  

  • In the given code we define same method two times that is "mystery()". but in this method, we pass two different parameters. For the first time, we pass a double variable that is "a" as a parameter. In the second time, we pass an integer variable that is "a" as a parameter and in both functions, we write some codes.
  • In the calling time, we call function two times. In first time calling we pass an integer value that is "1" and second time calling we pass double value that is "1.0". So the output of this code is "int! double!".  

That's why the option "b" is correct.

6 0
3 years ago
Which layout manager constructor call would be best-suited to create a telephone handset GUI which has three rows of three keys
Snezhnost [94]

Answer:

The correct option : b. new GridLayout(4,3)

Explanation:

The total number of rows are 4 and total number of columns are 3.

So the total keys can be added is 4*3=12. This is suited for telephone keypad.

7 0
3 years ago
Which column and row references are updated when you copy the formula: =F$5+12?
KIM [24]

Answer:

Column F and row 5

7 0
3 years ago
In which scenario would instant messaging be more useful than other forms of communication?
Fed [463]
When you're in a library and you don't want to disturb other people.
8 0
3 years ago
Other questions:
  • Lucy has to move data from column A to column N in a worksheet. Which keys should she select to move data in the same worksheet?
    7·2 answers
  • Given the variables isfulltimestudent and age, write an expression that evaluates to true if age is less than 19 or isfulltimest
    12·1 answer
  • Which of the following is a reason why the comments tool within PDF documents could be helpful? (Select all that apply.)
    5·1 answer
  • What is the main storage location of a computer
    13·1 answer
  • Which of the following is an example of a query with an explicit location? Select all that apply. True False [walmart boston], E
    7·2 answers
  • A computer is defined by 4 specific criteri. Select all 4.*
    7·1 answer
  • You load an image file into a numpy array and look at its shape, which is (433, 650). What does this indicate?
    13·1 answer
  • Write a simple hello world program in python 3
    8·2 answers
  • Jane receives an email claiming that her bank account information has been lost and that she needs to click a link to update the
    13·1 answer
  • Language modeling incorporates rules of __. Select all that apply.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!