Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java program that does basic encrypting of text. You will ask the user t

ID: 3837798 • Letter: W

Question

Write a java program that does basic encrypting of text. You will ask the user the filename of a text file which contains a few sentences of text. You will read this text file one character at a time, and change each letter to another one and write out to an output file. The conversion should be done a -> b, b->c , … z->a, A->B, B->C, …. Z->A. This means just shift each letter by one, but Z goes back to A. Example: Hello converts to Ifmmp All other punctuation and spaces or symbols can stay as they are.

Explanation / Answer

aboutComputer.txt (Save this file under D Drive.Then the path of the file pointing to it is D:\aboutComputer.txt )

A computer is a device that can be instructed to carry out an
arbitrary set of arithmetic or logical operations automatically.
The ability of computers to follow a sequence of operations
called a program make computers very flexible and useful.
Since ancient times simple manual devices like the abacus
aided people in doing calculations. Early in the Industrial
Revolution, some mechanical devices were built to automate
long tedious tasks, such as guiding patterns for looms.

___________________

Program:

package org.students;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class NextChar {

   public static void main(String[] args) throws IOException {
       //Declaring variables
       String sentence;
  
       String filePath="D:\PCOutFile.txt";
      
       //Creating BufferedWrier class object
       BufferedWriter writer = new BufferedWriter(new FileWriter(filePath));
       Scanner sc=new Scanner(new File("D:\aboutComputer.txt"));
  
       //read each line from the file
       while(sc.hasNextLine())
       {
           sentence=sc.nextLine();
           for (int i = 0; i < sentence.length(); i++) {
if (sentence.charAt(i) == 'z') {
  
   writer.write( 'a' );
}
else if (sentence.charAt(i) == 'Z') {
   writer.write('A');
}
else if ((sentence.charAt(i) >= 65 && sentence.charAt(i) <= 90) || (sentence.charAt(i) >= 97 && sentence.charAt(i) <= 122))
{
  
   writer.write((char)(sentence.charAt(i) + 1)) ;
}
else {
   writer.write(sentence.charAt(i));
}
}
           writer.newLine();
}
       //closing the output file
       writer.close();      

}
}

______________________

PCOutfile.txt ((We can See this file under D Drive.As we specified the path of the output file as D:\PCOutfile.txt)

B dpnqvufs jt b efwjdf uibu dbo cf jotusvdufe up dbssz pvu bo
bscjusbsz tfu pg bsjuinfujd ps mphjdbm pqfsbujpot bvupnbujdbmmz.
Uif bcjmjuz pg dpnqvufst up gpmmpx b tfrvfodf pg pqfsbujpot
dbmmfe b qsphsbn nblf dpnqvufst wfsz gmfyjcmf boe vtfgvm.
Tjodf bodjfou ujnft tjnqmf nbovbm efwjdft mjlf uif bcbdvt
bjefe qfpqmf jo epjoh dbmdvmbujpot. Fbsmz jo uif Joevtusjbm
Sfwpmvujpo, tpnf nfdibojdbm efwjdft xfsf cvjmu up bvupnbuf
mpoh ufejpvt ubtlt, tvdi bt hvjejoh qbuufsot gps mppnt.

___________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote