packagecom.croute.hw_1_1;

 

importjava.util.Scanner;

 

public class HW_1_1 {

 

        /**

         *@param args

         */

        public static voidmain(String[] args) {

               // TODOAuto-generated method stub

               intinput = 0;        

               doublemass = 0;

               doublevelocity = 0;

               doublekinetic_energy = 0;

              

               while( input != 9 ) {

                       System.out.println("움직이는물체의운동에너지를구하는프로그램입니다.");

                       System.out.println("1. 물체의속도입력");

                       System.out.println("2. 물체의질량입력");

                       System.out.println("3. 운동에너지구하기");

                       System.out.println("9. 프로그램종료");

                       System.out.print("번호를입력하세요: ");                     

                       Scanner scn = new Scanner(System.in);

                       input = scn.nextInt();

                      

                       switch( input )

                       {

                              case 1 :

                                      System.out.print("속도를입력하세요: ");

                                      ScannerscnV = new Scanner(System.in);

                                      velocity =scnV.nextDouble();

                                      System.out.print("입력속도: " + velocity);

                                      System.out.println("");

                                      break;

                              case 2 :

                                      System.out.print("질량을입력하세요: ");

                                      ScannerscnM = new Scanner(System.in);

                                      mass =scnM.nextDouble();

                                      System.out.print("입력질량: " + mass);

                                      System.out.println("");

                                      break;

                              case 3 :

                                      if ( mass == 0 || velocity == 0) {

                                      System.out.println("정확하게입력하세요.");                                            

                                      }

                                      else {

                                             kinetic_energy= get_kineticEnergy(mass, velocity);                                       

                                             System.out.println("질량: " + mass + ", 속도: " + velocity);

                                             System.out.println("운동에너지를구합니다.");

                                             System.out.println("운동에너지: " + kinetic_energy);                                      

                                      }

                                      break;

                              case 9 :

                                      System.out.println("");

                                      System.out.println("프로그램을종료합니다.");

                                      break;

                              default :

                                     

                                      break;

                      

                       }

                       System.out.println("");      

                       System.out.println("");

               }

              

              

        }

 

        public static doubleget_kineticEnergy(double m, double v){

               doubleresult = 0.0;

               doubleintegral_calculus = 0.5;             

               result = integral_calculus * m *( v * v );         

               returnresult;

        }      

}

 

Posted by croute

댓글을 달아 주세요