File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Static Methods Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic

Static Methods Problem

Adam Favel

Joined: Feb 09, 2005
Posts: 22
Hey, I'm trying to make a program that has four static methods (including main) that will ask if the person wants to make a parallelogram, a triangle, or quit the program (in the main method). Then its supposed to go to another method to ask for the dimensions (height and width for Parallelogram and just Height for Triangle). There is a certain range of numbers it has to be in-between (in the form of iLowerBound and iUpperBound), and the method has to close after three unsuccessful attempts. Then its either supposed to go to a parallelogram method to draw the parallelogram with those dimensions from the other method, with stars (*), or it will go to the triangle method and draw the triangle with dimensions from the previous method, with random chars.

I am having problems with the getValidInt method (Seen Below) where I can't figure out how to transfer the number range (Parallelogram height (1-40), width (1-60) and Triangle Height (1-30)) into this method. And i am not sure how to set the 3 tries and exit thing either.

Can Anyone Help Me Out?

import javax.swing.*;

public class a3q1{

public static int getValidInt(int iLowerBound, int iUpperBound, String strDescription){
String str;
int PHeight;
int PWidth;
int THeight;
int i;
boolean ThreeTry == true;

str = JOptionPane.showInputDialog("Enter a Height between"+iLowerBound+"and"+iUpperBound);
PHeight = Integer.parseInt(str);

str = JOptionPane.showInputDialog("Enter a Width between"+iLowerBound+"and"+iUpperBound);
PWidth = Integer.parseInt(str);

return PHeight;
return PWidth;

if(strDescription.equalsIgnoreCase == 't'){
str = JOptionPane.showInputDialog("Enter a Height between"+iLowerBound+"and"+iUpperBound);

return THeight;

public static void drawParallelogram(int iHeight, int iWidth) {


public static void drawTriangle(int iHeight, char chFillCharacter) {


public static void main (String []args){
String str;
char ch;
int choice;

str = JOptionPane.showInputDialog("Enter P for Parallelogram, T for Triangle, or Q to Quit.");
ch = str.charAt(0);

choice = getValidInt(); // for height
choice = getValidInt(); //for width

else if (ch.equalsIgnoreCase=='t'){
choice = getValidInt();}
else if (ch.equalsIgnoreCase=='q'){
System.out.println("Invalid Input, Try Again");
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
You don't need to make the methods static, by the way. If you're not sure what that means, then they probably shouldn't be static.

Now, about the problem you mentioned...take a look at your method:

When you call that, it should look like this:

You keep calling it with no parameters even though you declared that it has 3 parameters!
Adam Favel

Joined: Feb 09, 2005
Posts: 22
but, i have to solve this problem using static methods...
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Please don't crosspost. Continue discussion here:

Closing this thread...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: Static Methods Problem
It's not a secret anymore!