Question

Write a java program that computes the total surface area of a rectangular prism. There are...

Write a java program that computes the total surface area of a rectangular prism. There are six sides, so the area of all six sides has to the summed to get the total area. The program should ask the user to enter the length (L), width (W) and the height )H) for the object in inches. Create a separate method from the main to calculate the area (name the method calcArea). The output of calcArea will return a double. Output; The total area for the rectangular prisminches long, inches wide, and inches tall issquare inches. A must be formatted to two decimal places, using a printf statement.

Write a java program that computes the total surface area of a rectangular prism. There are six sides, so the area of all six sides has to the summed to get the total area. The program should ask the user to enter the length (L), width (W) and the height )H) for the object in inches. Create a separate method from the main to calculate the area (name the method calcArea). The output of calcArea will return a double. Output; The total area for the rectangular prisminches long, inches wide, and inches tall issquare inches. A must be formatted to two decimal places, using a printf statement.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code

  
import java.util.Scanner;
class ReatangularPrism {
private double length , width , height ;
private double area ;   
public ReatangularPrism(double length, double width, double height) {
this.length = length;
this.width = width;
this.height = height;
}
public double calcArea(){
System.out.printf(" long inches: %.2f", Double.valueOf(length) );
System.out.print("\n");
System.out.printf(" width inches: %.2f", Double.valueOf(width) );
System.out.print("\n");
System.out.printf(" tall balance : %.2f", Double.valueOf(height)); // this is for print value of 2 decimal according to you requirement
System.out.print("\n");
// formula to find the sufrace are aof rectangular prism prims it has size sides we are sum up as show below
area = (2 * (width * length)) +(2 * (length * height))+(2 * (length * width));
return area ;
}
}
public class Main1
{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in) ;
double length , width , height ;
System.out.println("Enter Length : ");
length = Double.valueOf(scan.nextLine());
System.out.println("Enter width : ");
width = Double.valueOf(scan.nextLine());
System.out.println("Enter height : ");
height = Double.valueOf(scan.nextLine());
ReatangularPrism rec = new ReatangularPrism(length , width , height);
double area = rec.calcArea();
System.out.printf("\nTotal Surface area is : %.2f", Double.valueOf(area));}}

code screenshot 1

package crap; import java.util.Scanner; class ReatangularPrism { private double length, width, height; private double area; p

code screenshot 2

System.out.print(\n); System.out.printf( tall balance : %.2f, Double.valueOf (height)); // this is for print value of 2 d

output screenshot

Output Main 1.java * Main.java * Formatter.java * Crap (run) #28 x Crap (run) #29 x Crap (run) #30 x run: Enter Length: 22 En

Please Thumb Up if you Satisfy with Answer

Comment Down If Any Query  

Add a comment
Know the answer?
Add Answer to:
Write a java program that computes the total surface area of a rectangular prism. There are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C Program 2. Write a program which defines a (hollow rectangular) prism as a...

    Write a C Program 2. Write a program which defines a (hollow rectangular) prism as a structure consisting of: length(int) width(int) height(int) • weight(double) • contents(char [25]) Initialize the structure with default values 10, 6, 3, 4.5, and "Best Jewelry" Ask user for new length, width and height and then display Contents, volume, and sum of dimensions

  • Write a C# application that implements a class ‘Prism’ with the following members. Five private data...

    Write a C# application that implements a class ‘Prism’ with the following members. Five private data members ‘length’, ‘height’, ‘width’, ‘Volume’ and ‘Area’ of double data type. Implement the constructor Prism( ) to accept the length, height, and width of the rectangular prism from the user. Implement three methods, Vol(), Area(), and Result() Vol() – to calculate the volume of the prism using the formulae Volume= length ×height ×width Area() – to calculate the surface area of the prism using...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • Write a Java program that prompts user to select one of the five shapes(Rectangle, Square, Triangle,...

    Write a Java program that prompts user to select one of the five shapes(Rectangle, Square, Triangle, Circle, and Parallelogram), then calculate area of the shape,must have input validation and uses more of java library like math class, wrapper class, string methods, use formatted output with the printf method. Finally, create a pseudo-code statement and flowchart

  • Write a program to display the area of a rectangle after accepting its length and width...

    Write a program to display the area of a rectangle after accepting its length and width from the user by means of the following functions: getLength – ask user to enter the length and return it as double getWidth – ask user to enter the width and return it as double getArea – pass width and length, compute area and return area displayArea – pass area and display it in this function. Expected Output: (i) Enter the length: 29 Enter...

  • I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the...

    I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...

  • USING C LANGUAGE Write a program that computes the total weight of a cargo. Ask the...

    USING C LANGUAGE Write a program that computes the total weight of a cargo. Ask the user to enter multiple inputs. For each input, the user indicate the weight and quantity of the boxes. The program computes and prints the total cargo weight The output should match the sample below. Make sure you print the input number (Input #1, Input #2,) 3 - Input # 1. Weight of the box (lbs): 4 Enter quantity: 2 Input #2. Weight of the...

  • ******** IN JAVA ********* I have a program that I need help debugging. This program should...

    ******** IN JAVA ********* I have a program that I need help debugging. This program should ask a user to input 3 dimensions of a rectangular block (length, width, and height), and then perform a volume and surface area calculation and display the results of both. It should only be done using local variables via methods and should have 4 methods: getInput, volBlock, saBlock, and display (should be void). I have most of it written here: import java.util.*; public class...

  • solve it with Java please Write a Java program that prompts the user to input length...

    solve it with Java please Write a Java program that prompts the user to input length and width of a shape. If length is equal to width, call a method to calculate the area of the shape and send only one side as parameter to this method. This meth return the area of the shape. If length is not equal to width, call a method to calculate the area of the shape and send both width and length as parameters...

  • Using basic c++ write a separate code for each of the following: 1. Area Rectangle •...

    Using basic c++ write a separate code for each of the following: 1. Area Rectangle • Write a program that asks the user to enter length and width of a rectangle and then display the rectangles area. • Write the following functions • getLength – prompt the user to enter length and return that value as a double • getWidth – prompt the user to enter width and return that value as a double • getArea – This method should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT