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
Mightier than the waves of the sea is his love for you
Inessa05 [86]

cool but kinda creepy ngl

8 0
3 years ago
Two technicians are discussing using a lift to raise a vehicle. Technician A says to be sure the lift pads on the lift are conta
lianna [129]
Its B no doubt
cuz ik how to do this i took classes for this so ik im right ight
6 0
3 years ago
Read 2 more answers
in the client server model, what is the primary protocol used for communication between a browser and Web server
worty [1.4K]
Assuming the client is using a web browser, your answer would most likely be the Hyper-Text Transfer Protocol (HTTP).

HTTP is a very, very common way of transfering insensitive data from client to server. HTTPS is more secure, adding a secure socket layer to protect communications from being intercepted.

--

As an alternative answer, the FTP (File Transfer Protocol) may be an acceptable answer, but this is usually not the primary method of communication for clients, as it is mainly used to access and modify files on the server, requiring a username-password combo to do so (usually).


7 0
3 years ago
What are the benefits if you pay off all your high-interest debt such as credit
lesya [120]
D. All of the above
7 0
4 years ago
Read 2 more answers
Which shortcut brings up the Print screen?
sashaice [31]

The answer is alt + prt sc

5 0
3 years ago
Read 2 more answers
Other questions:
  • Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than
    6·1 answer
  • Seasons Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month a
    14·1 answer
  • What is the output <br>this is a computer science question ​
    8·1 answer
  • Magnetic field strength in an ignition coil is measured in what units?
    15·2 answers
  • java Consider a class MotorBoat that represents motorboats. A motorboat has attributes for: The capacity of the fuel tank The am
    15·1 answer
  • Which of the following is a valid formula?<br> (C2-D16)<br> O A2/F2<br> O=B5/10<br> O =E10
    14·1 answer
  • When an object is created, the attributes associated with the object are called: A. instance fields B. instance methods C. fixed
    11·1 answer
  • Who requests services and who facilitates services to a client.​
    6·1 answer
  • Pls help me awnser this I will give points
    10·1 answer
  • Which measure is best to use to avoid outliers from corrupting the average?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!