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
FIrst person to put lyrics to wap gets brainliest 100% NO CAP
Firdavs [7]

Answer:

i got u

Explanation:

****** in this house

There's some ****** in this house

There's some ****** in this house

There's some ****** in this house (Hol' up)

I said certified freak, seven days a week

Wet and gushy, make that pullout game weak, woo (Ah)

[Chorus: Cardi B]

Yeah, yeah, yeah, yeah

Yeah, you dealin' with some wet and gushy

Bring a bucket and a mop for this wet and gushy

Give me everything you got for this wet and gushy

[Verse 1: Cardi B & Megan Thee Stallion]

Beat it up, baby, catch a charge

Extra large and extra hard

Put this cookie right in your face

Swipe your nose like a credit card

Hop on top, I wanna ride

I do a kegel, I'm kinda wild

Look at my mouth, look at my thighs

This water is wet, come take a dive

Tie me up like I'm surprised

Let's roleplay, I'll wear a disguise

I want you to park that big Mack truck right in this little garage

Make me dream, make a stream

Out in public, make a scene

I don't cook, I don't clean

But let me tell you how I got this ring (Ayy, ayy)

5 0
3 years ago
Which of the following is a trend that began during the Vietnam War and continued with the Internet?
Blizzard [7]
<span>As far as I remember, this one - a. a move toward stricter control of mass-media communications by Congress and the FCC </span><span>is a trend that began during the Vietnam War and continued with the Internet.</span>
7 0
3 years ago
________ is a model of computing in computer processing, storage, software, and other services which are provided as a shared po
Rudiy27

Answer:

"Cloud computing" is the correct answer .

Explanation:

Cloud computing is defined as it provided the resources of the system like data storage etc on the demanding purpose. In cloud computing, it provided the resources without knowing the management. Social media is one of the examples of cloud computing.

  • Cloud computing is a model in the computer system that stores the bulk data provided the services to the user on demands.
  • Cloud computing acts as a shared pool of virtual resources on the internet.
6 0
3 years ago
Assume the user types in 7 for x and 2 for y. What is output by the
vladimir1956 [14]

Answer:

49

Explanation:

3 0
3 years ago
Write an algorithm to find the average of three numbers: 10, 20, 30
STALIN [3.7K]

Language: JavaScript

Answer:

let num = [10,20,30];

average(num);  

function average(num) {

 let sum = 0;

 for(let i in num) {

   sum += num[i];

 }  

 return console.log(sum/num.length);

}

3 0
3 years ago
Other questions:
  • What three characteristics of a function are described in an IPO chart? What is performed at each characteristic?
    12·1 answer
  • Which of the following subjects is considered technical education
    11·1 answer
  • cellPhoneBill(m,tx)Write the function cellPhoneBill()that takes two int m and txas input and returns a float.The function takes
    11·1 answer
  • What is the navigation aid that shows users the path they have taken to get to a web page located within a website?
    12·1 answer
  • Create a dictionary that will hold AT LEAST 3 categories for food with at least 3 foods for each category. E.g. Fruits --&gt; Ap
    6·1 answer
  • Can some help me on this"..... / ..--- ..--- / ..... / .---- ---.. / .---- ----. / ..... / ..... / .---- ....- / ..--- ----- / .
    6·1 answer
  • What is the job of a router during the process of routing on the Internet?
    10·1 answer
  • Does speedtest report megabytes per second or megabits
    6·1 answer
  • 2.
    9·1 answer
  • What is the process of ensuring that corporate security policies are carried out<br> consistently?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!