Please help. I need to create a java class consisting of static methods that can
ID: 3632656 • Letter: P
Question
Please help. I need to create a java class consisting of static methods that can draw various shapes in the console. The methods should employ nested loops and output statements that print single characters. In addition, create a main method that prompts the user as follows:Sample output:
What kind of shape would you like to see?
1. solid square
2. hollow square
3. solid triangle
4. solid rectangle
5. hollow rectangle
6. solid diamond
Your choice (Or enter 0 to quit): 5
You chose a hollow rectangle.
Enter dimensions.
Length: 4
Width: 5
Enter a single character to draw with: *
*****
* *
* *
*****
A RECTANGLE
Press any key to continue ...
THANK YOU!
Explanation / Answer
The concept of static method will get more clear after this program. First of all create a class HowToAccessStaticMethod. Now define two variables in it, one is instance variable and other is class variable. Make one static method named staticMethod() and second named as nonStaticMethod(). Now try to call both the method without constructing a object of the class. You will find that only static method can be called this way. The code of the program is given below: public class HowToAccessStaticMethod{ int i; static int j; public static void staticMethod(){ System.out.println("you can access a static method this way"); } public void nonStaticMethod(){ i=100; j=1000; System.out.println("Don't try to access a non static method"); } public static void main(String[] args) { //i=100; j=1000; //nonStaticMethod(); staticMethod(); } } Output of the program is given below: C:java>java HowToAccessStaticMethod you can access a static method this way