Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help please!!

 
Nancy Bradley
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This program is suppose to calculate area and perimeter of a rectangle and an applet to test it.
When I run the program I can input the length and width, but the computer does not do any calculations
I can not figure it out
Thank you for your help and time
Nancy B
 
Nancy Bradley
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I forgot to type the code.
This is the Rectangle class
and here is the applet
[ edited to alleviate need to scroll left-right -ds ]
[ April 08, 2004: Message edited by: Dirk Schreckmann ]
 
Ashok C. Mohan
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here the x and y are local to the methods,setting those values will not have any effect in mainx and mainy.try setting the mainx and mainy values instead of x and y in the setter methods....
 
Amit Ghai
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have done a small mistake.
in your setLength you are assigning value to x and y
change that to mainX and mainY. Then your program will display wt u want.
public void setLength(float x) // set length
{
mainX = ((x >= 1 & x < 20) ? x : 1); // range validation
}
public void setWidth(float y) // set width
{
mainY = ((y >= 1 & y < 20) ? y : 1); // range validation
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic