(USE JAVA LANGUAGE) Kindly modify, add on where it is lacking and execute the java program provided below. Don't forget to provide a screenshot of the program output.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Instructions: (USE JAVA LANGUAGE) Kindly modify, add on where it is lacking and execute the java program provided below. Don't forget to provide a screenshot of the program output.

Stars.java

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; //number of stars in cluster
  private int width; //width of star cluster
  private boolean fixed = true;
  private ArrayList<Integer> lx;
  private ArrayList<Integer> 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<Integer>();
    ly = new ArrayList<Integer>();
    Random rand = new Random();
    for (int i = 0; i < num; 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 < num; 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);
      }
    }
  }
}

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY