CSCI 161 - Lab 8: Flip

Objectives

The objectives of this lab are to reinforce and help teach:

Overview

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.

Instructions

Following are the instructions and you should follow them carefully:

  1. Using Eclipse create a new Java Project and name it: Lab8
  2. As with all your labs and assignments, add a class of the same name, Lab8, and include in that class a main method.
  3. Think about how to deconstruct the problem. Your program must literally do the following tasks, in the following order (see the "Specification" below):
    • read the letter from the file and store in multidimensional array
    • print the letter
    • flip the letter
    • print the flipped letter (hey, we already know how to print the letter)
    Given the above steps you should already be thinking that you need three methods: IMPORTANT: If done properly, your main method has 5 statements: one that declares and initializes your file scanner class, another to read the file into and return the multi-dimensional array (aka a statement that has a method call with an assignment), a third that prints the letter given the array, a fourth that flips the content of the array passed to it, and lastly, a repeated call to the method that prints the array.
  4. Your program must read a file according to the "Input Specification" below.
  5. Your program must output according to the "Output Specification" below.
  6. Iteratively develop the assignment, get the file reading working, get the letter printing working, etc.
  7. When the lab is complete and working submit your Lab8.java file via AutoLab.

Input Specification

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).

Specification

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.

Output Specification

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:

        
###############
###############
      ###      
      ###      
      ###      
      ###      
      ###      

      ###      
      ###      
      ###      
      ###      
      ###      
###############
###############

 

Deadline

This lab be submitted to the instructor by 11:59pm on Monday, November 13th.