I have written a piece of code which is giving me some errors please look at it and debug it:
package measurement;
import java.util.*;
class Cylinder {
static double sa(float h,float r) { return 2*3.14*r*h; }
static double vol(float h,float r) { return 3.14*r*r*h; }
}
class Sphere {
static double sa(float r) { return 4*3.14*r*r; }
static double vol(float r) { return 4/3*3.14*r*r*r; }
}
class Cube {
static public double sa(float a) { return 6*a*a; }
static public double vol(float a) { return a*a*a; }
}
public class Measure {
public static void main(String arg[]) {}
public static void cubeSA(float a) { Cube.sa(a); }
public static void cubeVol(float a) { Cube.vol(a); }
}
Above piece of code is package I have created but in my other program it is giving error
Class measure cant be access
my main(other) program is:
import measurement.*;
import java.util.*;
public class PackExample {
public static void main (String args[]) {
Scanner sc=new Scanner (System.in);
Measure m=new Measure();
Cylinder cy=new Cylinder();
Sphere s=new Sphere();
while (true)
{ System.out.println("Enter:\n1.CYLINDER\n2.CUBE3.SPHERE");
int x=sc.nextInt();
if(x==1)
{
System.out.println("Enter height of cylinder:");
float a=sc.nextfloat();
System.out.println("Enter radius of base of cylinder:");
float b=sc.nextfloat();
System.out.println("Surface area is "+cy.Cylinder.sa(a,b)+" unit sq.");
System.out.println("Surface area is "+cy.Cylinder.vol(a,b)+" unit cube");
}
else if(x==2)
{
System.out.println("Enter its Edge length:");
float a=sc.nextFloat();
System.out.println("Surface area is "+m.CubeSA(a)+" unit sq.");
System.out.println("Surface area is "+m.CubeVol(a)+" unit cube");
}
else if(x==3)
{
System.out.println("Enter Radius of Sphere:");
float r=sc.nextFloat();
System.out.println("Surface area is "+s.Sphere.sa(r)+" unit sq.");
System.out.println("Surface area is "+s.Sphere.vol(r)+" unit cube");
}
else System.exit(0);
}
}
}
Although there must be other errors too but
Error:cannot access Measure
This is compiler error is need to debug first.