Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

{ static final int BONUS_POINTS = 5; static void addBonus(int[] array1, int[] shouldAdd) { for (int i = 0; i < array1.length; i++) { if

{

static final int BONUS_POINTS = 5;

static void addBonus(int[] array1, int[] shouldAdd)

{

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

{

if (shouldAdd[i] == 1)

{

array1[i] = array1[i] + BONUS_POINTS;

}

}

}

static double calculateStat1 (int[] a)

{

int s = 0;

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

{

s = s + a[i];

}

return s / (double)a.length;

}

static double calculateStat2(int[] a, double s1)

{

double s = 0;

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

{

s = s + (a[i] - s1) * (a[i] - s1);

}

return (Math.sqrt(s) / (a.length - 1));

}

public static void main(String[] args)

{

int data[] = { 42, 97, 64, 53, 78, 96, 83 };

int bonus[] = { 0, 1, 1, 0, 0, 1, 1 };

addBonus(data, bonus);

double stat1 = calculateStat1(data);

System.out.println("The first static is " + stat1);

double stat2 = calculateStat2(data, stat1);

System.out.println("The second statistic is " + stat2);

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

{

System.out.print(data[i] + " is ");

double distance = (data[i] - stat1) / stat2;

System.out.print(distance + " from " + stat1 + " which is a");

if (distance < -1.5)

{

System.out.println("n F");

}

if ((distance >= -1.5) && (distance < -0.5))

{

System.out.println(" D");

}

if ((distance >= -0.5) && (distance < 0.5))

{

System.out.println(" C");

}

if ((distance >= 0.5) && (distance < 1.5))

{

System.out.println(" B");

}

if (distance >= 1.5)

{

System.out.println("n A");

}

}

}

}

QUESTION:

Use the above code to answer the question:

In caclculateStat1(), how would the behiavior be different if the length of the array was not typecast to double?

Please be as detailed as possible. Thank you!

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

Step: 3

blur-text-image

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

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions