#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# How do I create a GETTER function?

edited November 2017

I am doing some schoolwork for computer science.

I have done most of the assessment but I just need help with creating the GETTER function. Here are the questions.

Problem 1 Star Class: Now let's say you want to decide how many stars are shown instead of hard- coding 25 in the array initialization (the first line of the program), as well as the maximum radius. You're only in charge of the Star class, so you want to add a variable called starCount and a variable called maxRadius. Main Program: - 25 = Star.starCount - 20 = Star.maxRadius

Problem 2 What happens if X & Y are made static

Problem 3: Static Methods Public variables are a security concern. Change the starCount and maxRadius to private variables and Create GETTER Functinos for both

Problem 4: Question: What would happen if getStarCount() was made static?

Here is my code Question 1 is completed, and the answer to question 2 is that the circles will clump together and overlap.

Note the code is in two separate tabs the first one is Star_Start

``````private Star[] stars = new Star [Star.starCount];

public void setup() {
size(500, 500);

ellipseMode(CENTER);

for (int i = 0; i < stars.length; i++) {
stars[i] = new Star(random(500), random(500), random(Star.maxRadius));

}
}

public void draw() {

background(0);

for (int i = 0; i < stars.length;  i++) {
}
}
public void mouseClicked() {
for (int i = 0; i < stars.length; i++) {
stars[i] = new Star(random(500), random(500), random(Star.maxRadius));
}
}
``````

2nd Tab

Star.Java

``````class Star {
private float x;
private float y;
public static int starCount = 250;
public static int maxRadius =  20;

public Star (float x, float y, float radius) {
this.x = x;
this.y = y;

}

public float getX () {
return x;

}

public float getY() {
return y;

}

}

}
``````

If someone could tell me what he means by GETTER function and how to add it to my code that would be wonderful. My friends and I cannot seem to figure it out and since we are on a long weekend and our teacher is busy, he is not available at the moment.

Tagged:

``````public float getX () {