드라이버 프로그램을 작성하면 사용자가 원의 사양을 입력하라는 메시지를 표시하고 원 객체를 생성 한 다음 원의 영역을 출력합니다. 프로그램에서 circle 클래스가 던진 IllegalDimesnsionException
오류를 적절히 처리해야합니다.throw 된 예외 오류를 사용하여 사용자에게 묻는 드라이버 프로그램 만들기
import java.util.Scanner;
//A = C2/4π
public class Driver {
public static void main(String[] args) {
String know;
// area of a circle
int Circumference;
int Diameter;
int Radius;
// pie of a circle
double pie;
double area;
// ask user for input
Scanner scanner = new Scanner(System.in);
System.out
.println("Do you know the Diameter, Circumference or the Radius of the circle?");
know = scanner.nextLine();
if (know.equals("Diameter")) {
System.out.println("What is the Diameter of the circle??");
Diameter = scanner.nextInt();
// Get area A = (π/4) × D2
pie = 3.14;
area = (pie/4) * (Diameter^2);
System.out.println("The area of the circle is: " + area);
}
if (know.equals("Radius")) {
System.out.println("What is the radius of the circle??");
Radius = scanner.nextInt();
// Get area A = π × r2
pie = 3.14;
area = pie * (Radius^2);
System.out.println("The area of the circle is: " + area);
}
if (know.equals("Circumference")) {
System.out.println("What is the circumference of the circle??");
Circumference = scanner.nextInt();
// Get area
pie = 3.14;
area = (Circumference^2)/4 * pie;
System.out.println("The area of the circle is: " + area);
}
}
}
난 그냥 예외 오류를 처리 할 수있는 프로그램을하는 데 도움이 필요 :
그래서 이것은 내가 지금까지있는 것입니다. 프로그램을 더 잘 만들기위한 다른 조언.
우리는 숙제를하고 있습니까? –
... [숙제 질문은 공식적으로 권장되지 않습니다] (http://meta.stackexchange.com/questions/147100/the-homework-tag-is-now-official-deprecated) – Augusto
@Augusto - 숙제 태그! = 숙제에 관한 질문. –