DESCRIPTION:
Calculate arithmetic mean in the superclass and standard deviation in the subclass in JAVA.
CODING:
Calculate arithmetic mean in the superclass and standard deviation in the subclass in JAVA.
CODING:
import java.util.Scanner;
class AMSD
{
public static void main(String[] args)
{
SD c1=new SD();
System.out.print("How many Enter Number:");
c1.CalAM(c1.num.nextInt());
System.out.println("Arithmetic Mean:" + c1.am);
c1.CalSD();
System.out.println("Standard Deviation :" + c1.sd);
}
}
class AM
{
Scanner num=new Scanner(System.in);
double am=0;
double[] a;
int i;
public void CalAM(int n)
{
a=new double[n];
for(i=0;i<n;i++)
{
System.out.print("Enter number:" );
a[i]=num.nextDouble();
am=a[i]+am;
}
am=am/n;
}
}
class SD extends AM
{
double sd=0;
public void CalSD()
{
for(i=0;i<a.length;i++)
{
sd=Math.pow(a[i]-am,2)+sd;
}
sd=Math.sqrt(sd/a.length);
}
}
class AMSD
{
public static void main(String[] args)
{
SD c1=new SD();
System.out.print("How many Enter Number:");
c1.CalAM(c1.num.nextInt());
System.out.println("Arithmetic Mean:" + c1.am);
c1.CalSD();
System.out.println("Standard Deviation :" + c1.sd);
}
}
class AM
{
Scanner num=new Scanner(System.in);
double am=0;
double[] a;
int i;
public void CalAM(int n)
{
a=new double[n];
for(i=0;i<n;i++)
{
System.out.print("Enter number:" );
a[i]=num.nextDouble();
am=a[i]+am;
}
am=am/n;
}
}
class SD extends AM
{
double sd=0;
public void CalSD()
{
for(i=0;i<a.length;i++)
{
sd=Math.pow(a[i]-am,2)+sd;
}
sd=Math.sqrt(sd/a.length);
}
}
Comments
Post a Comment