Create a code that accepts inputs for dimensions of a rectangularprism that has
ID: 3614301 • Letter: C
Question
Create a code that accepts inputs for dimensions of a rectangularprism that has 2 end and 4 sides. Opposite sides have the samearea.After the programs accepts inputs of dimensions:
-Indicate if length,width,and height are equal-call it a cube
-Indicate if height is twice greater than either length orwidth-call it a long prism
-Otherwise,call it a regular prism
Then calculate the surface area and volume of the prism as shownbelow:
Surface area of Rectangular Prism is calculated as follows:
-Find the area of two side(length*height)* 2 sides
-Find the area of adjacent sides(width*height)*2 sides
-Find the area of ends(length*width)*2 sides
-Add the three areas together to find the surface area
-Example: The surface area of a rectangular prism 5 cm long, 3 cm.wide and 2 cm.
high = 5*2*2+3*2*2+5*3*3=20+12+30=62 cm2
Volume of a rectangular prism can be found by theformula:
volume = length*width*height
Explanation / Answer
Hope this is what you are looking for:) import java.util.*; public class RectangularPrism { Scanner scanner = new Scanner(System.in); int length, width, height; public static void main(String[]args) { RectangularPrism rp = newRectangularPrism(); rp.run(); } public void run() { System.out.println("Rectangular Prism dimensions..."); System.out.print(" Length(cm): "); length =scanner.nextInt(); System.out.print(" Width(cm): "); width =scanner.nextInt(); System.out.print(" Height(cm): "); height =scanner.nextInt(); if(length == width) { if(width== height) { System.out.println(" This is acube."); cube(length, width, height); } elseif(height == length*length && height ==width*width) { System.out.println(" This is a longprism."); prism(length, width, height); } } else { System.out.println(" This is a regular prism"); prism(length, width, height); } } public void cube(int length, int width, intheight) { int cubeArea =length*width; int cubeVol =length*width*height; int cubeSurf =6*cubeArea; System.out.println("Cube Area= "+cubeArea); System.out.println("CubeVolume = "+cubeVol); System.out.println("CubeSurface Area = "+cubeSurf); } public void prism(int length, int width, intheight) { int sides2 =(length*height)*2; int sidesAdj =(width*height)*2; int areaEnd =(length*width)*2; int surfArea = sides2 +sidesAdj + areaEnd; int volume =length*width*height; System.out.println("Prismsurface area: "+ surfArea); System.out.println("Prismvolume: "+ volume); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.