Question

5. (30 pts) Write a program that calculates the surface area of a cube (see the formula below). The user inputs the cubes side length and your program will then print out the surface area of that cube. Your code must follow the output in the sample run below. Your program must be complete and correct, but you do not need to include comments. Here is the formula to calculate surface area given a cubes side length: surface area 6 side length)) / sample run: Enter the side length in meters: 1.5 The cube has a surface area of 13.50 square meters. import java util.Scanners public class CubeSurfaceArea ( public static void main(Stringl] args) f
0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution:

import java.util.Scanner;
public class CubeSurfaceArea {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double side;
System.out.println("Enter side length: ");
side = scanner.nextDouble();
System.out.printf("Surface area = %.2f", (6*side));
}
}

Add a comment
Know the answer?
Add Answer to:
5. (30 pts) Write a program that calculates the surface area of a cube (see the...
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
  • Java. (20 pts)          Write a program that reads all the numbers from the file mynums.dat...

    Java. (20 pts)          Write a program that reads all the numbers from the file mynums.dat and prints out the sum of the positive values from the file. Assume that the file contains only numeric values. You must output an error if the file can't be opened. You must write the complete program and the output when the program runs successfully must conform exactly to the sample output. Bonus ( 5 pts). Output an error if the file contains non-numeric...

  • 1. Let A be the surface area of a cube with side s at time t....

    1. Let A be the surface area of a cube with side s at time t. a) If the side changes at a rate of 3.0 cm/min, at what rate is the cube's surface area changing when the side is 25 cm? b) If the side changes at a rate of -5.0 cm/min, what is the side of the cube when the surface area is changing at a rate of -240 cm2 /min? 2. Find dy/dx by differentiating implicitly. Express...

  • Write a program named program51.py that defines a value-returning function named cuber that returns both the...

    Write a program named program51.py that defines a value-returning function named cuber that returns both the surface area and volume of a cube. A cube is a rectangular prism with all sides equal. Prompt the user to enter the cube's side length from the keyboard in the main function and then call the cuber function. Moving forward for all assignments and for this program, all other code would be in a main function, called at the very end of your...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • ******** 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...

  • Write a program that will check a Java file for syntax errors. The program will ask...

    Write a program that will check a Java file for syntax errors. The program will ask for an input-file name and output-file name and will then copy all the code from the Java input file to the Java output file, but with the following changes: 1. Any syntax error found in the Java input file will be corrected: a. Missing semicolon b. Missing compound statements (curly braces) c. All comments have to start with // and end with a period....

  • Part 1: Use principles of inheritance to write code calculating the area, surface area, and volume...

    Part 1: Use principles of inheritance to write code calculating the area, surface area, and volume of rectangular objects. First, write an abstract super class RectangularShape, then write a subclass Rectangle that inherits from the super class to compute areas of rectangles, including squares if there is only one data. Finally, write another subclass Cuboid that inherits from its super class Rectangle above to compute surface areas and volumes of cuboids, including 3 equal sided cube. Must apply code-reusability in...

  • Problem: Write a short C++ program that gets the side of a cube and the radius...

    Problem: Write a short C++ program that gets the side of a cube and the radius of a sphere from the keyboard and writes to a file the surfaces of these shapes.             ------------------------------------------------------------------------------------------------------------------------ Your task: implement in C++ the algorithm solution shown below. ------------------------------------------------------------------------------------------------------------------------ Part A (79 points) Algorithm solution (in pseudocode): To accomplish this task, your program will have to take the following steps: 1. Declare a variable named outFile that represents an output stream. 2. Declare a...

  • In this assignment, you will write a Java program(s) to print the binary representation of a...

    In this assignment, you will write a Java program(s) to print the binary representation of a positive integer inserted from command line.  You must finish your assignment in 2 different ways: Using a recursive method Using an iterative method     Your main method must be: public static void main(String[] args) {      int input;         input = Integer.parseInt(args[0]);     print_recursion(input);     print_binary(input); }     You must implement a class and test your program by different input values, including 0. Comment your program properly Example of test...

  • Why is my program returning 0 for the area of a triangle? public class GeometricObjects {...

    Why is my program returning 0 for the area of a triangle? public class GeometricObjects {    private String color = " white ";     private boolean filled;     private java.util.Date dateCreated;     public GeometricObjects() {         dateCreated = new java.util.Date();     }     public GeometricObjects(String color, boolean filled) {         dateCreated = new java.util.Date();         this.color = color;         this.filled = filled;     }     public String getColor() {         return color;     }     public void setColor(String color)...

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