In: Computer Science
The program will enquiry from the user a name and four decimal numbers: m, a, b and h. With this information, the program will evaluate moments of inertia (a physical property) for various 3D objects and print them.
· The program will calculate the following moments of inertia for various 3D objects and save the results in variables to be printed later from these variables:
o Moment of Inertia of a rod with length a = ma2 / 12.0
o Moment of Inertia of a rectangular parallelepiped with sides a, b and h with axis in the plane that is parallel to h = m (4a2+b2 ) / 12.0
o Moment of Inertia of a circular cylinder with radius a and height h perpendicular to the cylindrical axis = m (h2+3a2 ) / 12.0
o Moment of Inertia of a hollowed circular cylinder with radii a and b, and height h about an axis on a diameter at one end = m (3a2+3b2 +4h2) / 12.0
o Moment of Inertia of a hollowed sphere with
radii a and b about its diameter =
2 m (a5-b5)/( a3-b3) /
5.0
o Moment of Inertia of a hollowed sphere with
radii a and b about an axis tangent to its surface =
2 m (a5-b5)/( a3-b3) /
5.0 + ma2
Example
INPUT
Hi! What is your name?: Ferdinand
Ferdinand, give me a number for the mass in pounds. We are going to
call it m:10
Ferdinand, give me a number for the inner radius. We are going to
call it a:1
now give me a number for the outer radiosu. We are going to call it
b:2
finally, give me a number for the height. We are going to call it
h:10
OUTPUT
Ferdinand, with these numbers we can obtain the following moments
of inertia:
Moment of Inertia of a rod with length 1.0 is
0.8333333333333334
Moment of Inertia of a rectangular parallelepiped with sides 1.0,
2.0, and 10.0 with axis in the plane that is parallel to h is
6.666666666666667
Moment of Inertia of a circular cylinder with radius 1.0, and
height 10.0 perpendicular to its cylindrical axis is
85.83333333333333
Moment of Inertia of a hollowed circular cylinder with radii 1.0
and 2.0, and length 10.0 about an axis on a diameter at one end
is
345.8333333333333
Moment of Inertia of a hollowed sphere with radii 1.0 and 2.0 about
its diameter is
17.714285714285715
Moment of Inertia of a hollowed sphere with radii 1.0 and 2.0 about
an axis tangent to its surface is
27.714285714285715
Code
import java.util.Scanner;
public class Inertia {
public static void main(String[] args)
{
double m,a,b,h;
Scanner sc=new Scanner(System.in);
double
MIofRod,MIOfRectangularParallelepiped,MIOfCylinder,MIOfHollowedCylinder,MIhollowedSphere,MIhollowedSphereAboutXAxis;
String name;
System.out.print("Hi! What is your name?:");
name=sc.next();
System.out.print(name+", give me a number for the mass in pounds.
We are going to call it m:");
m=sc.nextDouble();
System.out.print(name+", give me a number for the inner radius. We
are going to call it a:");
a=sc.nextDouble();
System.out.print("now give me a number for the outer radiosu. We
are going to call it b:");
b=sc.nextDouble();
System.out.print("finally, give me a number for the height. We are
going to call it h:");
h=sc.nextDouble();
MIofRod=(m*a*a)/12.0;
MIOfRectangularParallelepiped=m*(4*a*a+b*b ) / 12.0;
MIOfCylinder= m*(h*h+3*a*a ) / 12.0;
MIOfHollowedCylinder=m*(3*a*a+3*b*b +4*h*h) / 12.0;
MIhollowedSphere=(2*(m*((a*a*a*a*a)-(b*b*b*b*b))/((a*a*a)-(b*b*b)))/5.0);
MIhollowedSphereAboutXAxis=(2*(m*((a*a*a*a*a)-(b*b*b*b*b))/((a*a*a)-(b*b*b)))/5.0+((m)*(a*a)));
System.out.println(name+", with these numbers we can obtain the
following moments of inertia:");
System.out.println("Moment of Inertia of a rod with length "+a+"is
\n"+MIofRod);
System.out.println("Moment of Inertia of a rectangular
parallelepiped with sides "+a+", "+b+" and "+h+" with axis in the
plane that is parallel to h
is\n"+MIOfRectangularParallelepiped);
System.out.println("Moment of Inertia of a circular cylinder with
radius "+a+", and height "+h+" perpendicular to its cylindrical
axis is\n"+MIOfCylinder);
System.out.println("Moment of Inertia of a hollowed circular
cylinder with radii "+a+" and "+b+", and length "+h+" about an axis
on a diameter at one end is\n"+MIOfHollowedCylinder);
System.out.println("Moment of Inertia of a hollowed sphere with
radii "+a+" and "+b+" about its diameter
is\n"+MIhollowedSphere);
System.out.println("Moment of Inertia of a hollowed sphere with
radii "+a+" and "+b+" about an axis tangent to its surface
is\n"+MIhollowedSphereAboutXAxis);
}
}
output
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.