Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

Static Methods Problem

Posts: 22
  • Mark post as helpful
  • send pies
  • Report post to moderator
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");
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Report post to moderator
but, i have to solve this problem using static methods...
Posts: 14112
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't crosspost. Continue discussion here:

Closing this thread...
Goodbye moon men. Hello tiny ad:
Enterprise-grade Excel API for Java
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!