Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Business Programming HW #6 Arrays Exercise 1: Using Arrays for Correlation coefficient (10pt) Let us revisit Homework 2-Exercise 2 and use arrays to calculate the

image text in transcribed

Business Programming HW #6 Arrays Exercise 1: Using Arrays for Correlation coefficient (10pt) Let us revisit Homework 2-Exercise 2 and use arrays to calculate the correlation coefficient. Save your program as Hw6_Ex1.java. Suppose we now have more data points than previously. Consider 10 data points as follows: Prices: 23.11 10.71 26.98 28.68 23.57 25.15 24.86 17.84 23.11 13.42 Sales: 262 428 185 162 217 237 230 325 267 382 Note that each price is paired with its matching sales volume in the same order. Recall that the correlation coefficient measures the linear correlation between two variables X and Y. It has a value between +1 and -1, where 1 is total positive linear correlation, 0 is no linear correlation, and -1 is total negative linear correlation. We want to find out the correlation coefficient between price (X) and sales quantity (Y). We can use the following formula to calculate the correlation coefficient r: -[(xi - )/i-y)] x)2 __(): - y)2 where x and y are the mean such that N y = 212 y, N Now write a simple Java program to compute the correlation coefficients r given the 10 data points listed above, using arrays to hold these data. You may follow the steps below: 1) Define two arrays, say, x and y, to hold the prices and sales, respectively; initialize the arrays by typing in the numbers; (Note: enter the data in the same order as listed above so that prices and sales will be matched properly) 2) Calculate the averages, X and y; (Hint: use for loops) 3) Calculate the correlation coefficient using the formula provided above; (Hint: use for loops to calculate the sums in the numerator and the denominator) 4) Display the value of the correlation coefficient. Only display 4 digits after the decimal point (Hint: use print) Hint: Your output should look like the following: C. Command Prompt C:\test>javac Hw6_Ex1.java C:\test>java Hw6_Ex1 Correlation coefficient: -0.9874 C:\test)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

5-8 What are the advantages and disadvantages of the BYOD movement?

Answered: 1 week ago