0

I want to run following code in Eclipse as Java Application and it requires main method to define. At all tries to do it myself was receiving a message:

method TemperatureNormalizer() is undefiened for the type TemperatureNormalizer

Could you please help me to write it correctly?

import java.util.Arrays;
public class TemperatureNormalizer {
   private double[] data;

   public TemperatureNormalizer(double[] list) {
       data = list;
   }

   public static void main(String[] args) {
       TemperatureNormalizer();
   }

   public double getAdjustedAverage() {
       double max = getMax();
       double min = getMin();
       double sum = getSum();

       int insertAt = 0;

       for (int i = 0; i < data.length; i++) {

           if (data[i] == max || data[i] == min) {
               for (int j = i; j > insertAt; j--) { 
                   data[j] = data[j - 1];
               }
               data = Arrays.copyOf(data, data.length - 1);
           }    
       }
       return (sum - max - min) / data.length;
   }

   public double getMax() {
        double current = 0;
        for (int i = 0; i < data.length; i++) {
            if (data[i] > current) {
                current = data[i];
            }
        }
        return current;
    }

    public double getMin() {
        double current = data[0];
        for (int i = 0; i < data.length; i++) {
            if (data[i] < current) {    
                current = data[i];  
            }   
        }
        return current;
    }

    public double getSum() {
        double sum = 0;
        for (double d : data) {
            sum = sum + d;
        }
        return sum;
    }
}
1
  • 1
    You need to construct the instance of TemperatureNormalizer , so in the main method add TemperatureNormalizer temperatureNormalizer = new TemperatureNormalizer(); then on a new line call the methodtemperatureNormalizer .getAdjustedAverage() Commented May 13, 2015 at 12:16

4 Answers 4

1

In your main method, initialize your object with: TemperatureNormalizer temperatureNormalizer = new TemperatureNormalizer ();

Also, your class TemperatureNormalizer has a constructor which expects an array of Double. Either give an array in your main method or create an extra constructor that doesn't take a parameter.

public TemperatureNormalizer()
{
  // do stuff (or not)
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you guyes, for your help
0

You should create a test class (for example) which will contain all your actions:

class Test{
    public static void main (String[] args){
        TemperatureNormalizer temperatureNormalizer = new TemperatureNormalizer();
   }  
}

If all your classes are in the same folder the compiler will have no problem.

Comments

0
  1. You need to create Object of the class in the main method. Already you have created Parameterized constructor, so the compiler won't create a default constructor. You have to code for that.

    public TempratureNormalizer(){
     // implementation here...
    }
    
    TempratureNormalizer TempNorm = new TempratureNormalizer();
    
  2. If you're calling Parameterized constructor that is

    TempratureNormalizer(double[] list)
    

    then the main method should be

    double[] list = {2.0,3.45,1.09} // give your dynamic values
    TempratureNormalizer TempNorm = new TempNormailzer(list);
    

Comments

0

If you just want to run this program then change main method in the program as below:

public static void main(String[] args) {
       double  a1[] = {1,2,3,4};
       TemperatureNormalizer temp = new TemperatureNormalizer(a1);
       System.out.println("Avg:" + temp.getAdjustedAverage());
   }

It will give output:

Avg: 1.6666666666666667

2 Comments

Are there any simplier ways to make run configuration in eclipse for the program, which has no main method?
you need main method to run your Java Program. Its not possible to run without main method because execution will start from main method only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.