Question: I have done two classes for this java program and I need the last part please help Class: Cylinder Add code from: Participation Activity -
I have done two classes for this java program and I need the last part please help
Class: Cylinder
- Add code from:
- Participation Activity - Class Declaration and Instance Variables
- Participation Activity - Constructors and Instance Methods
- Add Instance Method: Set Units
- Parameters: String
- Return Type: void
- Add Instance Method: Set Material
- Parameters: String
- Return Type: void
- Add Instance Method: Set Height
- Parameters: double
- Return Type: void
- Add Instance Method: Set Radius
- Parameters: double
- Return Type: void
Class: Lab Activity Classes And Objects
Main Method
- Add declarations from Participation Activity - Using Constructors and Calling Instance Methods
- Create Comment: Display Initial Values Display a description and the volume of Pin Display a description and the volume of Dowel
- Create Comment: User Input Get user input for Pin Units Get user input for Pin Material Get user input for Pin Height Get user input for Pin Radius
- Create Comment: Modifying Object Call the appropriate instance method to update the values of the Pin
- Create Comment: Final Values Display a description and the volume of Pin Display a description and the volume of Dowel
here is the cylinder class
-----------------------------------------------------------------------------------------------------------------------------------------------
public class Cylinder { // VARIALBES private double radius; private double height; private String units; private String material; // CONSTRUCTORS public Cylinder() { radius = 1.0; height = 1.0; units = "inches"; material = "Aluminum"; } public Cylinder(double cylinderRadius, double cylinderHeight, String cylinderUnits, String cylinderMaterial) { radius = cylinderRadius; height = cylinderHeight; units = cylinderUnits; material = cylinderMaterial; } //METHODS public double volume() { return(height * Math.PI * Math.pow(radius, 2)); } public void setUnits(String newUnits) { units = newUnits; } public void setMaterial(String newMaterial) { material = newMaterial; } public void setHeight(double newHeight) { height = newHeight; } public void setRadius(double newRadius) { radius = newRadius; } } -------------------------------------------------------------------------------
here is the main class
import java.util.Scanner;
public class LabActivityClassesAndObjects { public static void main(String[] args) { // CONSTANTS // VARIABLES // ARRAYS // OBJECTS Cylinder pin = new Cylinder(); Cylinder dowel = new Cylinder(5, 40, "mm", "Oak"); Scanner keyBoardInput = new Scanner(System.in); // Initial Values System.out.println("Pin volume: " + pin.volume() + " mm^2"); System.out.println("Dowel volume: " + dowel.volume() + " mm^2"); // User Input System.out.println("Please enter the units: "); String units = keyBoardInput.nextLine(); System.out.println("Please enter the material: "); String material = keyBoardInput.nextLine(); System.out.println("Please enter the height: "); double height = keyBoardInput.nextDouble(); System.out.println("Please enter the radius: "); double radius = keyBoardInput.nextDouble(); // Modifying Object pin.setUnits(units); pin.setMaterial(material); pin.setHeight(height); pin.setRadius(radius); // FinalValues here is what I need help
- Create Comment: Final Values Display a description and the volume of Pin Display a description and the volume of Dowel
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
