Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help in java. Please show results. Thank you To gain experience with using

ID: 3815646 • Letter: N

Question

Need help in java. Please show results. Thank you To gain experience with using java interface, abstract class, base class and subclass. Documentation: Explain the purpose of the program as detail as possible 8%. Develop a solution for the problem and mention algorithms to be used -12% List data structures to be used in solution. - 5%. Give a description of how to use the program and expected input/output - 5%. Explain the purpose of each class you develop in the program. - 5%. Programming: For each method, give the pre and post conditions and invariant, if any - 10% Program execution according to the requirements given 50% Naming of program as required 5% Description of Program You are to write a program name Shape.java that will: Write an inheritance hierarchy of three-dimensional shapes. Make a top-level shape interface that has methods for getting information such as volume and surface area of three-dimensional shape. Now make classes that are subclasses that implement various shapes such as cubes, rectangular prisms, triangular prisms, sphere, cones and cylinders. Place common behavior in super classes whenever possible as well as using abstract classes when appropriate. Add methods to the subclasses to represent unique behavior of each three-dimensional shape such as methods to get a sphere's radius, etc. All of these will be used in the main program rightarrow Shape.java (where you must invoke the methods from the subclasses and print values such as area, circumference, volume, perimeter, etc. where possible.)

Explanation / Answer

Code:-

import java.util.*;
import java.lang.*;
import java.io.*;

abstract class Shape {
public abstract double volume();
public abstract double surface_area();
}

class Sphere extends Shape {
private final double radius; //sides

public Sphere() {
this(1);
}
public Sphere(double radius) {
this.radius=radius;
}

@Override
public double volume() {
// volume = 4/3 * pi * r*r*r;
double volume= (4.0/3.0)*3.14*radius*radius*radius;
return volume;
}

@Override
public double surface_area() {
// surface_area= 4 * pi* radius*radius;
return 4*3.14*radius*radius;
}

}
class Cube extends Shape {
private final double edge; //sides

public Cube() {
this(1);
}
public Cube(double edge) {
this.edge=edge;
}

@Override
public double volume() {
// volume = a*a*a;
double volume= edge*edge*edge;
return volume;
}

@Override
public double surface_area() {
// surface_area= 6*edge*edge;
return 6*edge*edge;
}
}
class Cylinder extends Shape {
private final double radius,height; //sides

public Cylinder() {
this(1,1);
}
public Cylinder(double radius,double height) {
this.radius=radius;
this.height=height;
}

@Override
public double volume() {
// volume = pi * r*r*h;
double volume= 3.14*radius*radius*height;
return volume;
}

@Override
public double surface_area() {
// surface_area= 2*pi*r*(r+h);
return 2*3.14*radius*(radius+height);
}
}
class Cone extends Shape {
private final double radius,height; //sides

public Cone() {
this(1,1);
}
public Cone(double radius,double height) {
this.radius=radius;
this.height=height;
}

@Override
public double volume() {
// volume = pi * r*r*h/3;
double volume= 3.14*radius*radius*(height/3);
return volume;
}

@Override
public double surface_area() {
// surface_area= pi*r*r + pi*r*sqrt((r*r)+(h*h));
double surface_base=3.14*radius*radius;
double surface_side=3.14*radius*Math.sqrt((radius*radius)+(height*height));
double surface=surface_base+surface_side;
return surface;
}
}

class Test {
public static void main(String[] args) {

// Sphere test
double radius = 5;
Shape sphere = new Sphere(radius);
System.out.println("Sphere radius: " + radius
+ " Resulting volume: " + sphere.volume()
+ " Resulting surface area: " + sphere.surface_area() + " ");

// Cylinder test
radius=5;
double height=10;
Shape cylinder = new Cylinder(radius,height);
System.out.println("Cylinder radius: " + radius + "Cylinder height: " + height +
" Resulting volume: " + cylinder.volume()
+ " Resulting surface area: " + cylinder.surface_area() + " ");
  
// Cone test
radius=5;
height = 10;
Shape cone = new Cone(radius,height);
System.out.println("Cone radius: " + radius + "Cone height: " + height +
" Resulting volume: " + cone.volume()
+ " Resulting surface area: " + cone.surface_area() + " ");
  
// Cube test
double side = 5;
Shape cube = new Cube(side);
System.out.println("Cube side: " + side
+ " Resulting volume: " + cube.volume()
+ " Resulting surface area: " + cube.surface_area() + " ");
  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote