class and application - question about switch case and loop

Hi there! I am working on a project for class and I was wondeirng if someone might could look at my loop below and my switch case. I think I might have my loop in the wrong place because i have to have the original JOptionPane box pop up after each one in the actual swtich case, if that makes sense. That is not working and as I said I believe it is because I have the loop in the wrong place and also inside my switch case for exampe on case 3 the user must enter in the length of the reactangle, but when i enter that number in JOptionPane the next dialog box is not popping up. Does that have to do with the loop, or do I something written wrong inside that case? I am not to sure what to change or add, any ideas? Below is my class first and then my actually app. I put it all on here so that you knew what I was trying to do, if anything didnt make sense at all just let me know and I will explain better. I apprecaite it.

App:

//

// application using the Rectangle class

// demonstrate the use of the class with this app

import javax.swing.*;

publicclass RectangleApp

{

publicstaticvoid main( String[] arg )

{

int length = 0;

int l = 0;

int breadth = 0;

int b = 0;

int area = 0;

int perimeter = 0;

int input;

finalint SENT = 0;

//declaring a Rectangle object

Rectangle rect;

//initialize the object

rect =new Rectangle( );

//dialog box with options 0-7 to enter in rectangle attributes

input = Integer.parseInt( JOptionPane.showInputDialog(

"Please enter one of the following:\n"

+"1 - to set the length\n"

+"2 - to set the breadth\n"

+"3 - to get the length\n"

+"4 - to get the breadth\n"

+"5 - to get the perimeter\n"

+"6 - to get the area\n"

+"7 - to print the object as string\n"

+"0 - to quit\n" ) );

//loop that ends when user enters 0

while ( input != 0 )

{

switch ( input )

{

case 0:

System.exit(0);

break;

case 1: rect.setlength( l );

JOptionPane.showMessageDialog( null,

"The length is set at " + length );

break;

case 2: rect.setbreadth( b );

JOptionPane.showMessageDialog( null,

"The breadth is set at " + breadth );

break;

case 3: length = Integer.parseInt(

"Please enter the length of the Rectangle:");

break;

case 4:breadth = Integer.parseInt(

"Please enter the breadth of the Rectangle:");

break;

case 5: JOptionPane.showMessageDialog( null,

"The perimeter of the Rectangle is " + perimeter +"." );

break;

case 6: JOptionPane.showMessageDialog( null,

"The area of the Rectangle is " + area +"." );

break;

case 7: JOptionPane.showMessageDialog( null,

rect );

break;

}

}

}

}

Class:

//

// class to store information

// about a rectangle

publicclass Rectangle

{

//attributes

privateint length;

privateint breadth;

int area = 0;

int perimeter = 0;

//default constructor - overriding default constructor

public Rectangle()

{

length = 0;

breadth = 0;

}

//overload the constructor

public Rectangle(int l,int b )

{

setlength( l );

setbreadth( b );

}

//accessor methods or selector methods

publicint getlength( )

{

return length;

}

publicint getbreadth( )

{

return breadth;

}

publicint getarea(int b,int l )

{

area = l * b;

return area;

}

publicint getperimeter(int b,int l )

{

perimeter = ( l * 2 ) + ( b * 2 );

return perimeter;

}

publicint setlength(int l )

{

length = l;

return l;

}

publicint setbreadth(int b )

{

breadth = b;

return b;

}

public String toString( )

{

return"The Rectangle has a length of " + length +" and a breadth of " + breadth +".";

}

}

[8229 byte] By [CLab999] at [2007-9-30 22:28:00]
# 1

Integer.parseInt( "Please enter the length of the Rectangle:");

Integer.parseInt DOES NOT show a dialog box or a prompt. It simply tries to convert a string into an int. If it can't convert the string, it throws a NumberFormatException.

The usage pattern for Integer.parseInt is:

String s = "1234";

int n = Integer.parseInt (s); // n receives 1234

edsonw at 2007-7-7 12:51:13 > top of Java-index,Security,Event Handling...
# 2

Yes I just saw that right before I read your reply...that was a dumb mistake :)

Now everything works the way I want except for the area and perimeter display, but I think that might be something that needs to be changed in the the case where i say display "area" but ill see. Is that right?

CLab999 at 2007-7-7 12:51:13 > top of Java-index,Security,Event Handling...