0

Hey everyone. I am new to java and I am stuck in this program. I am getting error messages and cannot figure out why. On public class Rectangle I am getting error messages on lines 84, and 85. On RectangleTest line 12. Thank you all in advance for and guidance or light you can shed on my issues!

//
public class Rectangle
{
 
 int lenght; // lenght of rectangle
 int width; // width of rectangle
 
 
 // two arg constructor
 public Rectangle( int l, int w )
 {
  lenght = l;// initialize length
  width = w;// initialize width
  
 }// end constructor
 
 //method to set Lenght
 public void setLenght( int l )
 {
  
  lenght = l;
  
 }
 
 //Method to retrieve Lenght
 public int getLenght()
 {
  return lenght;
   
 }
 
  //method to set Width
 public void setWidth( int w )
 {
  
  width = w;
  
 }
 
 //Method to retrieve Width
 public int getWidth()
 {
  return width;
   
 }
 
 
 public void validate( int l, int w)
 {
  
  lenght = ( ( l >= 0 && l < 20) ? l : 1);// validate lenght
  width = ( ( w >= 0 && w < 20) ? w : 1);// validate lenght
  
   
 }
 
 // finds the perimeter
 public double perimeter( int l, int w )
 {
  // initializes and finds value for perimeter
  int perimeter = (l+w) * 2;
  // returns value of perimeter  
  return perimeter;
 }
 
 //finds the area of the rectangle
 public double area( int l, int w )
 {
  //initializes area and finds the value
  int area = ( l * w);
  // returns area
  return area;
   
  
 }
 
 //outputs final math
 public void processRectangle()
 {
  // this prints out the results..
  // perimeter() and area() not working??
  System.out.printf( "\n%s %d\n%s %d\n\n", 
  " The perimeter of the rectangle is: ", perimeter( int l, int w ), 
  " The area of the rectangle is: ", area( int l, int w )  );
  
  
  
 }
 
 
 
 
 
}
//
import java.util.Scanner;
public class RectangleTest
{
 public static void main ( String[] args )
 {
  //Scanner for input
  Scanner input = new Scanner( System.in );
  
  Rectangle myRectangle = new Rectangle( int l, int w );
  
  
  
  //inputs lenght
  System.out.println( " Please enter the lenght: ");
  int lenght = input.nextLine();
  System.out.println();
  
  //inputs width
  System.out.println( " Please enter the width: ");
  int width = input.nextLine();
  System.out.println();
  
  
  
  
 }
 
 
 
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by masijade
0

You include the parameter types (i.e. method(int a, int b)) when you declare a method, not when you call it. When you call it you simply provide values (or variables referencing values) i.e.

public int someMethod(int a, int b) {
  // do something
}
.....
int someInt = 2;
int anotherInt = 3;
int answerOne = someMethod(someInt, anotherInt);
int answerTwo = someMethod(1, 2);
// or any combination thereOf
...
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.