1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
olga55 [171]
2 years ago
14

Imagine that you have access to a class named MyCircle that has void setRadius(double r) and double getRadius() methods. Write a

static method that accepts a MyCircle array. The method should accomplish two goals: it should return the average of the radius’s for all MyCircles that have a positive radius, and for any MyCircles that have a negative radius it should set the radius to 0.
Computers and Technology
1 answer:
Nikitich [7]2 years ago
7 0

Code for the method described in the question in java:

public static double averageRadius(MyCircle[] myCircles) {

       double sum = 0;

       for (MyCircle myCircle: myCircles) {

           if(myCircle.getRadius() < 0) myCircle.setRadius(0);

           sum += myCircle.getRadius();

       }

       return sum / myCircles.length;

   }

And the complete program:

import java.util.Random;

public class MyCircle {

   private double radius;

   public double getRadius() {

       return radius;

   }

   public void setRadius(double radius) {

       this.radius = radius;

   }

   public static double averageRadius(MyCircle[] myCircles) {

       double sum = 0;

       for (MyCircle myCircle: myCircles) {

           if(myCircle.getRadius() < 0) myCircle.setRadius(0);

           sum += myCircle.getRadius();

       }

       return sum / myCircles.length;

   }

   public static void main(String[] args) {

       Random random = new Random();

       int N = 10;

       MyCircle[] myCircles = new MyCircle[N];

       for (int i = 0; i < myCircles.length; i++) {

           myCircles[i] = new MyCircle();

           myCircles[i].setRadius(random.nextInt(100));

           System.out.printf("Created MyCircle %d with radius %.2f \n", i, myCircles[i].getRadius());

       }

       System.out.printf("\nAverage radius of %d circles is %.2f \n", N, MyCircle.averageRadius(myCircles));

   }

}

The output was:

Created MyCircle 0 with radius 76.00

Created MyCircle 1 with radius 86.00

Created MyCircle 2 with radius 38.00

Created MyCircle 3 with radius 4.00

Created MyCircle 4 with radius 8.00

Created MyCircle 5 with radius 39.00

Created MyCircle 6 with radius 77.00

Created MyCircle 7 with radius 78.00

Created MyCircle 8 with radius 39.00

Created MyCircle 9 with radius 46.00

Average radius of 10 circles is 49.10

You might be interested in
In 1972, earlier designers built the
Sonbull [250]

The exercise is about filling in the gaps and is related to the History of the ARPANET.

<h3>What is the History of the ARPANET?</h3>

From the text:

In 1972, earlier designers built the <u>ARPANET </u>connecting major universities. They broke communication into smaller chunks, or <u>packets </u>and sent them on a first-come, first-serve basis. The limit to the number of bytes of data that can be moved is called line capacity, or <u>bandwidth</u>.

When a network is met its capacity the user experiences <u>unwanted pauses</u>. When the network is "slowing down", what is happening is users are waiting for their packet to leave the <u>queue</u>.

To make the queues smaller, developers created <u>mixed </u>packets to move <u>simultaneously</u>.

Learn more about the ARPANET at:
brainly.com/question/16433876

7 0
2 years ago
You want to divide the value in cell D3 by the value in cell E3. Which formula should you use?
Tom [10]
The formula is:
=D3/E3
4 0
3 years ago
Read 2 more answers
To be useful for most household applications, DC voltage is?please <br>​
satela [25.4K]

Answer: To be useful for most household applications, DC voltage is passed through a step-down transformer.

Explanation: Voltage coming through AC or DC outlets is typically far too high for most household appliances to handle, so the current is passed through a step-down transformer to reduce the voltage to a usable level.

3 0
2 years ago
A technician has been notified of a problem on the network. After investigation, the technician determines that a specific inter
bogdanovich [222]

Answer:

Virus is a type of malware which is used in this case.

Explanation:

7 0
3 years ago
Sedimentary rock formation occurs when igneous, metamorphic, or other sedimentary rocks are exposed to the unyielding forces of
Natalija [7]
Deposition is the answer
3 0
3 years ago
Read 2 more answers
Other questions:
  • Which computer port transmits audio and video without the need for compression?
    6·1 answer
  • Describe mobile computing
    7·1 answer
  • Gunther is filling in his own input mask. He wants to format the Social Security numbers of his clients. The field must contain
    5·1 answer
  • Which object waits for and responds toan event from a GUI component?
    9·1 answer
  • On five lane roadways, the center lane is designated for __________ and is used by vehicles traveling in both directions.A. Thro
    15·1 answer
  • True or false? Colons are required when entering the MAC address into the Reservation window?
    14·1 answer
  • How many passes will it take to find the four in this list?
    15·2 answers
  • Lucas wants to expand his vocabulary to better understand the sentence below. The insidious burglar moved through the house unhe
    7·2 answers
  • How would you want to change the copyright laws?
    11·1 answer
  • We can save our data peremently on a
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!