Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

i WILL GIVE A GOOD REVIEW: IF YOU FOLLOW EVERY INDICATION AND THE OUTPUT COMES OUT EXACTLY AS IT SHOULD BELOW. CSCI 161 - Lab

i WILL GIVE A GOOD REVIEW: IF YOU FOLLOW EVERY INDICATION AND THE OUTPUT COMES OUT EXACTLY AS IT SHOULD BELOW.

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:

Character to use to represent a fence post

Character to use to represent wire between horizontal fence sections

Character to use to represent wire between vertical fence sections

Number of horizontal sections of the fence

Number of vertical sections of the fence

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:

Using Eclipse create a new Java Project and name it: Lab5

As with all your labs and assignments, add a class of the same name, Lab5, and include in that class a main method.

Your program must read a file according to the "Input Specification" below.

Your program must employ, among possible others, the methods described in the Required Methods section below.

Your program must output according to the "Output Specification" below.

Iteratively develop the assignment (get the original version working, test it, add code to one method, test, fix if needed, continue).

When the assignment is complete and working submit it as Lab6

Required Methods

Following are a list of methods to write:

 // 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) // 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 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 height of the fenced area. public static printVerticals(char post, char vWire, int width, int height) 

Notes:

As us customary with a fence, the corners of your fenced in area will have fence posts (not wire).

Sections of the fence with start and end with a fence post and have a single wire "character" between, regardless if a horizontal or a vertical section.

Make sure that the getInt method only returns positive integers.

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 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions