I am trying to learn object oriented programming in the context of Java. I am writing a fairly simple code, but am getting this error:
Exception in thread "main" java.lang.NullPointerException
at Advisor_score.Rating.Score(Rating.java:12)
at Advisor_score.Rating.main(Rating.java:25)
Here is my code:
package Advisor_score;
public class Rating {
double [] Ratings;
double sum;
double raw_advisor;
double advisor_score;
public Rating (double [] x){
double [] Ratings = x;
}
public double Score(){
for(int i=2;i<Ratings.length;i++){
sum+=Ratings[i];
}
raw_advisor=((sum-(3*(Ratings.length-2)))/4);
advisor_score= 2.5+(2.5*(1-Math.pow(Math.E, -.5*raw_advisor)));
return advisor_score;
}
public void print(){
System.out.println(advisor_score);
}
public static void main(String[] args){
double p1_1[] = {101,1,1,1.5,.5};
Rating d = new Rating(p1_1);
d.Score();
d.print();
}
}
I have been looking at this for hours and cannot figure out the problem with the code. I am new to programming can anyone help me? Thanks in advance!