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
Following are the instructions and you should follow them carefully:
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:
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
char post = getChar(console, "Please enter a single character to represent a fence post: ");
char hWire = getChar(console, "Please enter a single character to represent the horizontal fence wire: ");
char vWire = getChar(console, "Please enter a single character to represent the vertical fence wire: ");
int width = getInt(console, "Please enter the # of sections in the width of the fence: ");
int height = getInt(console, "Please enter the # of sections in the height of the fence: ");
printOutput();
printHorizontal(post, hWire, width);
printVerticals(post, vWire, width, height);
printHorizontal(post, hWire, width);
}
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
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.