Time Limit: 1s
Memory Limit: 128MB
GeometricObject 클래스를 상속받은 Triangle이라는 이름의 클래스를 만드시오. 이 클래스는 다음을 포함한다 :
toString() 메소드는 다음과 같이 구한한다 : return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3;
(The Triangle class) Design a class named Triangle that extends GeometricObject. The class contains:
The toString() method is implemented as follows: return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3;
* Line 1 : 테스트케이스 T (1~1,000)
* Line 2 ~ T+1 : side1 side2 side3 color filled
- side1, side2, side3 는 0~10사이의 실수
- color는 공백없이 길이가 50을 넘지 않는 문자열
- filled는 true 또는 false
Sample Output 형식으로 출력
숫자는 소숫점 둘째자리 까지 출력하시오. (DecimalFormat("##.00") 참고)
import java.text.DecimalFormat; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int t = 0; t < T; t++) { double side1 = sc.nextDouble(); double side2 = sc.nextDouble(); double side3 = sc.nextDouble(); GeometricObject triangle = new Triangle(side1, side2, side3); String color = sc.next(); triangle.setColor(color); boolean filled = sc.nextBoolean(); triangle.setFilled(filled); DecimalFormat df = new DecimalFormat("##.00"); System.out.println("The area is " + df.format(triangle.getArea())); System.out.println("The perimeter is " + df.format(triangle.getPerimeter())); System.out.println(triangle); } } } abstract class GeometricObject { private String color = "white"; private boolean filled; /** * Default construct */ protected GeometricObject() { } /** * Construct a geometric object */ protected GeometricObject(String color, boolean filled) { this.color = color; this.filled = filled; } /** * Getter method for color */ public String getColor() { return color; } /** * Setter method for color */ public void setColor(String color) { this.color = color; } /** * Getter method for filled. Since filled is boolean, * so, the get method name is isFilled */ public boolean isFilled() { return filled; } /** * Setter method for filled */ public void setFilled(boolean filled) { this.filled = filled; } /** * Abstract method findArea */ public abstract double getArea(); /** * Abstract method getPerimeter */ public abstract double getPerimeter(); } YOUR_CODE
5 5.22856359077 8.64369661889 7.81208777215 red false 4.73859498495 5.28984483026 6.43911724765 blue true 9.85370908953 7.66252345724 4.89050910369 orange true 6.28459944776 9.74426851916 4.98337330199 green false 7.63836147698 7.61050092554 7.24533208254 violet true
The area is 20.14 The perimeter is 21.68 Triangle: side1 = 5.23 side2 = 8.64 side3 = 7.81 The area is 12.33 The perimeter is 16.47 Triangle: side1 = 4.74 side2 = 5.29 side3 = 6.44 The area is 18.38 The perimeter is 22.41 Triangle: side1 = 9.85 side2 = 7.66 side3 = 4.89 The area is 13.66 The perimeter is 21.01 Triangle: side1 = 6.28 side2 = 9.74 side3 = 4.98 The area is 24.30 The perimeter is 22.49 Triangle: side1 = 7.64 side2 = 7.61 side3 = 7.25
JAVA2015 PE11.1