|
|
|
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.
-
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'.
- 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.6 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:
| a | b | require |
| T | T | F |
| T | F | T |
| F | T | T |
| F | F | F |
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 containing a single new class, called Modifier. It has no attributes.
Create a method in this class called charToUpper(). This should use the signature (heading) of:
public char charToUpper(char ch)
and should do the following. It should take in, as a parameter 'ch', a valid alphabetic character, upper or lower-case. It should return, as its result, the character
'ch' converted into the equivalent upper-case character. If 'ch' is not alphabetic then return it unconverted.
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; |
In addition to the conversion, to assist in testing the method, it should also print out the character parameter value coming in and the character produced as the method's result.
Create a Modifier object and run its charToUpper method. Test it with an appropriate set of character data.
| In your portfolio, provide a printout of your class' code and a table showing the values used to test your work (both input value and the expected output). |
(not from Barnes and Kolling)
|