Please answer this utilizing Java Implement a class SodaCan
Please answer this utilizing Java.
Implement a class SodaCan utilizing the following methods: getSurfaceArea() and getVolume(). Within the constructor, supply both the height and radius of the soda can. Utilie the following formula for the surface area of a cylinder is SA = 2rh + 2r2 and the formula for the volume of a cylinder is V = r2h. Your class should have accessor methods for the instance variables.
Thank you in advanced
Solution
SodaCanDemo.java
 import java.util.Scanner;//package for keyboard inputting
class SodaCan {
public SodaCan(double aHeight, double aDiameter) {//constructor with parameters
 double height = aHeight;
 double diameter = aDiameter;
 double radius = diameter / 2;
 volume = Math.PI * Math.pow(radius, 2) * height;//volume formula
 System.out.println(\"volume of sodacan=\" + volume);
 //surface formula
 surfaceArea = (2 * Math.PI * radius * height)+(2 * Math.PI * radius * radius);
 System.out.println(\"surface of sodacan=\" + surfaceArea);
 }
public void setVolume(double volume) {//setter and getter methods
 this.volume = volume;
 }
public void setSurfaceArea(double surfaceArea) {
 this.surfaceArea = surfaceArea;
 }
public double getVolume() {
 return volume;
 }
public double getSurfaceArea() {
 return surfaceArea;
 }
double volume;
 double surfaceArea;
 }
public class SodaCanDemo {//main class
public static void main(String args[]) {//main method
 System.out.print(\"Enter the height:\");
 Scanner sc = new Scanner(System.in);
 double ht = sc.nextDouble();//key board inputting
 System.out.print(\"enter the radius:\");
 double r = sc.nextDouble();////key board inputting
 SodaCan s = new SodaCan(ht, r);
 }
 }
output
Enter the height:5
 enter the radius:6
 volume of sodacan=141.3716694115407
 surface of sodacan=150.79644737231007


