1.6.1.1 For Loop Assignment: Box This
You must use:
- nested for loops -- a for loop within a for loop
- multiple methods -- perhaps some of your methods may be: drawTopOfBox(), drawBottomOfBox() and drawSidesOfBox()
Box This Problem:
- prompt the user for the size of the box
- display a box in the console screen.
Details:
The box will be made up of *'s and will be the size the user enters in the program.
For example, if the user enters a 5, the box will look like this:
* * * * *
* *
* *
* *
* * * * *
the smallest box the program will draw is:
* *
* *
if a invalid size of box is entered, the user will receive a message stating the problem with the input
Modifications:
- prompt the user for a character for the box.
/**
* Use this framework to complete the Box This Assignment
*
* @author (Mr V)
* @version (April 2011)
*/
public class DrawBox
{
// instance variables
private String topOfBox;
private String sidesOfBox;
private String bottomOfBox;
private int sizeOfBox;
/**
* Constructor for objects of class DrawBox
*/
public DrawBox()
{
initializeAllSides();
sizeOfBox = 5;
drawBox();
}
/**
* initialize all sides
*/
public void initializeAllSides ()
{
// initialise all sides to null
topOfBox = "";
sidesOfBox = "";
bottomOfBox = "";
}
/**
* draw the box
*/
public void drawBox()
{
drawTopOfBox();
drawSidesOfBox();
drawBottomOfBox();
}
/**
* draw Top Of Box
*/
public void drawTopOfBox()
{
}
/**
* draw Sides Of Box
*/
public void drawSidesOfBox()
{
}
/**
* draw Bottom Of Box
*/
public void drawBottomOfBox()
{
drawTopOfBox();
}
}