In: Computer Science
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package
Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format.
Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class, every field, every constructor, and every method have a general (useful) comment and all relevant tags. This includes @param tags for methods and constructors and @param and @return tags for methods.
/*Solution Description:
Created App as per the instruction and added the ss for the same to give you an idea
In that 3 classes as mentioned with a basic explanation.
Please give thumbs up for the solution.
*/
1. Project :
2.Cube and Sphere Class :
public class Cube {
int loengthOfSide;
//Constructor with no arguments
public Cube() {
this.loengthOfSide = 1;
}
/*Constructor with an argument
* @Param int type lengthOfSide of the cube*/
public Cube(int loengthOfSide) {
this.loengthOfSide =
loengthOfSide;
}
/*Gtetters and Setters
* */
/*@return type int gives length of sides of
cube*/
public int getLoengthOfSide() {
return loengthOfSide;
}
/*@Param of type int sets length of sides of the
cube*/
public void setLoengthOfSide(int loengthOfSide)
{
this.loengthOfSide =
loengthOfSide;
}
/*toString method
* @return String contains info of Cube class*/
@Override
public String toString() {
return "Cube [" + loengthOfSide +
"]";
}
/*
* @return of type int surface area of the cube*/
public int getSurfaceArea() {
return
6*this.loengthOfSide*this.loengthOfSide;
}
/*
* @return of type int volume of the of the
cube*/
public int getVolume() {
return
this.loengthOfSide*this.loengthOfSide*this.loengthOfSide;
}
}
################################################################
public class Sphere {
private int radius;
//Constructor with no arguments
public Sphere() {
this.radius = 1;
}
/*Constructor with an argument
* @Param int type radius of the Sphere*/
public Sphere(int radius) {
this.radius = radius;
}
/*Gtetters and Setters
* */
/*@return type int gives radius of Sphere*/
public int getRadius() {
return radius;
}
/*@param type int radius of Sphere*/
public void setRadius(int radius) {
this.radius = radius;
}
/*toString method
* @return String contains info of Sphere class*/
@Override
public String toString() {
return "Sphere [" + radius +
"]";
}
/*
* @return of type double surface area of the
Sphere*/
public double getSurfaceArea() {
//Math.pi is java inbuilt variable
to define pi
return
4*Math.PI*this.radius*this.radius;
}
/*
* @return of type double volume of the of the
Sphere*/
public double getVolume() {
return
(4/3)*Math.PI*this.radius*this.radius*this.radius;
}
}
3.Program4 class:
import java.util.Scanner;
public class Program4 {
public static void main(String[] args) {
// Scanner
Scanner scanner = new
Scanner(System.in);
//Cubes
Cube firstCube = new Cube();
System.out.println(firstCube.toString());
System.out.println("Please enter
the length of the side for firstCube: ");
int length =
scanner.nextInt();
firstCube.setLoengthOfSide(length);
Cube secondCube = new
Cube(8);
Cube thirdCube = new Cube(3);
int accessorValue =
firstCube.getLoengthOfSide();
System.out.println("First Cube:
"+accessorValue+ "\nSecond Cube: "+secondCube.getSurfaceArea()+",
and \nThird Cube: "+thirdCube.getVolume());
//Spheres
Sphere firstSphere = new
Sphere();
System.out.println(firstSphere.toString());
System.out.println("Please enter
the radius of the firstSphere: ");
int rad = scanner.nextInt();
firstSphere.setRadius(rad);
Sphere secondSphere = new
Sphere(8);
Sphere thirdSphere = new
Sphere(3);
int accessorValueSphere =
firstSphere.getRadius();
System.out.println("First Sphere:
"+accessorValueSphere+ "\nSecond Sphere:
"+secondSphere.getSurfaceArea()+", and \nThird Sphere:
"+thirdSphere.getVolume());
}
}