CSCI 161 - Lab #5: Don't Fence Me In!

Objectives

Write a program that outputs to the screen a rectangular fence built from instructions supplied by the user including:

For Example:
If the user enters o, - and | for the fence post, horizontal wire and vertical wire, respectfully, and a fence horizontal width of 5 and vertical height of 2, then the following fenced area should be output:


o-o-o-o-o-o
|         |
o         o
|         |
o-o-o-o-o-o

Instructions

Following are the instructions and you should follow them carefully:

  1. Using Eclipse create a new Java Project and name it: Lab5
  2. As with all your labs and assignments, add a class of the same name, Lab5, and include in that class a main method.
  3. Your program must read input from the user according to the "Input Specification" below.
  4. Your program must employ, among possible others, the methods described in the Required Methods section below.
  5. Your program must output according to the "Output Specification" below.
  6. Iteratively develop the assignment (get the original version working, test it, add code to one method, test, fix if needed, continue).
  7. When the lab is complete and working submit your Lab5.java file via AutoLab.

Required Methods

In addition to the main method, following are a list of methods to write using the method names, return types and parameters given (exactly):

        
// Prompts for a character entry given the prompt string
// provided then returns single character entered by the
// user via the console object.
public static char getChar(Scanner console, String prompt)

// Prompts for a positive integer entry given the prompt string
// provided then returns the positive integer entered by the
// user via the console object.
public static int getInt(Scanner console, String prompt)

// Prints the text "Output:" and a new line.
public static void printOutput())

// Given the post and horizontal wire characters, this 
// method uses a for loop to print out the horizontal
// section of the fence given its width. Call this once for
// the top of the fence, and a 2nd time for the bottom of the
// fence.
public static void printHorizontal(char post, char hWire, int width)

// Given the post and vertical wire characters, this method
// uses 2 nested for loops to print out the vertical
// sections of the fence. Each vertical section includes the
// the left and right sides which must alternate between vertical
// wire characters and post characters along with spaces in
// between for the appropriate width of the fenced area.
public static void printVerticals(char post, char vWire, int width, int height)
        
        
Notes:

Input Specification

Your program must read user input from the console as shown below in the output specification dialogue with the user. In total, the user is asked for the post character, the horizontal wire character, the vertical wire character, the width of the fence, and the height of the fence.

Your program should output precisely according to the format below (wording, spacing, etc).

            
Please enter a single character to represent a fence post:  o
Please enter a single character to represent the horizontal fence wire:  -
Please enter a single character to represent the vertical fence wire:  |
Please enter the # of sections in the width of the fence:  5
Please enter the # of sections in the height of the fence:  2

Output:
o-o-o-o-o-o
|         |
o         o
|         |
o-o-o-o-o-o
        
        

Deadline

This assignment must be submitted to the instructor by 11:59:59pm on Monday, October 16th.