110CT: Lecture 9a Portfolio Questions 2008-9

 
 
Portfolio Requirements
These exercises are mostly based on material covered in a range of previous lectures. There are a couple of new concepts introduced though.

 

  • 9a.1: no project

    Re-run the 'object types' demo from CUOnline.

    1. At the end of the sequence, what colour would be the result returned by objectA.getColor(); Explain, carefully, why this is the case. Ensure you use the OOP terms 'object', 'instantiation' (or 'instance'), 'attribute' and 'state'.
    2. Go back to your answer to portfolio 2.3. Explain why the question asked you to set up a new attribute window2 and not just re-use window. If you are not sure, alter your project so it DOES re-use window and then change the colour of the right window to, say, blue.

    In your portfolio include answers to both questions.

    (not from Barnes and Kolling)

  •  

  • 9a.2: no project

    In portfolio 5.7 you were asked to produce a logical expression which evaluated to true/false in specified situations. As a truth table this question can be expressed as follow:

    abrequire
    a||b
    TTT
    TFT
    FTT
    FFF

    Some students submitted (a == b) as a solution. Create a truth table to check whether this is a correct answer. Is it correct?

    In your portfolio include your truth table and an answer.

    (not from Barnes and Kolling)

  •  

  • 9a.3: no project

    Complete CU BlueJ tutorial 7 about creating a new project.

    Create a new project. Create a Die class, copied intact from the ScissorsPaperStone project. Create another class, called RandomLetter. RandomLetter should have an attribute, a Die object. When a RandomLetter object is created, its constructor should create a 6-sided Die object and assign that to its Die attribute. By using this a RandomLetter object can create a random number 1-6.

    Create a method, with the signature:

    private void  createRandomLetter()
    
    which firstly creates a random number 1-6 and then converts that to the appropriate character, A-F, respectively. The random letter should be stored in an attribute of the object.

    Write a print method which prints out the current random letter: it does not generate a new one.

    Character values
    Don't forget, a char is written in single-quotes, eg 'x'.

    Each character has a numeric value: A-Z are 65-90 and a-z are 97-122. You can convert from char form into the equivalent numeric code using a 'cast' eg (int) ch; and, in reverse, from an integer to a char using, for example, (char) value;

    To check out how this works, in the CodePad type (char)((int) 'x' -32) and it'll compute to 'X'

    Create a RandomLetter object and run its methods, enough to demonstrate that they seem to work in all circumstances.

    In your portfolio, provide a printout of your class' code. Since there is no input required for this question you cannot generate test input data. However you can log your actions and the output received, as evidence that it appears to work.

    (not from Barnes and Kolling)

 

Index | Previous | Next

 

Last modified: 22 Dec 2008
Webpage: © Lisa Payne, Coventry University, 2006-8
Exercises and projects: © Barnes and Kolling