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
PLEASE HELP WHATS THE ANSWER
Mkey [24]

Answer:

C

Explanation:

A ends the whole html stuff

B starts a link

D is just the file extension for html files

4 0
3 years ago
Read 2 more answers
What has prompted schools to add Internet activities in their academic integrity policies? a. New technological advancements c.
AysviL [449]

Answer:

A

Explanation:

Schools are trying to adjust to technology to help students.

6 0
3 years ago
Read 2 more answers
_ is the adherence to a personal code of principles.
trapecia [35]

Answer: Ethics

Explanation:

 Ethics is the basic principle for the personal code. The code of the ethics is basically designed for outline the values in the organization with honesty and integrity.

The ethics is basically depend upon the principle of core value of the organization. The code of the ethics basically guide the core value in the organization and breaking the rule of ethics can also cause termination from the organization.

Morality, integrity and honesty are all the sub part of the ethics vale in the organization. Therefore, ethics is the correct option.  

3 0
4 years ago
9. Which of the following prefixes which relate to bytes are arranged from the smallest to the largest? a) mega, giga, tera, kil
dem82 [27]

Answer:

Explanation:

C

kilo = 1000

mega = 1,000,000

giga = 1 billion = 1 000 000 000

tera = 1 trillion = 1 000 000 000  000

6 0
3 years ago
Development of smart phone​
Delvig [45]

Answer:

The first smartphone, created by IBM, was invented in 1992 and released for purchase in 1994. It was called the Simon Personal Communicator (SPC). While not very compact and sleek, the device still featured several elements that became staples to every smartphone that followed.

4 0
3 years ago
Other questions:
  • How is gawain tempted​
    9·1 answer
  • Pablo can view a minimum of_____ panes and a maximum of_____ panes in a split screen worksheet.
    7·1 answer
  • Why would it be a bad idea for gateways to pass broadcast packets between networks? What would be the advantages of doing so
    12·1 answer
  • Nascar has inserted an image into his document but needs the image to appear on its own line Which option should he choose?
    12·2 answers
  • What is one expectation of open-source software?
    15·1 answer
  • Which of the following gestures would you use if you want to activate a link on your new tablet?
    12·1 answer
  • How do is excel interpret data?
    13·1 answer
  • Use the drop-down menus to complete the statements about how to crop an image in a word document.​
    5·2 answers
  • Who you think is better? Ninja or TFue ,btw do you know who icebear is?
    9·1 answer
  • What are the uses of DVD Ram​
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!