• Home
  • Blog
  • Write the Java code for each of the exercises in the attached document. Compile, debug and test via BlueJ

Write the Java code for each of the exercises in the attached document. Compile, debug and test via BlueJ

0 comments

Week 3 Lab

Exercise 1

Start with program called ScrollingSun

  • Modify to move on X axis
  • Modify so that Y axis is constant

Exercise 2

Perform Two Compliment

  • Add: 6, -4
  • Add: 7, -1

Exercise 3

Create a program called RandomBox with the following features:

  • When the program begins it creates a filled rectangle of random size (make your limits 20 – 120 pixels) centered on the screen
  • Hint: center is
    • canvasWidth – boxWidth/2
    • canvasHeight – boxHeight/2
  • When the mouse exits the window the box disappears
  • When the mouse re-enters the window, it generates a new size for the box and re-centers it on the screen
  • If time, make the color of the box random. Change each time a new box is drawn.

Extra Credit

Write a program called RandomBox2.

  • Same as RandomBox except for box position
  • Position box some value D within 150 px of center (changing both X and Y axis by the D value

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}