Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TestRectangle.java
- public class TestRectangle {
- public static void main(String[] args) {
- Rectangle rectangle1 = new Rectangle();
- Rectangle rectangle2 = new Rectangle(4, 5.5);
- System.out.println("Width: " + rectangle1.width + "\nHeight: " + rectangle1.height + "\nArea: "
- + rectangle1.getArea() + "\nPerimeter: " + rectangle1.getPerimeter());
- System.out.println("Width: " + rectangle2.width + "\nHeight: " + rectangle2.height + "\nArea: "
- + rectangle2.getArea() + "\nPerimeter: " + rectangle2.getPerimeter());
- }
- }
- //Rectangle.java
- public class Rectangle {
- double width = 1;
- double height = 1;
- public Rectangle() {
- }
- public Rectangle(double height, double width) {
- this.width = width;
- this.height = height;
- }
- public double getArea() {
- return (width * height);
- }
- public double getPerimeter() {
- return (2 * (width + height));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement