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] =

}

}

//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 );

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!