There are two tasks for this week’s lab:
- Activate your CSE account.
- Write your first program!
- Play with BlueJ
Activate your CSE account
The first thing we will do in this week’s lab is activate your CSE account:
- Go into the banjo lab (next door to the CHI lab)
- Login as ‘newuser’
- Follow the prompts to activate your account.
- Write your new username and password somewhere so you don’t lose it.
- Log out.
- Log back in with your new CSE login and password (to activate your account).
- Log out again.
- 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.
- Shuffle the deck.
- Go through the deck to find the smallest card.
- 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.
- 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?
- Swap programs with another pair and check their code. Was it the same as yours?
- Consider: What are the objects in your program? What are the classes? What fields do they have? What methods do they provide?
- Now try writing instructions to sort the entire deck into order.
Experiment with BlueJ
Experiment with the BlueJ projects we saw in lectures.
- Login with your CSE login and password set up earlier
- Start BlueJ
- Select ‘Open Project’ from the File menu and open the ‘shapes’ project.
- Experiment with constructing objects and calling methods. Try to construct a picture out of circles, squares and triangles of different sizes and colours.
- Use the inspector to examine the objects you have created. How do the fields on a Triangle differ from those on a Circle?
- 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?
- Open the ‘picture’ project and have a play with the new class it provides.
- 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.
- Change some of the method parameters and compile the source. Can you make the sun blue? Can you change the position of the window?
- Optional Challenge: Add code to the draw() method to make the sun set using the slowMoveVertical() method on the Circle class.
- 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.