Question
Please help me complete my Java assignment by improving my code with the following instructions (Please provide full code for copy and paste): Modify your
Please help me complete my Java assignment by improving my code with the following instructions (Please provide full code for copy and paste):
Modify your Poetry.java file to do the following: If the letter is coded to a vowel, make it a capital letter. Write your new encoded poem to a text file called capitalVowels.txt. Compile, save and run your file.
Modify your Poetry.java file to do the following: Take capitalVowels.txt and reverse the characters of each line of the file Then, decode the text back to its original letters Finally, write this text to a new file called reversePoem.txt. Make sure that the capitalised vowels go back to their original letters! Compile, save and run your file.
Here is my code:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class Poetry {
public static boolean isCharacterALetter(char c) {
return Character.isLetter(c);
}
public static ArrayList
int i = 0;
ArrayList
int nextAscii = 0;
while (i < str.length()) {
if (isCharacterALetter(str.charAt(i))) {
nextAscii = (int) str.charAt(i);
asciiArr.add(nextAscii);
} else {
asciiArr.add((int) str.charAt(i));
}
i++;
}
return asciiArr;
}
public static ArrayList
int i = 0;
ArrayList
while (i < arr.size()) {
if (isCharacterALetter((char) arr.get(i).intValue())) {
if (((arr.get(i) >= 108) && (arr.get(i) <= 122)) || ((arr.get(i) >= 76) && (arr.get(i) <= 90))) {
encodedArr.add(arr.get(i) - 11);
} else {
encodedArr.add(arr.get(i) + 15);
}
} else {
encodedArr.add(arr.get(i));
}
i++;
}
return encodedArr;
}
public static String toChar(ArrayList
int i = 0;
ArrayList
char nextChar;
while (i < arr.size()) {
if (isCharacterALetter((char) arr.get(i).intValue())) {
nextChar = (char) arr.get(i).intValue();
charArr.add(nextChar);
} else {
charArr.add((char) arr.get(i).intValue());
}
i++;
}
StringBuilder sb = new StringBuilder();
for (Character c : charArr) {
sb.append(c);
}
return sb.toString();
}
public static void main(String[] args) {
try {
Scanner scanner = new Scanner(new File("poem.txt"));
PrintWriter writer = new PrintWriter("encodedPoem.txt");
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
ArrayList
ArrayList
String encodedLine = toChar(encodedAscii);
writer.println(encodedLine);
}
scanner.close();
writer.close();
} catch (FileNotFoundException e) {
System.out.println("File not found.");
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started