Question: I am doing a final project in eclipse for a Java course. We were given 10 classes of different code that when ran together make

I am doing a final project in eclipse for a Java course. We were given 10 classes of different code that when ran together make the image shown. What I have provided is the class the stars. I would like to add snow falling and maybe some snowmen as well. If the stars class is removed that is fine. Anyone that can help? Let me know if anything else is needed.I am doing a final project in eclipse for a Java course.

import java.awt.*;

import java.util.*;

public class Stars

{

//private data

private int x; //beginning x coordinate of star cluster

private int height; //height of star cluster (always start from the top of the window, or 0)

private int num; /umber of stars in cluster

private int width; //width of star cluster

private boolean fixed = true;

private ArrayList lx;

private ArrayList ly;

/**

* The only constructor for the class,

* initializes all the private data,

* @param int x, int y, int number, int w

*/

public Stars (int x, int y, int number, int w)

{

this.x = x;

height = y;

num = number;

width = w;

lx = new ArrayList();

ly = new ArrayList();

Random rand = new Random();

for (int i = 0; i

//save the current starts

lx.add(rand.nextInt(width)+x);

ly.add(rand.nextInt(height));

}

}

public void setFixed(boolean f) {fixed = f;}

/** Draws a star cluster relative to the x, height, num, width

@param Graphics page

* @return n/a

*/

public void draw (Graphics page)

{

page.setColor(Color.white);

Random rand = new Random();

//draws the amount of randomly placed stars specified by user

for (int i = 0; i

{

//the random coordinates are generated to be within specified area given the height, width, and beginning of star cluster

//all stars are little tiny squares

if (fixed) {

page.fillRect(lx.get(i), ly.get(i), 2, 2);

if (i%10 == 0) {

page.drawLine(lx.get(i)+x-4,ly.get(i), lx.get(i)+x+4, ly.get(i));

page.drawLine(lx.get(i)+x,ly.get(i)-4, lx.get(i)+x, ly.get(i)+4);

}

}

else {

lx.set(i, rand.nextInt(width));

ly.set(i, rand.nextInt(height));

page.fillRect(lx.get(i)+x, ly.get(i), 2, 2);

//bigger star - in the shape of a tiny cross for variety

//generated randomly in the same way as the stars above

int xStar = rand.nextInt(width)+x;

int yStar = rand.nextInt(height);

//horizantal line

page.drawLine(xStar+x-4,yStar, xStar+x+4, yStar);

//vertical line

page.drawLine(xStar+x,yStar-4, xStar+x, yStar+4);

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!