Question

In: Computer Science

The program will enquiry from the user a name and four decimal numbers: m, a, b...

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.

  • Use the Scanner class to accept input from the user.
  • Prompt the user for her/his name (i.e. “Ferdinand”).
  • Using her/his name, prompt the user for a value for mass in pounds and save it in a variable (m).
  • Prompt the user for a second value for an inner radius in inches and save it in another variable (a).
  • Prompt the user for a third value for an outer radius in inches and save it in another variable (b).
  • Prompt the user for a fourth value for a height in inches and save it in another variable (h).

·         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

  • b2 means b to the power of 2. There is no need to use an especial operation for exponentiation in the program. Remember that b2 is equivalent to the multiplicationof b by itself. Similarly b5 is equivalent to b multiplied 4 more times by b.
  • Print the results of your calculations. The output should look like the example shown below. If the output does not match, there is some problem with your code.
  • Students should not use Arrays, multiple methods, any other advanced concept that was not reviewed in the class to solve this assignment. Assignments that use these concepts will only be given 10% for presentation

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

Solutions

Expert Solution

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.


Related Solutions

In C++ Design and implement a program (name it ProcessGrades) that reads from the user four...
In C++ Design and implement a program (name it ProcessGrades) that reads from the user four integer values between 0 and 100, representing grades. The program then, on separate lines, prints out the entered grades followed by the highest grade, lowest grade, and averages of all four grades. Format the outputs following the sample runs below.
Using MatLab Write a program which will: a. Accept two numbers from the user m and...
Using MatLab Write a program which will: a. Accept two numbers from the user m and n b. Define an array with the dimensions a(n,m) and fill it with random numbers in the range of -100 to 100 inclusive. c. Accept from the user two row numbers. Multiply the two rows (element by element) and find the sum. Print the result. d. Accept from the user two column numbers. Add the two columns (element by element) and find the sum....
Develop a python program to convert two decimal numbers (A and B) to binary numbers. You...
Develop a python program to convert two decimal numbers (A and B) to binary numbers. You should generate B complement signal (flip all the bits of Input B,
Write an assembly language program that repeatedly prompts the user to enter signed decimal integer numbers....
Write an assembly language program that repeatedly prompts the user to enter signed decimal integer numbers. The program should be run from the command prompt, output a text prompt to the screen, and then wait for the user to type in a number followed by the Enter key. (The legitimate range of user input values is any signed integer that can be represented in 32 bits.) After each number is entered, the program should determine and display the following information...
Write a user-defined MATLAB function that converts real numbers in decimal form to binary form. Name...
Write a user-defined MATLAB function that converts real numbers in decimal form to binary form. Name the function b = deciTObina (d), where the input argument d is the number to be converted and the output argument b is a 30-element-long vector with 1s and 0s that represents the number in binary form. The first 15 elements of b store the digits to the left of the decimal point, and the last 15 elements of b store the digits to...
Write a program that will print the whole numbers from a user-specified minimum to a user-specified...
Write a program that will print the whole numbers from a user-specified minimum to a user-specified maximum. Display the total amount of numbers printed.
Write a C++ program that reads numbers from the user until the user enters a Sentinel....
Write a C++ program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: Output the sum of all even numbers Output the sum of all odd numbers Output the count of all even numbers Output the count of all odd numbers You must use loops and numbers to do this. You must not use any arrays or vectors for this program.
Write a C++ program that reads numbers from the user until the user enters a Sentinel....
Write a C++ program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input (other than the sentinel). Do the following: 1. Output the sum of all even numbers 2. Output the sum of all odd numbers 3. Output the count of all even numbers 4. Output the count of all odd numbers You must use alternation ('if' statements), loops and simple calculations to do...
Write a program that: a. Asks the user for their first name using a JOptionPane. b....
Write a program that: a. Asks the user for their first name using a JOptionPane. b. Asks the user for their age using a JOptionPane. C. Asks the user for their last name using a JOptionPane. d. Pops up a dialog with the following information: i. Number of characters in the first & last name combined ii. The full name all-in upper-case letters iii. The full name all-in lower-case letters iv. The first letter of the name v. The age...
(write a program that get the numbers from user and search the file numbers.text for that...
(write a program that get the numbers from user and search the file numbers.text for that value. in C++) numbers.txt: 10 23 43 5 12 23 9 8 10 1 16 9 you must to have the exact output: Enter a number: 10 10 last appears in the file at position 9 Enter a number: 29 29 does not appear in the file Enter a number: 9 9 last appears in the file at position 12 Enter a number:
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT