Hi .l am real new to programming . l have a problem with my code .l have tried to translate the following programming problem into java language but the problem l have is that l cannot create the subclass that is Cube class.Here is the programming problem:Design a class called Square with a value for the side of the square and validate that value and calculate the area of the square .The child class Cube will use the existing methods of the parent class to validate and receive the side of the cube and create a new method to calculate and display the volume of the cube.Below are the code for two relational classes.Hoping for assistance.
Below is the code for the child class
Please help me to fix my code.
Thanks in advance
KKHULUZA NKOMO
Code:
/**
*
* @author Abraham Nkomo
*/
public class Square
{
public double sideLength;
public Square(double inSideLength )
{
sideLength = inSideLength;
}
double Area;
public void calculateSquare()
{
if (validInput)
Area = sideLength * sideLength;
else
System.out.println("Invalid input");
}
boolean validInput = true;
{
if (sideLength < 0)
validInput = false;
else
validInput = true;
}
public double displayArea()
{
return Area;
}
}
Below is the code for the child class
Code:
/**
*
* @author Abraham Nkomo
*/
public class Cube extends Square
{
double cubeVolume ;
public void calculateCubeVolume()
{
validInput = true;
if(validInput)
cubeVolume = sideLength * sideLength * sideLength;
else
System.out.println("Invalid input");
}
public double getCubeVolume()
{
return cubeVolume;
}
}
Please help me to fix my code.
Thanks in advance
KKHULUZA NKOMO
Comment