Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Final Exam - Assignment3:08 with Amit Bijlani
Here's the assignment for the final for you to implement on your own Xcode playground.
- Create a base class called Shape which will have 2 properties: sides and name
- Create a subclass called Square, it will also have 2 properties called: sideLength and area.
- The area property will be a computed property with getter and setter methods.
- Add a designated initializer to Square which accept all three properties: sides, name and sideLength
- Add a convenience initializer to Square that will accept only the sideLength and provide default values. 4 for sides and “Square” for name
- Create an instance of Square using the convenience initializer
It's that time in the course where we apply everything we have learned so far.
So that you can understand how to put things into practice.
Now I'm going to pose a problem, and
you will have to try to solve it on your own, in your ExCo playground.
And if you can't solve it,
don't worry, because in the next video I'll give you the answer.
I know it's tempting to look ahead at the answer, but
I do encourage you to try your best even if it gets frustrating.
>> All right, so here's your assignment for
your final exam, the last assignment or the final exam in this course.
Create a base class called Shape which will have two properties, sides and name.
It's up to you if you want to make them var or
let, but remember that best practice calls for lets or constants.
You will also have to create designated initializers for
Shape, because you can't just create a class and have properties and
then not have a designated initializer, unless you are providing default values.
Next, create a subclass called Square which will
also have 2 properties called, sideLength and area.
The area property will be a computed property with getter and setter methods.
That's right, it'll have both getter and setter methods.
The area of a square is side square, or in this case, sideLength square.
So when you're creating a setter method, it's basically going to
take that new value and get its square root and assign it to the sideLength.
Next, add a designated initializer to Square which will
accept all three properties, sides, name, and sideLength.
After that, add a convenience initializer to Square that will accept only sideLength
and provide default values, 4 for sides, and square for name.
And finally, create an instance of Square using the convenience initializer.
You can also inspect each one of the individual properties and
also assign a value to the area property to make sure that your
setter method is working as intended.
So, that's it.
That's your final exam.
You have to create two classes.
One is a subclass of the other, and if you ever need to refer to this,
check the teacher's notes,
because this exact same thing is typed out in the teacher's notes.
So, good luck with the assignment, hope you'll give it your best shot.
And if you do get frustrated, don't worry,
in the next video we're going to solve this problem together.
However, I really want you to try this on your own first,
before you peek at the answer, so good luck.
You need to sign up for Treehouse in order to download course files.Sign up