SlideShare a Scribd company logo
1 of 2
Download to read offline
File PrintCoded.java (shown above) contains an incomplete program. The goal of the program is
to take as input strings from the user, and then print out coded (encrypted) versions of those
strings, by replacing each letter with another letter. Complete that program, by defining a
printCoded function, that satisfies the following specs:
Function printCoded takes three arguments, called word, sources, targets. They are all strings.
Function printCoded processes the letters of word one by one, in the order in which they appear
in word. For every such letter X, the function processes X as follows:
If X is equal to the character at position P of sources, then the function prints the character at
position P of targets.
Otherwise, the function prints X.
Note that arguments sources and targets are hardcoded in the main function, the user cannot
change those values. The user can only specify the value of word.
IMPORTANT: you are NOT allowed to modify in any way the main function.
This is an example run of the complete program:
Solution
PrintCoded.java
import java.util.Scanner;
public class PrintCoded
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String sources = "abcdefghijklmnopqrstuvwxyz";
String targets = "bcdefghijklmnopqrstuvwxyza";
while (true)
{
System.out.printf("Enter some word, or q to quit: ");
String word = in.next();
if (word.equals("q"))
{
System.out.printf("Exiting... ");
System.exit(0);
}
printCoded(word, sources, targets);
System.out.printf("  ");
}
}
public static void printCoded(String word, String sources, String targets){
for(int i=0; i

More Related Content

Similar to File PrintCoded.java (shown above) contains an incomplete program. T.pdf

import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
wilcockiris
 
Your 1ab8 c file is doe by Friday 1159pm to be submitted.pdf
Your 1ab8 c file is doe by Friday 1159pm to be submitted.pdfYour 1ab8 c file is doe by Friday 1159pm to be submitted.pdf
Your 1ab8 c file is doe by Friday 1159pm to be submitted.pdf
abhijitmaskey
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdf
ComedyTechnology
 
Instructions Write a program whose main function is merely a.pdf
Instructions Write a program whose main function is merely a.pdfInstructions Write a program whose main function is merely a.pdf
Instructions Write a program whose main function is merely a.pdf
adinathknit
 

Similar to File PrintCoded.java (shown above) contains an incomplete program. T.pdf (20)

import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
 
COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis: COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis:
 
over all view programming to computer
over all view programming to computer over all view programming to computer
over all view programming to computer
 
Your 1ab8 c file is doe by Friday 1159pm to be submitted.pdf
Your 1ab8 c file is doe by Friday 1159pm to be submitted.pdfYour 1ab8 c file is doe by Friday 1159pm to be submitted.pdf
Your 1ab8 c file is doe by Friday 1159pm to be submitted.pdf
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Getting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosGetting started with Microsoft Excel Macros
Getting started with Microsoft Excel Macros
 
Shanks
ShanksShanks
Shanks
 
Lexical and Parser tool for CBOOP program
Lexical and Parser tool for CBOOP programLexical and Parser tool for CBOOP program
Lexical and Parser tool for CBOOP program
 
Function
FunctionFunction
Function
 
Program by Demonstration using Version Space Algebra
Program by Demonstration using Version Space AlgebraProgram by Demonstration using Version Space Algebra
Program by Demonstration using Version Space Algebra
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdf
 
C programming language Reference Note
C programming language Reference NoteC programming language Reference Note
C programming language Reference Note
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
function in python programming languges .pptx
function in python programming languges .pptxfunction in python programming languges .pptx
function in python programming languges .pptx
 
Instructions Write a program whose main function is merely a.pdf
Instructions Write a program whose main function is merely a.pdfInstructions Write a program whose main function is merely a.pdf
Instructions Write a program whose main function is merely a.pdf
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
 

More from footsmart1

Student Outcome f the broad education necessary to understand th.pdf
Student Outcome f the broad education necessary to understand th.pdfStudent Outcome f the broad education necessary to understand th.pdf
Student Outcome f the broad education necessary to understand th.pdf
footsmart1
 
Post your response to the following focus questionsDescribe a sol.pdf
Post your response to the following focus questionsDescribe a sol.pdfPost your response to the following focus questionsDescribe a sol.pdf
Post your response to the following focus questionsDescribe a sol.pdf
footsmart1
 
Please fill in the code, which only need to add code in the adju.pdf
Please fill in the code, which only need to add code in the adju.pdfPlease fill in the code, which only need to add code in the adju.pdf
Please fill in the code, which only need to add code in the adju.pdf
footsmart1
 
Linear AlgebraHello. I need help with my practice final. I am not .pdf
Linear AlgebraHello. I need help with my practice final. I am not .pdfLinear AlgebraHello. I need help with my practice final. I am not .pdf
Linear AlgebraHello. I need help with my practice final. I am not .pdf
footsmart1
 
Many nations, including the US, already maintain a national DNA data.pdf
Many nations, including the US, already maintain a national DNA data.pdfMany nations, including the US, already maintain a national DNA data.pdf
Many nations, including the US, already maintain a national DNA data.pdf
footsmart1
 

More from footsmart1 (20)

Which of the following properties best describes pentoses Pentoses .pdf
Which of the following properties best describes pentoses  Pentoses .pdfWhich of the following properties best describes pentoses  Pentoses .pdf
Which of the following properties best describes pentoses Pentoses .pdf
 
What is going to be the output of the following program #include .pdf
What is going to be the output of the following program  #include   .pdfWhat is going to be the output of the following program  #include   .pdf
What is going to be the output of the following program #include .pdf
 
What competencies underpin successful management in implementing org.pdf
What competencies underpin successful management in implementing org.pdfWhat competencies underpin successful management in implementing org.pdf
What competencies underpin successful management in implementing org.pdf
 
What is frictionSolutionThe force that resist relative motion .pdf
What is frictionSolutionThe force that resist relative motion .pdfWhat is frictionSolutionThe force that resist relative motion .pdf
What is frictionSolutionThe force that resist relative motion .pdf
 
What happens to the nominal exchange rate when the USs rate increa.pdf
What happens to the nominal exchange rate when the USs rate increa.pdfWhat happens to the nominal exchange rate when the USs rate increa.pdf
What happens to the nominal exchange rate when the USs rate increa.pdf
 
What are the recent developments in corporate reporting practice .pdf
What are the recent developments in corporate reporting practice .pdfWhat are the recent developments in corporate reporting practice .pdf
What are the recent developments in corporate reporting practice .pdf
 
We have not seen any humming birds in this forest todayWe have not.pdf
We have not seen any humming birds in this forest todayWe have not.pdfWe have not seen any humming birds in this forest todayWe have not.pdf
We have not seen any humming birds in this forest todayWe have not.pdf
 
Verbal statementscannot be a probabilitythe event is very unlik.pdf
Verbal statementscannot be a probabilitythe event is very unlik.pdfVerbal statementscannot be a probabilitythe event is very unlik.pdf
Verbal statementscannot be a probabilitythe event is very unlik.pdf
 
The three major domains of li.pdf
The three major domains of li.pdfThe three major domains of li.pdf
The three major domains of li.pdf
 
There are two major groups of seed plants, gymnosperms (Exercise 24) .pdf
There are two major groups of seed plants, gymnosperms (Exercise 24) .pdfThere are two major groups of seed plants, gymnosperms (Exercise 24) .pdf
There are two major groups of seed plants, gymnosperms (Exercise 24) .pdf
 
The steps in the closing process are (1) close credit balances in re.pdf
The steps in the closing process are (1) close credit balances in re.pdfThe steps in the closing process are (1) close credit balances in re.pdf
The steps in the closing process are (1) close credit balances in re.pdf
 
The positron decay of ^15 O goes directly to the ground state of ^15 .pdf
The positron decay of ^15 O goes directly to the ground state of ^15 .pdfThe positron decay of ^15 O goes directly to the ground state of ^15 .pdf
The positron decay of ^15 O goes directly to the ground state of ^15 .pdf
 
The disease bullous pemphigoid results in the destruction of protein.pdf
The disease bullous pemphigoid results in the destruction of protein.pdfThe disease bullous pemphigoid results in the destruction of protein.pdf
The disease bullous pemphigoid results in the destruction of protein.pdf
 
Student Outcome f the broad education necessary to understand th.pdf
Student Outcome f the broad education necessary to understand th.pdfStudent Outcome f the broad education necessary to understand th.pdf
Student Outcome f the broad education necessary to understand th.pdf
 
QUESTION 8 1.00000 P Financial intermediaries are different from inve.pdf
QUESTION 8 1.00000 P Financial intermediaries are different from inve.pdfQUESTION 8 1.00000 P Financial intermediaries are different from inve.pdf
QUESTION 8 1.00000 P Financial intermediaries are different from inve.pdf
 
Post your response to the following focus questionsDescribe a sol.pdf
Post your response to the following focus questionsDescribe a sol.pdfPost your response to the following focus questionsDescribe a sol.pdf
Post your response to the following focus questionsDescribe a sol.pdf
 
Please fill in the code, which only need to add code in the adju.pdf
Please fill in the code, which only need to add code in the adju.pdfPlease fill in the code, which only need to add code in the adju.pdf
Please fill in the code, which only need to add code in the adju.pdf
 
Linear AlgebraHello. I need help with my practice final. I am not .pdf
Linear AlgebraHello. I need help with my practice final. I am not .pdfLinear AlgebraHello. I need help with my practice final. I am not .pdf
Linear AlgebraHello. I need help with my practice final. I am not .pdf
 
Many nations, including the US, already maintain a national DNA data.pdf
Many nations, including the US, already maintain a national DNA data.pdfMany nations, including the US, already maintain a national DNA data.pdf
Many nations, including the US, already maintain a national DNA data.pdf
 
implement the add() method for min-heappublic class Heap {    .pdf
implement the add() method for min-heappublic class Heap {    .pdfimplement the add() method for min-heappublic class Heap {    .pdf
implement the add() method for min-heappublic class Heap {    .pdf
 

Recently uploaded

Recently uploaded (20)

latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 

File PrintCoded.java (shown above) contains an incomplete program. T.pdf

  • 1. File PrintCoded.java (shown above) contains an incomplete program. The goal of the program is to take as input strings from the user, and then print out coded (encrypted) versions of those strings, by replacing each letter with another letter. Complete that program, by defining a printCoded function, that satisfies the following specs: Function printCoded takes three arguments, called word, sources, targets. They are all strings. Function printCoded processes the letters of word one by one, in the order in which they appear in word. For every such letter X, the function processes X as follows: If X is equal to the character at position P of sources, then the function prints the character at position P of targets. Otherwise, the function prints X. Note that arguments sources and targets are hardcoded in the main function, the user cannot change those values. The user can only specify the value of word. IMPORTANT: you are NOT allowed to modify in any way the main function. This is an example run of the complete program: Solution PrintCoded.java import java.util.Scanner; public class PrintCoded { public static void main(String[] args) { Scanner in = new Scanner(System.in); String sources = "abcdefghijklmnopqrstuvwxyz"; String targets = "bcdefghijklmnopqrstuvwxyza"; while (true) { System.out.printf("Enter some word, or q to quit: "); String word = in.next();
  • 2. if (word.equals("q")) { System.out.printf("Exiting... "); System.exit(0); } printCoded(word, sources, targets); System.out.printf(" "); } } public static void printCoded(String word, String sources, String targets){ for(int i=0; i