The class I just made is as follows:
package rectangle;
public class Rectangle {
private double length,width;
public void setLength(double length) {
this.length=length;
}
public void setWidth(double width) {
this.width=width;
}
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
public double area() {
return length*width;
}
}
It is in the package rectangle. I understand now that I am supposed to import the class when I am going to use it outside a package that it is in. So:
/*Testing out the rectangle class*/
package rectangleclasstest;
import java.util.Scanner;
import rectangle.Rectangle; //Here I try to import the class
public class RectangleClassTest {
static void main(String[] args)
{
Scanner keyboard= new Scanner(System.in);
Rectangle rec=new Rectangle();
//get length
System.out.println("Please enter the length");
rec.setLength(keyboard.nextInt());
}
}
I am now having trouble because the program is telling me that the package rectangle does not exist. Why would it be saying this? I am using Netbeans.