-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice0602.java
More file actions
73 lines (59 loc) · 1.72 KB
/
Copy pathpractice0602.java
File metadata and controls
73 lines (59 loc) · 1.72 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
62
63
64
65
66
67
68
69
70
71
72
import java.util.Scanner;
class Shape {
public static double calculateArea() {
return 0;
}
}
class Circle extends Shape {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
public static double calculateArea() {
double area = this.radius*this.radius;
return area;
}
}
class Rectangle extends Shape {
private double length;
private double width;
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
public static double calculateArea() {
double area = this.length*this.width;
return area;
}
}
class Triangle extends Shape {
private double base;
private double height;
public Triangle(double base, double height) {
this.base = base;
this.height = height;
}
public static double calculateArea() {
double area = (this.base*this.height)/2;
return area;
}
}
public class practice0602 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("intput r : ");
double r = sc.nextDouble();
System.out.println("intput l, w : ");
double l = sc.nextDouble();
double w = sc.nextDouble();
System.out.println("intput b, h : ");
double b = sc.nextDouble();
double h = sc.nextDouble();
Circle a = new Circle(r);
Rectangle b = new Rectangle(l, w);
Triangle c = new Triangle(b, h);
System.out.println("Circle area: " + a.calculateArea());
System.out.println("Rectangle area: " + b.calculateArea());
System.out.println("Triangle area: " + c.calculateArea());
}
}