-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise09_01.java
More file actions
61 lines (48 loc) · 1.28 KB
/
Copy pathExercise09_01.java
File metadata and controls
61 lines (48 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author jorda
*/
public class Exercise09_01 {
public static void main(String[] args) {
Rectangle shape1 = new Rectangle(4, 40);
Rectangle shape2 = new Rectangle(3.5, 35.9);
System.out.println("Shape 1: \n" + shape1);
System.out.println("");
System.out.println("Shape 2: \n" + shape2);
}
}
class Rectangle {
double width;
double height;
public Rectangle() {
width = 1;
height = 1;
}
public Rectangle(double width, double height) {
this.width = width;
this.height = height;
}
public double getHeight(){
return height;
}
public double getWidth(){
return width;
}
public double getArea() {
return width * height;
}
public double getPerimeter() {
return 2*(width + height);
}
public String toString(){
return "Width: " + width + "\n" +
"Height: " + height + "\n" +
"Area: " + this.getArea() + "\n" +
"Perimeter: " + this.getPerimeter();
}
}