subject

Complete the constructor in the following program so that it constructs the array data, then copies values from the parameter init into data. Then complete the toString() method.

class Weight
{
private int[] data;

// Constructor
public Weight(int[] init)
{
// Make data the same length
// as the array referenced by init.
data = new

// Copy values from the
// input data to data.
for (int j)
{
data[j] =
}
}

//Print
public String toString()
{

}
}

public class WeightTester
{
public static void main ( String[] args )
{
int[] values = { 98, 99, 98, 99, 100, 101, 102, 100, 104, 105,
105, 106, 105, 103, 104, 103, 105, 106, 107, 106,
105, 105, 104, 104, 103, 102, 102, 101, 100, 102};
Weight june = new Weight( values );
System. out. println( june );
}
}
2.

class Weight
{
. . .

public int average()
{
. . .
}
}

public class WeightTester
{
public static void main ( String[] args )
{
int[] values = { 98, 99, 98, 99, 100, 101, 102, 100, 104, 105,
105, 106, 105, 103, 104, 103, 105, 106, 107, 106,
105, 105, 104, 104, 103, 102, 102, 101, 100, 102};

Weight june = new Weight( values );
int avg = june. average();
System. out. println("average = " + avg );
}
}

Now add another method that computes the average for a range of days. The method header looks like this:

public int subAverage( int start, int end )

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 22:30
The qwerty keyboard is the most common layout of keys on a keyboard
Answers: 3
question
Computers and Technology, 23.06.2019 05:20
Which operating system is a version of linux?
Answers: 1
question
Computers and Technology, 24.06.2019 18:00
Which of the following is an example of synchronous communication? a) e-mail b) voicemail c) telephone conversation d) text message.
Answers: 1
question
Computers and Technology, 24.06.2019 19:30
Can someone who is skilled at coding create me a java chess game. don't copy from online source codes. make it original ! : d
Answers: 1
You know the right answer?
Complete the constructor in the following program so that it constructs the array data, then copies...
Questions
question
Mathematics, 03.02.2021 21:00
question
Mathematics, 03.02.2021 21:00
Questions on the website: 13722361