Advertisements

java program to find work done by body and to calculate kinetic and potential energy

import java.util.Scanner;
class work
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("If you want to find out work in terms of displacement on ground choose1 If you want to find out work  in terms of gravitychoose 2 If you want to find out kinetic energy choose3 If you want to find potential energy choose 4.");
int ch=sc.nextInt();
if (ch==1)
{
System.out.println("Enter the force applied in newton");
double f=sc.nextDouble();
System.out.println("Enter the displacement in meter");
double d=sc.nextDouble();
System.out.println("Enter the time taken in second");
Double t=sc.nextDouble();
double w=(f*d);
System.out.println("The work done by the force="+w+"J");
double p=(w/t);
System.out.println("The power spent="+p+"w");
}
else if(ch==2)
{
System.out.println("Enter the mass in kg");
double m=sc.nextDouble();
System.out.println("Enter the accleration due to gravity in m/s*s");
double a =sc.nextDouble();
System.out.println("Enter the height in meter");
double h=sc.nextDouble();
System.out.println("Enter the time in second");
double s=sc.nextDouble();
double x=(m*a*h);
System.out.println("Work done ="+x+"J");
double y=(x/s);
System.out.println("Power ="+y+"w");
}
else if(ch==3)
{
System.out.println("Enter the mass in Kg");
double kg=sc.nextDouble();
System.out.println("Enter the velocity in m/s");
double v=sc.nextDouble();
double b=(0.5*kg*v*v);
System.out.println("The kinetic energy="+b+"J");
}
else if(ch==4)
{
System.out.println("Enter the mass in Kg");
double c=sc.nextDouble();
System.out.println(" Enter accleration in m/s*s ");
double d=sc.nextDouble();
System.out.println("Enter the height in meter");
double e=sc.nextDouble();
double f=(c*d*e);
System.out.println("The potential energy ="+f+"J");
}
else
System.out.println("Wrong choice");
}
}