Question
Complete the constructor in the following program so that it constructs the arraydata, then copies values from the parameterinitintodata. Then complete thetoString()method. import java.io.* ;
Complete the constructor in the following program so that it constructs the arraydata, then copies values from the parameterinitintodata.
Then complete thetoString()method.
import java.io.* ;
class Weight
{
int[] data;
// Constructor
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] =
}
}
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 );
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started