-3

I am a beginner in java and I am trying to write a java code where the program has to calculate the arithmetic mean in the superclass and standard deviation in the subclass.

Here is my code:

import java.util.*;
class ArithmeticMean
{
    double  sum=0, mean, variance, sd, vsum;
    double a[] = new double[10];
    int n,i;
    void accept()
    {
        Scanner scanner = new Scanner(System.in);
        System.out.println("How many Numbers do you want to enter?");
        n=scanner.nextInt();

        for(i=0; i<n; i++)
        {
            System.out.println("Enter No ["+(i+1)+"] : ");
            a[i] = scanner.nextInt();
        }       
    }
    void calculate()
    {
        for(i=0; i<n; i++)
        {
            sum = sum + a[i];
            mean = sum/n;
        }
    }
}
class StandardDeviation extends ArithmeticMean
{
    void calculateSd()
    {
        for(i=0; i<n; i++)
        {
            vsum = vsum+((a[i]-mean)*(a[i]-mean));
            variance = vsum/(n-1);
            sd=Math.sqrt(variance);
        }
    }
    void display()
    {
        System.out.println("Arithmetic mean = "+mean);
        System.out.println("Variance = "+variance);
        System.out.println("Standard Deviation = "+sd);
    }
}
class u3Program9
{
    public static void main(String args[])
    {
        StandardDeviation s = new StandardDeviation();
        s.accept();
        s.calculate();
        s.calculateSD();
        s.display();
    }
} 

Here is the error I'm getting:

enter image description here

Sagar Pudi
  • 4,634
  • 3
  • 32
  • 51
Abhishek Diwakar
  • 466
  • 1
  • 6
  • 18

4 Answers4

1

Java is case-sensitive programming language.

You have defined calculateSd() in StandardDeviation class and invoking calculateSD() on instance of StandardDeviation s.calculateSD(). Where it should be accesed as s.calculateSd()

Sagar Pudi
  • 4,634
  • 3
  • 32
  • 51
1

your method is declared as calculateSd,

in your main method change

s.calculateSD(); 

to

s.calculateSd();
MinA
  • 405
  • 4
  • 9
0

You failed type method name. Your method in StandardDeviation class: calculateSd. You invoke method: calculateSD.

You need rewrite method number to upper or lower case.

Jaleary
  • 1
  • 2
0

The error message says that it cannot find the symbol named 'calculateSD()' in s of StandardDeviation class.

That gives a clue. The method is defined as 'calculateSd()' in StandardDeviation.class, with the lower-case 'd' in the back.

enadiz
  • 23
  • 5