Programming for Designers

Class announcements for COMP1400

Programming for Designers random header image

Ass 3 solution

Posted by malcolmr on October 31st, 2011 · Assignments

I have posted my solution to assignment 3 for you to download.

Exam

Posted by malcolmr on October 30th, 2011 · Uncategorized

The COMP1400 exam is this Thursday (Nov 3) at 8:45am in Leighton Hall of Scientia (but make sure you confirm this on myUNSW).

It is a 2 hour exam. It will consist of:

  • 20 multiple choice questions testing your understanding of various aspects of Java
  • 5 short-answer question on general programming concepts
  • 2 questions which involve reading a long piece of code and answering questions about what it does.

The exam booklet will include print-outs of relevant parts of the Java API website so you do not have to memorise this information.

There are no questions on writing code (they were in the prac-exam).

Good luck.

Loops

Posted by simm on October 16th, 2011 · Uncategorized

To save people constantly looking up how to do loops in the lecture notes, here’s a simple example that prints the numbers 0 to 4 inclusive.

As a for loop:

for(int i=0; i<5; i++) {

System.out.println(i);

}

 

As a while loop:

int i=0;

while(i<5) {

System.out.println(i);

i++;

}

Ass 3 Unit Testing

Posted by malcolmr on October 11th, 2011 · Assignments

It turns out that testing the play() method on your classes is tricker than I had anticipated when I set assignment 3. To test this method properly, you need to set up a game in a known situation, forcing one of the players to play the card you are testing and then check that it does what you expect.
[Read more →]

Prac Exam FAQs

Posted by malcolmr on October 11th, 2011 · Uncategorized

FAQs about the Prac Exam:

Can I bring my laptop?

No. You must use the lab computers.

Can I bring my own files on a USB stick?

Yes.

Will I have access to the web?

Yes, but we will be monitoring your web access to make sure you are not communicating with other students.

Assignment solutions: ass1 & ass2

Posted by malcolmr on October 11th, 2011 · Assignments

My solutions to assignment 1 and assignment 2 are now available for you to download.

Sample Prac Exam

Posted by malcolmr on October 10th, 2011 · Lab

The Prac Exam for COMP1400 will take place in labs in Week 13.

  • Please make sure you turn up to your designated lab time. You will not be allowed to sit the exam at another time.
  • The exam will be open book, so you will have access to the web and any texts you care to bring. We will be monitoring you, however, to make sure you do not communicate with others during the exam.
  • This exam is worth 40% of your final mark.

The questions below are a sample of the kinds of questions you will receive in the test.

[Read more →]

Assignment 3 – Uno

Posted by malcolmr on September 25th, 2011 · Assignments

Due Date: Sunday week 12 (23:59:59 16 October 2011)

Your final assignment is to complete an implementation of the game of Uno. The focus of the assignment is on using inheritance. You will also be required to write unit tests for you code to demonstrate its correctness.

[Read more →]

Tut 10

Posted by malcolmr on September 25th, 2011 · Lab

The following exercises are taken from chapter 8 of the textbook.

Exercise 8.4 Open the project dome-v2. This project contains a version of the DoME application rewritten to use inheritance, as described above. Note that the class diagram displays the inheritance relationship. Open the source code of the DVD class and remove the ‘extends Item‘ phrase. Close the editor. What changes do you observe in the class diagram? Add the ‘extends Item‘ phrase again.

 

Exercise 8.5 Create a CD object. Call some of its methods. Can you call the inherited methods (for example, setComment)? What do you observe about the inherited methods?

 

Exercise 8.6 In order to illustrate that a subclass can access non-private elements of the superclass without any special syntax, try the following slightly artificial modification to the CD and Item classes. Create a method called printShortDetails in the CD class. Its task is to print just the artist and the title of a CD on a line by itself. However, because the titIe field is private in the Item class, it will be necessary to add a public getTitIe method to Item. Call this method from printShortDetails to access the title for printing. Remember that no special syntax is required when a subclass calls a superclass method. Try out your solution by creating a CD object. Implement a similar method in the DVD class to print just the director and title.

 

Exercise 8.8 Open the dome-v2 project. Add a class for games and a subclass for video games to the project. Create some video game objects and test that all methods work as expected.

Database inheritance diagram

 

Exercise 8.12 Assume we have four classes: Person, Teacher, Student and PhDStudent. Teacher and Student are both subclasses of Person. PhDStudent is a subclass of Student.

a. Which of the following assignments are legal, and why or why not?

Person p1 = new Student();
Person p2 = new PhDStudent();
PhDStudent phd1 = new Student();
Teacher t1 = new Person();
Student s1 = new PhDStudent();

b. Suppose that we have the following legal declarations and assignments

Person p1 = new Person();
Person p2= new PerSon ();
PhDStudent phd1 = new PhDStudent();
Teacher t1 = new Teacher () ;
Student s1 = new Student();

Based on those just mentioned, which of the following assignments are legal and or why not?

s1 = p1;
s1 = p2;
p1 = s1;
t1 = st;
s1 = phd1;
phd1 = s1;

 

Exercise 8.13 Test your answers to the previous question by creating bare-bones versions of the classes mentioned in that exercise and trying it out in BlueJ

 

Tutorial 9

Posted by malcolmr on September 15th, 2011 · Lab

JUnit Testing

For the exercises this week, download the diary-testing-junit-v2 project. These examples and exercises are based on chapter 6 of the textbook.

  1. Using the diary-testing-junit-v2 project, create a method in DayTest to check that findSpace returns the value of 10 for a one-hour appointment if a day already has a single one-hour appointment at 9 a.m. You must first create the 9 a.m. appointment, then the 10 a.m appointment. Specify assertions for the results of both calls.
  2. Create a test to check that findSpace returns a value of -1 if an attempt is made to find an appointment In a day that is already full.
  3. Create a test class that has Appointment as its reference class. Record separate test methods within It that check that the description and duration flelds of an Appointment object are initialised correctly following its creation.
  4. Create the following negative test in the DayTest class. Create a Day object, a one-hour Appointment object and a two-hour Appointment object. Make the one-hour appointment at 10 a.m. and then try to make the two-hour appointment at 9 a.m. Since this call to makeAppointment should fail, the value to put into the assertion is false. Now run the test. What is shown in the test results window?