Given the partially coded project:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StaticHW
{ Â Â
class Program
{
static void Main(string[] args)
{
// will have 3 Dogs
Dog[] allDogs = new Dog[3];
allDogs[0] = new Dog(20f, 10f, \"Fido\");
allDogs[1] = new Dog(40f, 20f, \"Percy\");
allDogs[2] = new Dog(70f, 30f, \"Snoopy\");
// comment out the next 3 lines until you have written the Dogclass and the code runs ok
// then put these 3 lines back in after you write your staticclass
Console.WriteLine(\"{0} is healthy: {1}\", allDogs[0].Name,HealthCheck.IsHealthy(allDogs[0]));
Console.WriteLine(\"{0} is healthy: {1}\", allDogs[1].Name,HealthCheck.IsHealthy(allDogs[1]));
Console.WriteLine(\"{0} is healthy: {1}\", allDogs[2].Name,HealthCheck.IsHealthy(allDogs[2]));
Console.ReadLine();
}
}
}
define a class Dog , give it 3 properties:
float Weight
float Height
string Name
write a constructor that takes in a weight, height and name andsets those 3 properties
get the first part of the Main method to work.
Then write a static class named HealthCheck
indside, write a method called IsHealthy that takes in a Dogobject
divide the dog's weight by its height
if the answer is greater than 2, return false, otherwise, returntrue
Output:
Fido is healthy: True
Percy is healthy: True
Snoopy is healthy: False