This is the code I made to attempt to calculate the perimeter and area of a rectangle.
public class Rectangle
{
public static void main (String [ ] args)
private double side1;
private double side2;
new Rectangle( )
{
This is where I get the first error
side1 = 1;
side2 = 1;
}
public Rectangle (double s1, double s2)
{
side1 = s1;
side2 = s2;
}
public double computePerimeter()
{
double perimeter;
perimeter = (side1 * 2) + (side2 *2);
return perimeter;
}
public double computeArea()
{
double area;
area = side1 * side2;
return area;
}
public double getSide1()
{
return side1;
}
public double getSide2()
{
return side2;
}
public void setSides(int firstSide, int secondSide)
{
side1 = firstSide;
side2 = secondSide;
}
public String toString()
{
System.out.println("Area is " + area);
System.out.println("Perimeter is " + perimeter);
}
{
Scanner scan = new Scanner(System.in);
int sideOne = scan.nextInt();
side1 = sideOne;
int sideTwo = scan.nextInt();
side2 = sideTwo;
computePerimeter();
computeArea();
}
This is where I keep getting the other two errors
}
}
I keep getting this message, but after line 10 I have a { and after line 67 a }. I'm just pretty confused. "3 errors found:File: C:\Users\jrader\Desktop\GridWorldCode\projects\firstProject\Rectangle.java [line: 10] Error: Syntax error on token "{", { expected after this token [line: 67] Error: Syntax error, insert "}" to complete ClassBody [line: 67] Error: Syntax error, insert ";" to complete Statement"
This is a class definition so there is no main method, only constructors and method declarations. I realized my mistake.