I have two files. I tried coding a program where one file is my Rectangle class that finds and calculates area and perimeter, while the other file uses the Rectangle class and creates two objects. But I can't seem to get it to work. What's wrong with it?
"MyRectangleClassProgram"
"Rectangle"import Rectangle.pkg.Rectangle; public class MyRectangleClassProgram { public static void main(String args[]) { Rectangle = new rectangle1(); Rectangle = new rectangle1(); rectangle1.setLW(10.0); rectangle1.setLW(5.0); rectangle2.setLW(7.0); rectangle2.setLW(3.0); System.out.println("Perimeter of rectangle1 is "); System.out.println(rectangle1.calculatePerimeter()); System.out.println("\n"); System.out.println("Area of rectangle1 is "); System.out.println(rectangle1.calculateArea()); System.out.println("\n"); System.out.println("Perimeter of rectangle2 is "); System.out.println(rectangle2.calculatePerimeter()); System.out.println("\n"); System.out.println("Area of rectangle2 is "); System.out.println(rectangle2.calculateArea()); System.out.println("\n"); System.exit(0); } }
Here are my errors:class Rectangle { public double length, width; public double getLW(double len, double wid){ return length; return width; } public double setLW(double len, double wid){ length = len; width = wid; return; } public double calculateArea(){ return width * length; } public double calculatePerimeter(){ return 2 * (width + length); } }
MyRectangleClassProgram.java:1: error: package Rectangle.pkg does not exist import Rectangle.pkg.Rectangle; ^ MyRectangleClassProgram.java:7: error: cannot find symbol Rectangle = new rectangle1(); ^ symbol: variable Rectangle location: class MyRectangleClassProgram MyRectangleClassProgram.java:7: error: cannot find symbol Rectangle = new rectangle1(); ^ symbol: class rectangle1 location: class MyRectangleClassProgram MyRectangleClassProgram.java:8: error: cannot find symbol Rectangle = new rectangle1(); ^ symbol: variable Rectangle location: class MyRectangleClassProgram MyRectangleClassProgram.java:8: error: cannot find symbol Rectangle = new rectangle1(); ^ symbol: class rectangle1 location: class MyRectangleClassProgram MyRectangleClassProgram.java:10: error: cannot find symbol rectangle1.setLW(10.0); ^ symbol: variable rectangle1 location: class MyRectangleClassProgram MyRectangleClassProgram.java:11: error: cannot find symbol rectangle1.setLW(5.0); ^ symbol: variable rectangle1 location: class MyRectangleClassProgram MyRectangleClassProgram.java:12: error: cannot find symbol rectangle2.setLW(7.0); ^ symbol: variable rectangle2 location: class MyRectangleClassProgram MyRectangleClassProgram.java:13: error: cannot find symbol rectangle2.setLW(3.0); ^ symbol: variable rectangle2 location: class MyRectangleClassProgram MyRectangleClassProgram.java:17: error: cannot find symbol System.out.println(rectangle1.calculatePerimeter()); ^ symbol: variable rectangle1 location: class MyRectangleClassProgram MyRectangleClassProgram.java:20: error: cannot find symbol System.out.println(rectangle1.calculateArea()); ^ symbol: variable rectangle1 location: class MyRectangleClassProgram MyRectangleClassProgram.java:23: error: cannot find symbol System.out.println(rectangle2.calculatePerimeter()); ^ symbol: variable rectangle2 location: class MyRectangleClassProgram MyRectangleClassProgram.java:26: error: cannot find symbol System.out.println(rectangle2.calculateArea()); ^ symbol: variable rectangle2 location: class MyRectangleClassProgram Rectangle.java:14: error: incompatible types: missing return value return; ^ 14 errors Error: Could not find or load main class MyRectangleClassProgram