Question

Create a JAVA class that reads data from two arrays and calculates the correlation coefficient.

Create a JAVA class that reads data from two arrays and calculates the correlation coefficient.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution

class CorrelationCoefficient{
int[] A;
int[] B;
public CorrelationCoefficient(int n,int[] A,int[] B)
{
this.A = new int[n];
this.B = new int[n];
this.A = A;
this.B = B;
}
public float getCorrelationCoefficient(int n)
{
int sumA = 0, sumB = 0, sumAB = 0;
int squareSumA = 0, squareSumB = 0;
float soln = 0;
for(int i = 0;i<n;i++)
{
sumA += A[i];
sumB += B[i];
sumAB += A[i]*B[i];
squareSumA += A[i]*A[i];
squareSumB += B[i]*B[i];
}
soln = (float)(n*sumAB - sumA*sumB)/(float)(Math.sqrt((n*squareSumA - sumA*sumA)*(n*squareSumB - sumB*sumB)));
return soln;
}
  
}
public class Main
{
   public static void main(String[] args) {
   int[] A = {15,18,21,24,27};
   int[] B = {25,25,27,31,32};
   int n = 5;
   CorrelationCoefficient CC = new CorrelationCoefficient(5,A,B);
  
       System.out.println("Correlation Coefficient : " + CC.getCorrelationCoefficient(n));
   }
}

Output

Feel free to reach out regarding any queries . And please do rate the answer . Thank you .

Add a comment
Know the answer?
Add Answer to:
Create a JAVA class that reads data from two arrays and calculates the correlation coefficient.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a class that reads data from 'Grades.txt' calculates average grade and output the data t...

    Write a class that reads data from 'Grades.txt' calculates average grade and output the data t 'Grades_average.txt'in JAVA public class CH10 Grader_main { CH10 Grade public static void main(String [ ] args) { String fileName = "StudentGrades.txt"; String outfile Name-"StudentGrades_average.txt"; CH10 Graderrun(filename, outfileName) ? Name,StudentNum, Java, DataStructure,OpenSource, Cal1 aman,201601,70,30.10,20 bman,201602,30,30,20,20 cman 201603.30,70,30.40 dman,201604,10,70,50,50 eman,201605,60,60.60,90 fman,201606,80,50,50,10 gman,201607,10,10,80,80 hman,201608,20,30.10,20 Input file('Grades.txt) Name,StudentNum,Java,DataStructure,OpenSourca, Cal1, Average aman,201601,70,30,10,20,32.5 bman,201602,30,30.20,20.25.0 aman,201603,30,70,30.40,42.5 dman,201604,10,70,50,50.45.0 eman,201605,60,60,60,90,67.5 fman.201606,80,50,50.10,47.5 Output file ('Grades_average.txt) man201607.10.10.80,80.45.0 hman,201608,20,30,10,20,20.0 Average 000000.38.75.43.75,38.75,41.25.40.625

  • JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods...

    JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class) 1) Data members: none 2) Methods a. A method named displayContents that accepts an array of type int and prints their values to the b. A method named cemoveNegatives that accepts an array of type int, copies all its non-negative the new array should be the...

  • Java netbeans, points out of 10 Exercise#3 Create a class CourseGrades that consists of two data...

    Java netbeans, points out of 10 Exercise#3 Create a class CourseGrades that consists of two data fields, student_id and grade. The class has set and get methods for each data variable. Then, write a Java program that reads students ids and corresponding grades into an array of type CourseGrades and print the average grade for the class. Your program should have two methods in addition to main(), one method for reading the students ids and grades and another method for...

  • Create a java project. Create a class called cls2DarrayProcessor.java. with the following: Reads numbers from a...

    Create a java project. Create a class called cls2DarrayProcessor.java. with the following: Reads numbers from a pre-defined text file. A: Text file name should be data.txt B: Text file should be in the same workspace directory of your project's folder C: Text file name should be STORED in a String and called: String strFile ='./data.txt' Defines a 2-D array of integers with dimensions of 5 rows by 5 columns. Inserts the data from the text file to the 2-D array...

  • This is for JAVA programming. Create a test class that contains two arrays and two methods:...

    This is for JAVA programming. Create a test class that contains two arrays and two methods: - The first array has 3 rows and 3 columns and is initialized with type double data - The second array has 4 rows and 4 columns and is also initialized with type double data - The first method ArraysRows will receive an array of type double as an argument and then print out the sum and average of all elements in each ROW....

  • Create a java class that calculates the various statistics of your favorite quarterback in NFL. If...

    Create a java class that calculates the various statistics of your favorite quarterback in NFL. If you don’t have one, you could use pick Matt Ryan of Atlanta Falcons from his 2015 season. Use either visit nfl.com or their team website for some of the data you would need to complete this assignment. Implement the main method in the class and do the following in the main method Create an appropriate type of array (yards) to store a number of...

  • JAVA: create a program that reads all text files in a directory, calculates the occurrences of...

    JAVA: create a program that reads all text files in a directory, calculates the occurrences of words, and saves the result in one single output text file. assume that you are in a directory called Desktop/programdirectory, where you have multiple text files. textfile1.txt : "how are you" textfile2.txt: "great thank you" textfile3.txt: "great to see you. see you later" Then, your output.txt should have: how: 1 are: 1 you: 4 great: 2 thank: 1 to: 1 see: 2 later: 1

  • Create a class called CompareArrays that determines if two specified integer arrays are equal. The class...

    Create a class called CompareArrays that determines if two specified integer arrays are equal. The class should have one static methods: public static boolean compare(int[] arrayOne, int[] arrayTwo) – Which compares the two arrays for equality. The two arrays are considered equal if they are the same size, and contain the same elements in the same order. If they are equal, the method should return true. Otherwise, the method should return false. Create a second class called CompareArraysTest that contains...

  • Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method...

    Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...

  • JAVA JAVA 1- Create two arrays one for the rank of the playing cards and one...

    JAVA JAVA 1- Create two arrays one for the rank of the playing cards and one for the suit. 2- Create an array of 52 strings that contain a deck of playing cards. The first 13 items are the cards, whose suit is clubs, the next 13 diamonds, the next 13 hearts and finally the spades. In this step, the array and the order of the cards should be printed. 3- Use the shuffling algorithm you have learnt in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT