Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hi, I was wondering if I could get some help on a java program that I am supposed to be writing. The code that I
Hi, I was wondering if I could get some help on a java program that I am supposed to be writing. The code that I have can be found below. Thanks in advance.
Here are the requirements of the code
1) Create 3 cube objects. The size of each of the cubes should be input from the keyboard (hint: study the code below) 2) Print the Side length, Surface area and Volume to the users screen (console) for each of the cubes 3) The program should catch input error exceptions and deal with them in a reasonable manner
import java.util.Scanner;
import java.io.*;
public class Cube { // Hint: put your class variables and objects here
// For example the Scanner statement as a 'static' object // Create the getLength() method to accept input and verify it is numeric // Create the calculateSurfaceArea() method // Create the calculateVolume() method
/** * main() -- creates 3 instances of Cube and calculates the surface area and volume */ public static void main(String args[]) throws IOException { int length; // HINT: input the side from the keyboard and check for errors and exceptions Cube cube1 = new Cube(10); System.out.println("Side length of cube1 is " + cube1.getLength()); System.out.println("Surface Area of cube1 is " + cube1.calculateSurfaceArea()); System.out.println("Volume of cube1 is " + cube1.calculateVolume()); // Hint - add two more cube instances // Don't forget to close your Scanner object
} // main() } // Cube
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started