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]
3 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]3 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
Which of the following is true about parallel computing performance?
Ierofanga [76]

Answer:

Computations use multiple processors. There is an increase in speed.

Explanation:

The increase in speed is loosely tied to the number of processor or computers used.

Mark me a brainliest answer

4 0
3 years ago
What are some preferences you can set in photoshop?
pishuonlain [190]

Answer: face brightness

Explanation:

hope this is the right answer :)

5 0
2 years ago
Playstation 4 how to change mtu settings
tamaranim1 [39]
Ask google mam.............
4 0
3 years ago
In which phase of website design does the designer create a mock-up aimed at the target use
alexdok [17]

Answer:

The answer is design.

Explanation:

I know this because based off the notes it states that "the designer can use a model or mock-up to illustrate the look and feel, to help gain a better understanding of the necessary elements and structures.

3 0
3 years ago
To “synthesize” means to combine information to create new information.<br> YES or NO
KIM [24]

Answer:Yes

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • Illustrate the process of using an operating system to manipulate a computer’s desktop, files and disks.
    12·1 answer
  • Reggie has hired you to design a home network. The home network will share a printer but will mainly be used to stream movies to
    7·1 answer
  • Integration Management, one of the 10 PMBOK Guide Knowledge Areas, represents the processes and activities to identify, define,
    12·1 answer
  • If you want to write some fancy interface on your computer with expanded communication to the Arduino, what library should you u
    13·1 answer
  • A system is composed of four parts, J, K, L, and M. All four must function for the system to function. The four component reliab
    6·1 answer
  • Write an application that displays the strings in the provided array alphabetically in ascending order.
    9·1 answer
  • Compile and Execute a Program
    13·1 answer
  • By convention only, either the first usable address or the last usable address in a network is assigned to the router (gateway)
    11·1 answer
  • write ms-dos command to list all the files and folders of EIGHT sub directory of C: drive in ascending order according to file n
    5·1 answer
  • What is the purpose of the Subtotal feature?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!