/
30classvsinstance_17157.cs
46 lines (41 loc) · 1.09 KB
/
30classvsinstance_17157.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*****************************
Code by: David Zentner dazcode@gmail.com
http://www.dazcode.com/
this code is an accepted solution for code challenge located at:
https://www.hackerrank.com/challenges/30-class-vs-instance
this code may need to run in the hackerrank online ide to work correctly
*****************************/
class Person
{
int age;
public void yearPasses()
{
age++;
}
public void amIOld()
{
if (age < 13)
{
Console.WriteLine("You are young.");
}
else if(age>=13 && age<18)
{
Console.WriteLine("You are a teenager.");
}
else
{
Console.WriteLine("You are old.");
}
}
public Person(int initialAge)
{
if (initialAge > 0)
{
age = initialAge;
}
else
{
age = 0;
Console.WriteLine("Age is not valid, setting age to 0.");
}
}