Advertisement
Go-Ice

Sophomore Java Homework-P5.34

Oct 21st, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. /**
  2.  * Name: Method practice - The frustum of a cone
  3.  * @author LinChuWen
  4.  * Date: 2014.10.22
  5.  *
  6.  * NCHU EE,course number:2335
  7.  * course name: Object Oriented Language
  8.  * Textbook: Big Java:Late Objects-Cay S. Horstmann
  9.  * Problem: P5.34
  10.  * Description: Compute the volume and surface area of the frustum of a cone.
  11.  */
  12. import java.util.*;
  13. import java.lang.Math;
  14. public class HW4_P5_34 {
  15.    
  16.     public static void main(String[] args) {
  17.         Scanner input = new Scanner(System.in);
  18.        
  19.         System.out.print("Please enter \"first radius\" (R1): ");
  20.         double R1 = input.nextDouble();
  21.        
  22.         System.out.print("Please enter \"second radius\" (R2): ");
  23.         double R2 = input.nextDouble();
  24.        
  25.         System.out.print("Please enter \"height\" (h): ");
  26.         double h = input.nextDouble();
  27.        
  28.         System.out.println("volume = " + volume(R1,R2,h));
  29.         System.out.println("surface area = " + surfaceArea(R1,R2,h));
  30.        
  31.         input.close();
  32.     } //main end
  33.    
  34.     private static double volume( double R1,double R2,double h){
  35.         double volume = (1.0/3) * Math.PI * h * (R1*R1 + R2*R2 + R1*R2);
  36.         return volume;
  37.     } //voulme() end
  38.    
  39.     private static double surfaceArea( double R1,double R2,double h){
  40.         double surfaceArea = Math.PI * ((R1+R2) * Math.sqrt(Math.pow(R2-R1, 2) + h*h) + R1*R1);
  41.         return surfaceArea;
  42.     } //surfaceArea() end
  43.    
  44. } //class end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement