67 238
Assignments Done
99,2%
Successfully Done
In November 2018

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(radius);
add(new Label("Enter the height of the Cylinder"));
add(height);

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

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

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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions