COMP1400 – Programming for Designers

Class announcements for Programming for Designers

COMP1400 – Programming for Designers random header image

Assignment 1 correction

Posted by on August 11th, 2011 · Assignments

It has pointed out to me that in the Assignment 1 spec, I wrote:

The player’s initial health (which is also their starting health).

This should read:

The player’s initial health (which is also their maximum health).

So if the player starts with 30 health points then this is the maximum amount of health they can have.

lab 5 – lists

Posted by on August 11th, 2011 · Lab

Your task today is to implement a program to represent decks and hands of playing cards.

  1. Download the cards.zip file and uncompress it. It contains an incomplete BlueJ project called cards.
  2. Open the project and inspect the classes:
    • Card – this represents a single playing card.
    • Deck – this represents a deck of cards. The constructor has been written but the methods need to be completed.
    • Hand – this represents a hand of cards drawn from the deck. The fields, constructor and methods all need to be implemented.
  3. Complete these classes following the comments. Do the Deck class first then the Hand class.

To complete the Deck.draw() method you will need to use the Random class in the Java API. This class provides a random number generator to pick random numbers.

To use this class you will have to import it, by putting the line:

import java.util.Random

at the top of your code.

Read the documentation to find out what constructors and methods the Random class provide.

To see what the class does, try typing the following into the Codepad:

import java.util.Random;
Random rng = new Random();
rng.nextInt(6)
rng.nextInt(6)
rng.nextInt(6)
rng.nextInt(20)
rng.nextInt(20)

lab 4 – object interaction

Posted by on August 5th, 2011 · Lab

Task 1: Universities

Suppose we were writing a program to administer a university. Discuss:

  • What are the different levels of abstraction we might use to represent the university?
  • Choose an object at the mid-level of your hierarchy. What kind of public interface might it provide? What private implementation details might it hide?

Task 2: Return to the Ticket Machine

Go back to the ticket machine project you worked on in last week’s tut.

  1. Create a new class Ticket which represents a ticket.
  2. Create appropriate fields. What information shoud a Ticket carry?
  3. Create a constructor to initialise these fields.
  4. Now modify purchaseTicket on the TicketMachine class so that it creates a new Ticket object and returns it, rather than printing it.

Let’s suppose now that a ticket has 10 charges. Each time we use it, one charge is lost.

  1. Change your Ticket class to track charges. What changes do you need to make to do this?

Now let’s add a recharge method to the TicketMachine. It should take a Ticket as a parameter and reset its charges to 10 but at the cost of 1/10th of the ticketPrice for every charge added (if the user has enough balance). Implement this in stages:

  1. Make the method just recharge the Ticket for free.
  2. Compute how much the recharge will cost. You will need to use an accessor method on the Ticket to find out how much charge it has.
  3. Add a test to see if the user has enough balance.
  4. If there is not enough balance print an error message and do not recharge.
  5. Subtract the charge from the balance.

Task 3: Clock

Take a look at the clock project from Chapter 3 of the textbook.

  1. Investigate the NumberDisplay class first. How does it work?
  2. Look at the setValue method. What does the && operator do? This is a boolean operator. Try experimenting with it in the Code Pad.
  3. Look at the increment method. What does the % operator do? Try experimenting with it in the BlueJ Code Pad.
  4. Now take a look at the ClockDisplay class. Try to understand how it works.
  5. ClockDisplay has two constructors. How do they differ?
  6. The second constructor does not call updateDisplay. Is this a bug? Why/why not?
  7. Change this class to have a seconds field as well as hours and minutes.
  8. Change the class to show a 12 hour clock with AM/PM.

Consultation time

Posted by on August 4th, 2011 · Uncategorized

Malcolm will be doing consultations for COMP1400 students at 2-3pm on Tuesdays in consultation room G01 on the ground floor of the K17 building.

Assignment 1: RPG Player

Posted by on August 1st, 2011 · Assignments

NOTE: This assignment is for COMP1400 students ONLY.

If you are an INFS1609 or 2609 student you should look at the assignment on the INFS1609 blog.

Due Date: Friday week 5 (23:59:59 19 August 2011)

Your first assignment is to implement a class to represent a simple player in a role-playing game like World of Warcraft. Your class will need to implement the following features:

  • A health counter which drops as the player takes damage.
  • A potion counter which can be spent to heal damage.
  • An attack method to allow players to hit each other with weapons.

[Read more →]

Tutorial Wk3 – designing classes

Posted by on July 28th, 2011 · Lab

Investigating the TicketMachine:

  1. Download the TicketMachine project we have been building in lectures. Unzip it on your desktop and open the project with BlueJ.
  2. Create an instance of the TicketMachine class.
  3. Experiment with the addMoney() method. What happens if you:
    • Add 0 cents?
    • Add an negative amount?

    Is this behaviour correct?

  4. Experiment with the purchaseTicket() method. Does it work correctly? Try a number of different tests to make sure.
  5. Open up the source and place a breakpoint at the beginning of the purchaseTicket() method by clicking in the grey bar on the left. A little stop sign should appear.
  6. Call the method again and use the Debugger to step through the code.
  7. Try this with different balances to see how the execution varies.
  8. There is a bug in this method. Can you find it?

Extending the TicketMachine

Let us extend the ticket machine to keep track of the total amount of cash collected and to allow us to change ticket prices.

  1. Add a new field to the class to store the total cash collected.
  2. When does this value change? What methods will you need to modify to track these changes?
  3. Add a new accessor method getTotal() to return the value.
  4. Test your code with a variety of method calls to make sure it does the right thing.
  5. Add a new mutator method setPrice() to allow you to change the ticket price.
  6. What happens if you set the ticket price to zero? a negative number?
  7. Add a conditional statement to set-price to stop the price from being set to a negative value.

Design a Class to represent an E-Book.
It should record the following information:

  • An author
  • An title
  • The number of pages
  • The current page being read.

Implement your class in the following steps:

  1. Create a class definition with an appropriate name.
  2. Add appropriate fields. What types will they have? What names will you give them?
  3. Create a constructor to initialise these fields. What starting values will you use?
  4. Create accessor methods to access these fields.
  5. Create mutator methods to allow the use to:
    • turn pages forwards and backwards
    • jump to a specific page
  6. What should happen if they try to access a page outside of the sensible range? How can you implement this?
  7. Create several different books to test your code. What happens if:
    • Your book has only one page?
    • Your book has no pages?
    • Your book has 1000000000000000000000 pages?
  8. Comment your class to describe what it is for and what each of your methods does.

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

[Read more →]

Lecture Notes and Video

Posted by on July 18th, 2011 · Lectures

I have just uploaded the lecture slides from today’s class. I future you should be able to find slides on the web shortly before the lecture. Follow the link on the sidebar on the right of this page to access them.

Lecture videos should also go up soon.

Welcome to COMP1400 2011

Posted by on July 18th, 2011 · Uncategorized

Welcome everybody to the 2011 class of Programming for Designers. My name is Malcolm and I will be your captain on this flight. Your attendants are Tim Wiley and Sim Mautner. We’re all here to look after you and make sure you have a pleasant flight.

Before we take off, please make sure you check out the safety instructions in the seat pocket in front of you. If you have any questions, don’t hesitate to contact us.

We expect this session’s flight to be smooth and hope to have you to your destination in a little over 13 weeks. So sit back, relax, and let’s learn Java.

Assignment 3 mark is ready to collect.

Posted by on November 14th, 2010 · Uncategorized

Assignment 3 marking is finished and the mark and feedbacks are ready to collect by using the below link:

https://cgi.cse.unsw.edu.au/~give/Student/give.php

Please report any error in collecting the result (with the exact error message) to cs1400@cse.unsw.edu.au.