COMP1400 – Programming for Designers

Class announcements for Programming for Designers

COMP1400 – Programming for Designers random header image

Tutorial Wk 2 – Getting to know BlueJ

Posted by on July 21st, 2011 · Uncategorized

There are two tasks for this week’s lab:

  1. Activate your CSE account.
  2. Write your first program!
  3. Play with BlueJ

Activate your CSE account

The first thing we will do in this week’s lab is activate your CSE account:

  1. Go into the banjo lab (next door to the CHI lab)
  2. Login as ‘newuser’
  3. Follow the prompts to activate your account.
  4. Write your new username and password somewhere so you don’t lose it.
  5. Log out.
  6. Log back in with your new CSE login and password (to activate your account).
  7. Log out again.
  8. Return to the Mac lab, but don’t log in yet as it will take a while for your account details to be processed.

Write your first program.

This is an exercise in breaking down a task into a sequence of simple instructions. Work in pairs. Your tutor will give each of you a small, incomplete pack of cards.

  1. Shuffle the deck.
  2. Go through the deck to find the smallest card.
  3. On a sheet of paper, write a set of instructions so that someone else can repeat the same procedure. Assume that they are very stupid and need to have ever last detail spelled out.
  4. Test your instructions on different size decks:
    • What if there is only 2 cards in the deck? Or only one? Or none?
    • What if all the cards in the deck were the same?
  5. Swap programs with another pair and check their code. Was it the same as yours?
  6. Consider: What are the objects in your program? What are the classes? What fields do they have? What methods do they provide?
  7. Now try writing instructions to sort the entire deck into order.

Experiment with BlueJ

Experiment with the BlueJ projects we saw in lectures.

  1. Login with your CSE login and password set up earlier
  2. Start BlueJ
  3. Select ‘Open Project’ from the File menu and open the ‘shapes’ project.
  4. Experiment with constructing objects and calling methods. Try to construct a picture out of circles, squares and triangles of different sizes and colours.
  5. Use the inspector to examine the objects you have created. How do the fields on a Triangle differ from those on a Circle?
  6. Double click on the Circle class to view its source code. Try to identify the fields and methods in the code. How much of the code can you understand?
  7. Open the ‘picture’ project and have a play with the new class it provides.
  8. Open the source code for the Picture class and take a look at the draw() method. This is the code that constructs the house from shapes.
  9. Change some of the method parameters and compile the source. Can you make the sun blue? Can you change the position of the window?
  10. Optional Challenge: Add code to the draw() method to make the sun set using the slowMoveVertical() method on the Circle class.
  11. Optional Extra Challenge If you did the above challenge you probably found that the sunset happened as soon as the draw() method was called. Try creating a separate method called sunset() that does this instead.

No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.