Skip to content
loading...

re: FIXED: Troubles in Java please help, my teacher has been ignoring my questions for almost a week VIEW POST

FULL DISCUSSION
 

public class RectangleCW {
private double width;
private double height;

public RectangleCW() {
    width = 1f;
    height = 1f;
}

public RectangleCW(double height, double width) {
    this.height = height;
    this.width = width;
}

public double getArea() {
    return width * height;
}

public double getPerimeter() {
    return 2 * (height + width);
}

public double getWidth() {
    return width;
}

public void setWidth(double width) {
    this.width = width;
}

public double getHeight() {
    return height;
}

public void setHeight(double height) {
    this.height = height;
}

}

public class RectangleTestCW {
public static void main(String[] args) {

    RectangleCW r1 = new RectangleCW(4, 40);
    RectangleCW r2 = new RectangleCW(3.5, 35.9);

    System.out.println("The height for rectangle 1 is: " + r1.getHeight());
    System.out.println("The width for rectangle 1 is: " + r1.getWidth());
    System.out.println("The area for rectangle 1 is: " + r1.getArea());
    System.out.println("The perimeter for rectangle 1 is: " + r1.getPerimeter());

    System.out.println("The height for rectangle 2 is: " + r2.getHeight());
    System.out.println("The width for rectangle 2 is: " + r2.getWidth());
    System.out.println("The area for rectangle 2 is: " + r2.getArea());
    System.out.println("The perimeter for rectangle 2 is: " + r2.getPerimeter());
}

}

code of conduct - report abuse