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

Lab 7A above. Using any editor (i.e., Notepad) you are to create and save a one

ID: 3632055 • Letter: L

Question

Lab 7A above. Using any editor (i.e., Notepad) you are to create and save a one line string file named randomCharacters.txt. The file string is made up of at least 50 characters: numbers (1 – 9), upper and lower case letters, and special characters including blanks. You are to write a program which reads the file string that was created. Your program will then modify the input string so that each upper case letter from A to J is replaced by a corresponding number A-1 B-2 C-D...etc. . Additionally each other upper case letter is converted to a lower case letter which is one more in the alphabet: .

Your output should look similar to this…..

Enter the file name: randomCharacters.txt
The contents of the input file string is....
ABCDEFGHIJKLMNZZZ123!@#
The contents of the converted file string is....
1234567890lmnoaaa123!@#
The contents of the appended file string is now....
ABCDEFGHIJKLMNZZZ123!@#1234567890lmnoaaa123!@#

Original code

public static void main(String[] args) throws FileNotFoundException {
String nameofFile, buff1, buff2;
nameofFile = getFilename();
Scanner input = openFile(nameofFile);
buff1 = getData(input);
buff2 = conversion(buff1);

print("Contents of the original characters", buff1);
print("Contents of the appended File String", buff2);
PrintStream output = new PrintStream(new File(nameofFile));
output.print(buff2);
}

public static String conversion(String buffer) {
String buffc = buffer;
int j;
char c;
for (j = 0; j < buffer.length(); j++) {
c = buffer.charAt(j);
if (Character.isDigit(c)) {
c += 16;
} else if (Character.isLowerCase(c)) {
c++;
if (c > 'z') {
c = '1';
}
}
buffc = buffc + c;
}
return buffc;
}

public static void print(String b, String buffer) {
System.out.println(b + ":");
System.out.println(buffer);
}

public static String getFilename() {
Scanner in = new Scanner(System.in);
String filename;
System.out.print("Enter the file name: ");
filename = in.nextLine();
return filename;
}

public static Scanner openFile(String filename) throws FileNotFoundException {
Scanner in = new Scanner(new File(filename));
return in;
}

public static String getData(Scanner input) {
return input.nextLine();
}
}
Code written in Java

Explanation / Answer

please rate - thanks

import java.util.*;
import java.io.*;
public class main{
public static void main(String[] args) throws FileNotFoundException {
String nameofFile, buff1, buff2;
nameofFile = getFilename();
Scanner input = openFile(nameofFile);
buff1 = getData(input);
print("Contents of the original characters", buff1);
buff2=buff1;
buff1 = conversion(buff1);


print("The contents of the converted file string is", buff1);
buff2=buff2+buff1;
print("Contents of the appended File String", buff2);
PrintStream output = new PrintStream(new File(nameofFile));
output.print(buff2);
}

public static String conversion(String buffer) {
String buffc = "";
int j;
char c;
for (j = 0; j < buffer.length(); j++) {
c = buffer.charAt(j);

if(c>='A'&&c<='J')
    {c=(char)((int)c-16);
    if(c>'9')
        c='0';
    }
else if(Character.isUpperCase(c))
     {c=Character.toLowerCase(c);
       c=(char)((int)c+1);
        if(c>'z')
           c='a';
        }
buffc = buffc + c;
}

return buffc;
}

public static void print(String b, String buffer) {
System.out.println(b + ":");
System.out.println(buffer);
}

public static String getFilename() {
Scanner in = new Scanner(System.in);
String filename;
System.out.print("Enter the file name: ");
filename = in.nextLine();
return filename;
}

public static Scanner openFile(String filename) throws FileNotFoundException {
Scanner in = new Scanner(new File(filename));
return in;
}

public static String getData(Scanner input) {
return input.nextLine();
}
}