Common Computer Science References
At the end of this lesson, you will be able to:
understand and use properties in a class
basics of OOP
read "Using OOP", Chapter 8, Computer Based Problem Solving
read "Property Members" & "Read only Property Members"
fields need to be declared as "private" so that no one can change them!
return this._age
}
public set age(theAge: number): void {
if (theAge <= 0 || theAge >= 200) {
throw new Error('The age is invalid')
}
this._age = theAge
}Java Getters and Setters
go over the Bicycle Class example:
Bicycle Example - TypeScript
Bicycle Example - Java
continue to re-create the MrCoxallStack from last time:
you already have pushItem(stringItem), now add popItem() -> stringItem
remove the top item and return it
add "getters" and "setters" for each of the fields
it turns out for MrCoxallStack, you currently only have 1 field and it is a list
you should not be able to change it, so remove your showStack() method and make it a getter
do the above in a second language
mr_coxall_stack.py
main.py
output