Intro CS Assignments
Assignments by week:
Fall Term:
Winter Term:
Spring Term:
Monday, December 3
Description
OO Practice
Homework
  • Design a class called "BankAccount". This class does not draw anything on the screen; it is just a class to model specific behavior of an abstract object. A BankAccount has a balance (amount of money), PIN (or password), and an account number (integer). It should be able to return the amount of money in the account, have money added to it (deposit), and taken out (withdraw). Due at the start of next class.
  • Design a class called "Spinny". This class creates a rectangle that rotates in place, so a Spinner must know its own coordinates and angle of rotation. It should also have a varying speed and the ability to "pause" the spinning. In your main program, create several Spinners at random locations, and then pause or unpause them if they are clicked on, like in the example below. Hint: to figure out if you clicked in the shape, use an approximation (distance from center) so you don't have to figure out the rotation. If you want to be precise, see the screenX() and screenY() functions for a way to map the coordinates exactly.

    We'll work on this during next class, but you should at least have the variables, a constructor, and some attempt at the functions for the class.

    Your browser does not support the canvas tag.

Tuesday, December 4
Description
More OO Practice
Homework
  • Keep working on the Spinny class we started today. At a minimum, we're looking to register mouse presses on each individual object (using the location and size of the spinner to figure out if the mouse is "inside"). If you have time, try to finish up the program so it looks like the demo from last week. We'll go over the solution together in class tomorrow, so bring any questions with you if you aren't able to finish.
Thursday, December 6
Description
Finishing Spinners
Homework
  • We're going to start learning about physics this week, and we'll do so by progressively adding features to a program to build it up slowly. Work through the assignments in order as best you can, and we'll answer questions during class.

    • Make a class-based program that has one class, called "Ball" in it. A ball should know where it is on the screen, how big it is, and what color it is. If you click on a ball, it should alternate its color between red, green, and blue. Balls do not move on their own, nor can they be dragged. See the example below:

      Your browser does not support the canvas tag.

      The version above should work for any number of Ball objects in an array, so you should be able to create an arbitrary number just by changing a single parameter in your program (the size of the array). You should randomize the location of the Ball objects, either in the constructor or by passing random values to the constructor.

    • Add velocities to the balls so they move on their own, and change color whenever they hit a side. If you need some hints, remember that the objects tutorial created a Car that had velocity and wrapped around the screen. It should look something like this:

      Your browser does not support the canvas tag.

Friday, December 7
Description
Introduction to Physics
Homework
  • Read this article on time-based animation. It's written in JavaScript, so don't worry too much about the code (you should get the general idea, though). The main thing to focus on is why time-based animation is necessary and what you need to do in order to implement it.
  • Continue working on the Ball class that we've started in class. We'll go into it more tomorrow, but you should at least have multiple Ball objects showing up on the screen, and should try to animate them before tomorrow.
  • If you get through everything above and still have time, add gravity to the velocities (recall that acceleration is just a change in velocity over time...). For extra features, allow the user to click on the screen to "pop" everything back into the air, and (if you can!) allow collisions between objects. Don't worry if you can't get to all of this; we'll talk about it in class.

    Your browser does not support the canvas tag.