The objectives of this lab are to reinforce and help teach:
In this lab you will write a program that reads a text file into a two-dimensional array. The text file contains characters that represent an "ASCII-art" letter. As such, the text file has exactly 7 lines, with each line having 15 characters. Your program will print out the "letter", then it will vertically flip the letter, and lastly print the flipped letter.
Following are the instructions and you should follow them carefully:
Your program shall read the letter.txt file from the current directory. The file has exactly 7 lines and each line has exactly 15 characters. Each character of each line could be anything, but expect that the file will represent an ASCII-art letter composed of space characters and other characters that represent the letter.
For example, the capital letter "T" would be represented by a file containing the following characters:
###############
###############
###
###
###
###
###
When creating your own sample letter.txt file make sure that it has exactly 7 lines and each line has exactly 15 characters (even if trailing spaces are needed on a line to make it exactly 15 characters long).
Your program must implement the following three methods exactly as defined:
/**
* Reads an ASCII-art letter given a file Scanner and returns the letter
* as a two-dimensional char array.
*
* @param file - A file scanner to read
*
* @return char[][] - The two-dimensional ASCII letter to read
*/
public static char[][] readLetter(Scanner file) {
// YOUR CODE GOES HERE
}
/**
* Prints a two-dimensional array of characters holding an
* ASCII-art letter to the screen and then after printing
* the two-dimensional array print a blank line.
*
* @param letter - The two-dimensional ASCII letter to print
*/
public static void printLetter(char[][] letter) {
// YOUR CODE GOES HERE
}
/**
* Vertically flips a two-dimensional array of characters holding
* an ASCII-art letter.
*
* @param letter - The two-dimensional ASCII letter to flip.
*/
public static void flipLetter(char[][] letter) {
// YOUR CODE GOES HERE
}
With the above methods coded exactly as defined, with the formal parameters as stated and the return types as specified, your main program is simple and straightforward as follows (feel free to copy and paste):
public static void main(String[] args) throws FileNotFoundException {
Scanner file = new Scanner(new File("letter.txt"));
char[][] letter = readLetter(file);
printLetter(letter);
flipLetter(letter);
printLetter(letter);
}
DO NOT change the main method above. DO NOT author a flipLetter method that
simply prints the letter upside down (from bottom to top). If you do these things you will get a failing
grade for this lab.
Your program should read the text file into a two-dimensional array, print out the file contents from the two dimensional array, print a blank line, flip the contents of the two-dimensional array vertically, and then print the resulting letter.
Example output, given the letter T as described above is as follows:
###############
###############
###
###
###
###
###
###
###
###
###
###
###############
###############
This lab must be AutoLab submitted to the instructor by 11:59pm on the Monday a week after it was assigned. Check AutoLab for the specific due date.