|
| 1 | +# [5th problem in the 30-Days-of-Code-Hackerrank Challenge](https://www.hackerrank.com/challenges/30-class-vs-instance/problem?isFullScreen=true) |
| 2 | +## This repository contains the codes, I have been submitting in the 30 Days of Code program by Hackerrank. |
| 3 | + |
| 4 | +## Objective |
| 5 | +In this challenge, we review some basic concepts that will get you started with this series. You will need to use the same (or similar) syntax to read input and write output in challenges throughout HackerRank. |
| 6 | + |
| 7 | +## Task |
| 8 | +Write a Person class with an instance variable,```age``` , and a constructor that takes an integer,```initialAge``` , as a parameter. The constructor must assign ```initialAge``` to ```age``` after confirming the argument passed as ```initialAge``` is not negative; if a negative argument is passed as ```initialAge```, the constructor should set ```age``` to 0 and print ```Age is not valid, setting age to 0.```. |
| 9 | + |
| 10 | +In addition, you must write the following instance methods: |
| 11 | + 1. yearPasses() should increase the ```age``` instance variable by 1. |
| 12 | + 2. amIOld() should perform the following conditional actions: |
| 13 | + - If ```age < 13```, print ```You are young.```. |
| 14 | + - If ```age ≥ 13``` and ```age < 18```, print ```You are a teenager.```. |
| 15 | + - Otherwise, print ```You are old.```. |
| 16 | + |
| 17 | +Note: If you are using a language that doesn't support using for string concatenation (e.g.: C), you can just print one variable immediately following the other on the same line. The string provided in your editor must be printed first, immediately followed by the string you read as input. |
| 18 | +Note: The instructions are Java-based, but we support submissions in many popular languages. You can switch languages using the drop-down menu above your editor, and the variable may be written differently depending on the best-practice conventions of your submission language. |
| 19 | + |
| 20 | +The problem should follow the following format: |
| 21 | +<img src="https://github.com/AdityaSeth777/30-Days-of-Code-Hackerrank/blob/main/4%20-%20Class%20vs.%20Instance/4%20day.png"> |
| 22 | + |
| 23 | +## Explanation |
| 24 | +<img src="https://github.com/AdityaSeth777/30-Days-of-Code-Hackerrank/blob/main/4%20-%20Class%20vs.%20Instance/4%20day%20exp.png"> |
| 25 | + |
| 26 | +## Logic |
| 27 | +It will be updated after uploading all the required details in all the questions in the repo. |
| 28 | + |
| 29 | +## FAQ |
| 30 | +- How to stop the script? Ctrl+C (control+C for Mac) |
| 31 | +- For any other problems, feel free to raise an issue. |
| 32 | + |
| 33 | +## Contributing |
| 34 | +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. |
| 35 | + |
| 36 | +Please make sure to update tests as appropriate. |
| 37 | + |
| 38 | +## License |
| 39 | +[MIT License © Aditya Seth](https://github.com/AdityaSeth777/30-Days-of-Code-Hackerrank/blob/main/License) |
| 40 | + |
| 41 | +## What next ? |
| 42 | +- I will be working on completing this wonderful bunch of programs by Hackerrank, which I will be uploading as well. |
| 43 | +- Along with that, I will be uploading other programs as well including my college assignments and other projects. |
| 44 | + |
| 45 | +## Where to contact ? |
| 46 | + |
| 47 | + |
| 48 | +## 🙋♂️ Support |
| 49 | + |
| 50 | +💙 If you like this project, give it a ⭐ and share it with friends!<br><br> |
| 51 | +[☕ Buy me a coffee](https://www.buymeacoffee.com/adityaseth) |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +Made with ❤️ and C, C++, Python, Ruby, and Kotlin. <br><br> |
0 commit comments