Você está na página 1de 3

Lab 3

Exercise 1
The HelloDogs application presented in the lecture is available on
teachmat. Download the code and make sure you understand every single
line - if something is not clear, go back to the lecture notes. If it is still not
clear, ask a tutor.

A RichTextBox

A Button

Exercise 2
Make the following changes to the HelloDogs application :
a) In the class Dog, add the following private variables:
o dogHeight - an instance variable of integer type (height in cm)
o dogColour an instance variable what type should it be?
o noOfLEgs a class (static) variable
b) In the class Dog, create properties to encapsulate the variables created in
the previous task (a)

Note: Use the wizard (as explained in the lecture)


Hint: the property for the noOfLegs will be static

c) In the class Dog, add a new constructor that takes the following
parameters
o dogHeight
o dogColour
o breed
d) In the class Dog, add a private method called IsBig that returns a Boolean
and takes a parameter of type integer. If that parameter is <50, the method
should return false. Otherwise it should return true
e) In the class Dog, change the method GetSpeech so
o using the method IsBig created in point (d) checks if the dog is big
or not.
o it returns all details about the dog (including dogHeight ,
dogColour). Also, the dog should state if it is big or not.
Hint: It cannot return the noOfLegs as it is a static variable
f) In the class DogChorus, create 2 more dogs (instances of class Dog)
using the constructor you created in point(c)
g) In the class DogChorus, change the GetOutput () method so:
o it returns details of all dogs created including the number of leges
that all dogs have
Hint: you need to call the static NoOfLegs property you
created at point (b) through the class name
h) On your Form1 user interface add 4 textboxes. Through the new
textboxes you should be able to change the instance variables breed,
dogHeight , dogColour and barkSound of a dog.
Add a new button that will create new dogs.
When the button is clicked a new dog instance will be created. This dog
instance will have the details specified in the textboxes. The rich text box
should display the new dogs details, including dogHeight , dogColour,
noOfLegs and if the dog thinks it is a big dog or not.

Exercise 3
Download Classes and Objects Tutorial from teachmat.
Build the temperature converter application as presented in the tutorial. It
should have the extra following classes
Class Conversions
ClassTemperature
Add a new constructor to the class Temperature
Should take 3 parameters:
o double temperature, bool CtoF, DateTime myDate
On the form
add a new control - DateTimePicker- from toolbox
Add a new button
o When clicked create an object of type Temperature for which you
can pass other days than today though the DateTimePicker
o Add the temperatures to your log.

Optional Exercise
In class Conversions you have 2 methods, each with one parameter. By
default, the parameters are value type. Change them to ref type and see what
impact it has on the program.