69 670
Assignments Done
Successfully Done
In February 2019

Answer to Question #59187 in Java | JSP | JSF for Hashfi Farizi

Question #59187
Can you help me code this please?

Develop and run a Complete Java applet to prompt user to input for radius of a cylinder and call methods CylinderVolume and CylinderSurfaceArea to calculate and display the area and perimeter of that rectangle using the assignment. Declare all variables as double data type and display the output to two digits after decimal point.

volume = 3.14 * radius^2 * height
surfacearea = 2 * 3.14 * radius (height + radius)

With this user interface:


Enter Radius [Input Text Field]
Enter the height of the Cylinder [Input Text Field]

(Button to calculate volume) (Button to calculate surface area)

The Volume of Cylinder is [Output Text Field]
The Surface Area of a Cylinder is [Output Text Field]

Expert's answer
import java.awt.*;
import java.applet.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyApplet extends Applet {
private TextField radius = new TextField("0", 20);
private TextField height = new TextField("0", 20);
private TextField vol = new TextField("0", 20);
private TextField area = new TextField("0", 20);
private Button calculateVolume = new Button("Calculate volume");
private Button calculateSurfacearea = new Button("Calculate surface area");

public void init() {
add(new Label("Enter Radius"));
add(new Label("Enter the height of the Cylinder"));

calculateVolume.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
vol.setText(String.format("%.2f", CylinderVolume()));

calculateSurfacearea.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
area.setText(String.format("%.2f", CylinderSurfaceArea()));
add(new Label("The Volume of Cylinder is "));
add(new Label("The Surface Area of a Cylinder is "));

public double CylinderVolume(){
return Math.PI * Math.pow(Double.parseDouble(radius.getText()), 2) * Double.parseDouble(height.getText());

public double CylinderSurfaceArea() {
return 2 * Math.PI * Double.parseDouble(radius.getText()) * (Double.parseDouble(height.getText()) + Double.parseDouble(radius.getText()));

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions