![maryanapritchak1829](/avatars/29189.jpg)
maryanapritchak1829
11.02.2021 •
Computers and Technology
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 )
Solved
Show answers
More tips
- S Sport Where can you play football in Moscow?...
- F Food and Cooking 10 Reasons Why You Should Avoid Giving Re-Gifts: An Informative Guide...
- S Sport How to wrap boxing hand wraps? Everything you need to know!...
- A Animals and plants 5 Tips for Taking Care of Yews to Keep Them Green and Beautiful...
- H Health and Medicine How to Calm Your Nerves? Expert Tips That Actually Work...
- O Other What is a Disk Emulsifier and How Does it Work?...
- S Sport How to Pump Your Chest Muscle? Secrets of Training...
- C Computers and Internet How to Get Rid of 3pic Infector: Everything You Need to Know...
- S Style and Beauty How to Grow Hair Faster: Real Methods and Advice...
- C Computers and Internet How to Top Up Your Skype Account Without Losing Money?...
Answers on questions: Computers and Technology
- M Mathematics The length of a rectangle is 2 times the width. The perimeter of the rectangle is 600. What is the measure of the length?...
- P Physics While you are studying for an upcoming physics exam, a lightning storm is brewing outside your window. suddenly, you see a tree across the street struck by lightning....
- M Mathematics PLEASE ANSWER 20 POINTS...
Ответ: