Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic

Static Methods Problem

 
Adam Favel
Greenhorn
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;

if(strDescription.equalsIgnoreCase=='P'){
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);


if(ch.equalsIgnoreCase=='p'){
choice = getValidInt(); // for height
choice = getValidInt(); //for width
}

else if (ch.equalsIgnoreCase=='t'){
choice = getValidInt();}
else if (ch.equalsIgnoreCase=='q'){
System.exit(0);
else
System.out.println("Invalid Input, Try Again");
}
}
 
Stephen Huey
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
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Report post to moderator
but, i have to solve this problem using static methods...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't crosspost. Continue discussion here: http://www.coderanch.com/t/398878/java/java/Static-Methods

Closing this thread...
 
    Bookmark Topic Watch Topic
  • New Topic