From the course: Learning Groovy
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Challenge: Creating and using a class - Groovy Tutorial
From the course: Learning Groovy
Challenge: Creating and using a class
(upbeat music) - [Instructor] In this chapter, we covered a lot of ground. We learned how to define variables with static and dynamic typing. Moreover, we talked about creating classes equipped with methods. Finally, we discussed how to implement conditional logic and how to handle error situations. It's time to put our knowledge into practice. For this challenge, I want you to implement the functionality of a calculator. Create a new class for the calculator and expose methods for each of the common operations, addition, subtraction, multiplication and division. Each method should allow two parameters of type integer. Choose a return type appropriately. Try to think about potential error conditions that might arise. One particular case I'd like you to handle is division by zero. Put appropriate conditional logic into place to cover the use case. Once the internals of the calculator class have been created, add a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Groovy and Java3m 21s
-
(Locked)
Variables and data types2m 54s
-
Classes and methods2m 46s
-
(Locked)
Conditional structures and loops2m 51s
-
(Locked)
Exception handling2m 35s
-
(Locked)
Using the GDK documentation2m 25s
-
(Locked)
Challenge: Creating and using a class1m 37s
-
(Locked)
Solution: Creating and using a class7m 10s
-
-
-