Lektion 6: lösningsförslag
- static bool CanBecomePresident(string country, int age, int elected)
- {
- return country == "USA" && age >= 35 && elected <= 1;
- }
- static bool IsWarm(double temperature)
- {
- return temperature >= 18 && temperature <= 26;
- }
- static bool IsQuiet(double volume)
- {
- return volume <= 45;
- }
- static bool IsHabitable(double temperature, double volume)
- {
- return IsWarm(temperature) && IsQuiet(volume);
- }
- class Person1
- {
- public string FirstName;
- public string LastName;
- public int Age;
- public double Income;
- }
- static string FullName(Person1 p)
- {
- return p.FirstName + " " + p.LastName;
- }
- static bool CanMarry(Person1 p)
- {
- return p.Age >= 18;
- }
- static double FederalIncomeTaxRate(Person1 p)
- {
- if (p.Income <= 438900)
- {
- return 0;
- }
- else if (p.Income <= 638500)
- {
- return 0.2;
- }
- else
- {
- return 0.25;
- }
- }
- class Person2
- {
- public string Name;
- public int Age;
- public double Wealth;
- public double Salary;
- }
- static void PaySalary(Person2 p)
- {
- p.Wealth += p.Salary;
- }
- static void WinLottery(Person2 p)
- {
- p.Wealth += 10000;
- }
- static void CelebrateBirthday(Person2 p)
- {
- p.Age += 1;
- p.Wealth += 500;
- }
- static void ShowPerson(Person2 p)
- {
- Console.WriteLine(p.Age + "-åriga " + p.Name + " har en lön på " + p.Salary + " kronor och " + p.Wealth + " kronor på banken.");
- }
- static bool IsLarge(string s)
- {
- return s.Length > 50;
- }
- static bool IsLarge(int i)
- {
- return i > 1000;
- }
- class Person3
- {
- public double Height;
- }
- static bool IsLarge(Person3 p)
- {
- return p.Height > 190;
- }