I'm new to coding and I'm having trouble with trying to get a double from another method. In trying to make it so I can set the length, width, and height of a cube and it outputs these numbers and the area, but I can't get one of my methods to take the math problem I made?
Cube.java
public class Cube {
public double height;
public double width;
public double length;
static void CalculateTotalArea(double height, double width, double length) {
double area = (double) (height * width * length);
}
public void printWords(){
System.out.println("This cube has a height of " + height +
" , a width of " + width +
" , and a depth of " + length +
". Its total area is: " + area);
}
}
What I'm trying to do in printWords
, is have it print the numbers type and show the area but it won't take my area from the math problem above it.
I don't know if you need to see the other class to understand what I'm doing so I'm just gonna post that too.
Lab5.java
import java.util.Scanner;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Please type the Height, Width, and Length"
+ " of the cube you would like to see the area of."
+ " For example 10 5 2");
// allows "scan(Hight, Width, and Length)" to be given a typed number
double scanHeight = scanner.nextInt();
double scanWidth = scanner.nextInt();
double scanLength = scanner.nextInt();
Cube finalCube = new Cube();
finalCube.height = scanHeight;
finalCube.width = scanWidth;
finalCube.length = scanLength;
Cube.CalculateTotalArea(finalCube.height, finalCube.width, finalCube.length);
finalCube.printWords();
}