Course of Raku / Addendum 🆕 / Types and text machines / Objects and classes / Exercises

Which quadrant

Problem

Write a Point class holding x and y, with a method that reports which quadrant the point lies in — first, second, third, or fourth — or that it sits on an axis. Report the points (3, 4), (-2, 5), (-1, -6), and (0, 3).

Example

The program prints:

(3, 4): first
(-2, 5): second
(-1, -6): third
(0, 3): on an axis

Solution

See the solution

Course navigation

Solution: Shapes sharing a role   |   Solution: Which quadrant