
Write an application program that will draw a hollow box (a box with empty space in between). The program will ask the user to key in a whole number larger or equals to 5. An error message would appear if the user keys in a number less than 5. The program should only exit if the user chooses to exit. For example, if the user keys in 8, the hollow box (of length and width of 8 characters) should be as follows :
88888888 88888888 88 88 88 88 88 88 88 88 88888888 88888888
The walls of the box are fixed at 2 layers. Hence, another example, if the user keys in 7, the hollow box (of length and width of 7 characters) should be as follows :
7777777 7777777 77 77 77 77 77 77 7777777 7777777
Provide a tester class to test the implementation of your solution. Writing the entire program in a single Class is not allowed.

Hello Friend,
Try this:
import java.util.*;
class Box{
public void check(Scanner input,int key){
if(key<5){
System.out.println("Error!Enter another key (>=5): ");
key=input.nextInt();
}
for(int i=1;i<=2;i++){
for(int j=1;j<=key;j++){
System.out.print(key);
}
System.out.print(" ");
}
int n=key-4;
int c=n*2;
for(int i=1;i<=c;i++){
for(int j=1;j<=2;j++){
System.out.print(key);
}
System.out.print(" ");
}
for(int i=1;i<=2;i++){
for(int j=1;j<=key;j++){
System.out.print(key);
}
System.out.print(" ");
}
}
}
public class HollowBox{
public static void main(String[] args){
Box b=new Box();
Scanner input=new Scanner(System.in);
int menu = 0;
System.out.println("Choose Option");
System.out.println("1. Draw");
System.out.println("2. Exit");
boolean quit = false;
do{
System.out.println();
System.out.print("Please enter your choice: ");
menu = input.nextInt();
System.out.println();
switch(menu) {
case 1:
System.out.println("Enter key (>=5): ");
int key=input.nextInt();
b.check(input,key);
break;
case 2:
quit = true;
break;
}
}
while (!quit);
}
}
Thanks

thx so much buddy.... so helpfull ^^
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.