Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi everyone. I\'m having some trouble with my assignment. I need to design an ap

ID: 3538467 • Letter: H

Question

Hi everyone. I'm having some trouble with my assignment. I need to design an applet that draws 5 circles of random radius(between 25-100) and in random locations. Use a width of 400 and height of 300 as the size of the applet.

There are a few things I don't completely understand about the directions. It says a random "radius" between 25-100. the drawOval statement requires a x and y value as the argument to draw the "imaginary" rectangle in which the oval is contained. What exactly do the instructions mean when they say "radius". Also I can't figure out how to size the applet to 400x300.

Below is my code so far. Right now the output is 5 circles that descend from the top/left to bottom/right of the screen. They also increase in size one at a time. So yes, they are not random. What can I use to improve my code? Am I using the random number generator correctly here? Thank you for your help!
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
import javax.swing.JApplet;
import java.awt.*;
import java.util.Random;

public class Drawing extends JApplet
{
public void paint(Graphics page)
{
Random generator=new Random();

int random;
int x,y;
int width, height;
setBackground(Color.white);

random=generator.nextInt(80);
page.setColor(Color.black);
x=random;
y=random;
width=random;
height=random;
page.drawOval(x, y, width, height);

random=generator.nextInt(80)+25;
page.setColor(Color.black);
x=random;
y=random;
width=random;
height=random;
page.drawOval(x, y, width, height);

random=generator.nextInt(80)+25;
page.setColor(Color.black);
x=random;
y=random;
width=random;
height=random;
page.drawOval(x, y, width, height);

random=generator.nextInt(80)+25;
page.setColor(Color.black);
x=random;
y=random;
width=random;
height=random;
page.drawOval(x, y, width, height);

random=generator.nextInt(80)+25;
page.setColor(Color.black);
x=random;
y=random;
width=random;
height=random;
page.drawOval(x, y, width, height);
}

}

Explanation / Answer

public class Drawing extends JApplet
{
public void paint(Graphics page)
{
Random generator=new Random();

int random,randomx,randomy;
int x,y;
int width, height;
setBackground(Color.white);

random=generator.nextInt(75)+25;
randomx=generator.nextInt(400);
randomy=generator.nextInt(300);
page.setColor(Color.black);
x=randomx;
y=randomy;
width=random*2;
height=random*2;
page.drawOval(x, y, width, height);

It prints a bunch of interconnecting circles of different sizes.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote