Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Name: Method practice - The frustum of a cone
- * @author LinChuWen
- * Date: 2014.10.22
- *
- * NCHU EE,course number:2335
- * course name: Object Oriented Language
- * Textbook: Big Java:Late Objects-Cay S. Horstmann
- * Problem: P5.34
- * Description: Compute the volume and surface area of the frustum of a cone.
- */
- import java.util.*;
- import java.lang.Math;
- public class HW4_P5_34 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("Please enter \"first radius\" (R1): ");
- double R1 = input.nextDouble();
- System.out.print("Please enter \"second radius\" (R2): ");
- double R2 = input.nextDouble();
- System.out.print("Please enter \"height\" (h): ");
- double h = input.nextDouble();
- System.out.println("volume = " + volume(R1,R2,h));
- System.out.println("surface area = " + surfaceArea(R1,R2,h));
- input.close();
- } //main end
- private static double volume( double R1,double R2,double h){
- double volume = (1.0/3) * Math.PI * h * (R1*R1 + R2*R2 + R1*R2);
- return volume;
- } //voulme() end
- private static double surfaceArea( double R1,double R2,double h){
- double surfaceArea = Math.PI * ((R1+R2) * Math.sqrt(Math.pow(R2-R1, 2) + h*h) + R1*R1);
- return surfaceArea;
- } //surfaceArea() end
- } //class end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement