I have completed until part 4 please do the rest import java
I have completed until part 4 please do the rest.
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.Random;
import java.util.Scanner;
public class MirrorWriter {
public static void main(String[] args) throws java.io.IOException {
Scanner scanner = new Scanner(new InputStreamReader(System.in));
FileWriter fw = new FileWriter(\"output.txt\");
boolean cont=true;
//rg is for jumbling the letters of input
Random rg=new Random();
//stores the jumbled string
String outText;
//this is the array where we jumble letters
char[] c_array;
while ( cont ) {
System.out.println (\"Enter a line of input\");
// Read a line of text.
String inputText = scanner.nextLine().toUpperCase();
// Stop if a blank line is detected.
if (inputText.length() == 0){
cont = false;
} else {
c_array=inputText.toCharArray();
// Go through each character of text in reverse order and write it to the file. take a string and look at every character. loop goes from 0 to length of the string. i goes to to last character and backwards till you print something. calculate tail of the string. string is
for (int i=0; i< inputText.length(); i++) {
int tail = inputText.length()-1;
//want to character at tail-i
fw.write(inputText.charAt(tail-i));
System.out.println(inputText.charAt(tail-i));
//char[] array = inputText.toCharArray();
}
}
fw.write(\"\ \");
System.out.println(\"\ \");
}
fw.close();
System.out.println(\"Done\");
}
}
Part 2 - Word Jumble Writer Modify Mirror writer to be an anagram writer. So, for example, the input Enter a line of input Hello there Enter a line of input goodbye Enter a line of input Done May be written in output.txt as EELLO THERH 00GDBYE To do this: 1. Add to your program (before the for loop starts) a random generator called rg, a string called outText, and a char array called c_array (you can initialize it to be of length 0, yoiu will override it later anyway). 2. When you read the string from the scanner, use .toUpperCase() to make all the letter uppercase. 3. Before the for loop, use .toCharArray() to save the inputText into c array. 4. In the for loop, use the random generator to get two random numbers, i1 and i2, that are smaller than inputText.length() 5. Swap the character from c array[i1] with the character from c array[i2]. (Remember: to swap elements, you will need a third temporary char that will hold one of the values while it is overridden with the other. Since this is in a loop, you will have inputText.length) number of swaps that will scramble the original word. 6. Outside of the loop, save into outText the c array as a string. To make a char array into a string use outText = new String(c-array); 7. Move the fw.write command to be right after you set outText and write the content of outText to the file.Solution
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Random;
public class MirrorWriter {
public static void main(String[] args) throws java.io.IOException {
Scanner scanner = new Scanner(new InputStreamReader(System.in));
char c_array[20];
FileWriter fw = new FileWriter(\"output.txt\");
boolean cont=true;
while ( cont ) {
System.out.println (\"Enter a line of input\");
// Read a line of text.
String inputText = scanner.nextLine();
inputText=inputText.toUpperCase();
// Stop if a blank line is detected.
if (inputText.length() == 0){
cont = false;
} else {
c_array=inputText.toCharArray();
Random r=new Random();
// Go through each character of text in reverse order and write it to the file.
for (int i=0; i< inputText.length(); i++) {
int tail = inputText.length()-1;
var:
int i1=r.nextInt(tail);
int i2=r.nextInt(tail);
if(i1==i2)goto var;
int temp;
temp=c_array[i1];
c_array[i1]=c_array[i2];
c_array[i2]=temp;
}
String outText=new String(c_array);
fw.write(outText);
}
fw.write(\"\ \");
}
fw.close();
System.out.println(\"Done\");
}
}


