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

Create a class called Cylinder.java that contains two double-precision instance

ID: 3531498 • Letter: C

Question

Create a class called Cylinder.java that contains two double-precision instance variables named radius and height. The class should include a constructor that initializes the radius and height variables. Also, you need a class method named volume() that returns the volume of a Cylinder object. The volume of a cylinder is given by its radius squared times its height times Pi (radius * radius * height * Math.PI). You can either use the value 3.1416 for Pi or use the Java provided value named Math.PI.

Write a class called CylinderTest.java and declare an array of three Cylinder objects to call the methods you declared in the Cylinder class. Make sure that all class methods are called from main(). Have main() display the value returned by volume() and verify the returned value by hand calculations (paper/pencil). Prompt the user to enter the values for the radius and height of each Cylinder object in the array.

Grading Rubric

Cylinder

Points

Description

Standard header included

1

Program compiles

2

Program executes

2

Created Cylinder class

3

Constructor created that initializes variables

2

Contains a volume method

2

CylinderTest class, which drives the application, is created

4

Correct output is displayed

4

Subtotal

20

Cylinder

Points

Description

Standard header included

1

Must contain program's name, student name, and description of the program

Program compiles

2

Program does not have any error

Program executes

2

Program runs without any error

Created Cylinder class

3

Program contains the Cylinder class

Constructor created that initializes variables

2

A constructor method exists in the Cylinder class and initializes radius and height

Contains a volume method

2

The volume method exists in the Cylinder class and it returns the volume of a Cylinder object

CylinderTest class, which drives the application, is created

4

A driver class with the main method

Correct output is displayed

4

Program displays the radius, height, and volume of three Cylinder objects

Subtotal

20

Explanation / Answer

import java.lang.Math.* // Imports the Math class
public class Cylinder { // creates the Cylinder class

// instance double variables for radius and height should always be declared private
private double radius, height;
private double final Pi = 3.1416;
private double volume;

public Cylinder () { //default constructorJava will not provide this to you since you are overloading it

}

// constructor that initializes the radius and height variables.
public Cylinder (double height, double radius) {
this.height = height;
this.radius = radius;
}

// accessor method for height
public double getHeight() {
return height;
}

// accessor method for radius
public double getRadius() {
return radius;
}

// volume method
public double volume() {
volume = Math.pow(radius, 2) * Pi // main calculation
return volume;
}

}

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