Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a generic class with a type parameter constrained to the Number class or a

ID: 3758182 • Letter: W

Question

Write a generic class with a type parameter constrained to the Number class or any subclass of Number. The constructor should accept an array of such objects. The class should have methods that return the highest and lowest values in the array, the total of the elements, and the average value of all the elements.

I need help getting this code up and running with the code in the photo. If someone can help me out, I will appreciate it.

Can anyone help me. I need someone to make this program on the bottom work with the program in the photo. If you could can you please not have any scanner classes please.

/**

This class keeps the sales figures for a number of

days in an array and provides methods for getting

the total and average sales, and the highest and

lowest amounts of sales.

*/

public class SalesData

{

private double[] sales; // The sales data

/**

The constructor copies the elements in

an array to the sales array.

@param s The array to copy.

*/

public SalesData(double[] s)

{

// Create an array as large as s.

sales = new double[s.length];

  

// Copy the elements from s to sales.

for (int index = 0; index < s.length; index++)

sales[index] = s[index];

}

/**

getTotal method

@return The total of the elements in

the sales array.

*/

public double getTotal()

{

double total = 0.0; // Accumulator

// Accumulate the sum of the elements

// in the sales array.

for (int index = 0; index < sales.length; index++)

total += sales[index];

// Return the total.

return total;

}

/**

getAverage method

@return The average of the elements

in the sales array.

*/

public double getAverage()

{

return getTotal() / sales.length;

}

/**

getHighest method

@return The highest value stored

in the sales array.

*/

public double getHighest()

{

double highest = sales[0];

for (int index = 1; index < sales.length; index++)

{

if (sales[index] > highest)

highest = sales[index];

}

return highest;

}

/**

getLowest method

@returns The lowest value stored

in the sales array.

*/

public double getLowest()

{

double lowest = sales[0];

for (int index = 1; index < sales.length; index++)

{

if (sales[index] < lowest)

lowest = sales[index];

}

return lowest;

}

C:/TMCCCIS220/Instructor Resourcus/NetReans Source Code/Chapter17/Chp17PCO7Demoscichp17pc07demo/(I package chp17pc07deo; Chapter 17, Progranminq Chaltenge 7 5 publc class Chp17 PCO7Demo 6 public static void main(SLri] args) // Create an array of Integer values. Intogor[] numbers = { new Tnteger (44) new Inteer (77), new Tnteger(11), new Integer (99) , new Tnteger (55), new Integer (22) 12 14 15 17 18 // Create an Analyzer object Analyzer analyzer new Analyzor nubers); // Di spiay the highost value in the array System. out, prin 1n("The highest value is " + analyzer.qetHighest; // Display the Lowest valuo in he array, System.out,println("he lowest value is " + 26 analyzor.getLowest // Display the totat of the values in he array. System.out.println ("The Lotal of the values is "+ 31 32 3 34 35 analyzer.getTotal; // Display the average of the values in he array. System.out println "The avere of the values is "+ ana yzer.getAvcrage () 37 38 I.1 ofl 2014.10.23 11:3040

Explanation / Answer

import java.util.Scanner;

public class Analyzer <T extends Number>
{
T[] array;

//constructor.
public Analyzer (T[] a)
{
array = a;

} //end constructor

/*
*highest method returns the
*highest value in the array.
*/

T getHighest()
{
T high = array[0];
//find the highest value.
for (int i = 1; i <array.length; i++)
{
if ((high.toString()). compareTo(array[i].toString())<0)
{
high = array[i];
}
}
return high;
} //end of constructor

public T getLowest()
{
T low = array[0];
//find the highest value.
for (int i = 1; i <array.length; i++)
{
if ((low.toString()). compareTo(array[i].toString())>0)
{
low= array[i];
}
}
return low;
} //end of constructor

public T getTotal()
{
T total = array[0];
//find the highest value.
for (int i = 1; i <array.length; i++)
{
  
   int k=Integer.parseInt(total.toString());
int arr=Integer.parseInt(array[i].toString());
int tot=k+arr;
Integer in=new Integer(tot);
total=(T) in;
}
return total;
}
public T getAverage()
{
T total = array[0];
//find the highest value.
for (int i = 1; i <array.length; i++)
{
  
   int k=Integer.parseInt(total.toString());
int arr=Integer.parseInt(array[i].toString());
int tot=k+arr;
Integer in=new Integer(tot);
total=(T) in;
}
int k=Integer.parseInt(total.toString());
k=k/array.length;
Integer in=new Integer(k);
total=(T) in;
return total;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote