Question

In: Computer Science

Given the partially coded project: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace...

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 Dog class and the code runs ok
// then put these 3 lines back in after you write your static class
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 and sets 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 Dog object
divide the dog's weight by its height
if the answer is greater than 2, return false, otherwise, return true

Output:

Fido is healthy: True

Percy is healthy: True

Snoopy is healthy: False

Solutions

Expert Solution

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 Dog class and the code runs ok
    // then put these 3 lines back in after you write your static class
    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();
    }
}
public class Dog
{
    public float Weight;
    public float Height;
    public string Name;
    public Dog(float weight,float height,string name)
    {
        Weight=weight;
        Height= height;
        Name= name;
    }
    
}
public static class HealthCheck{
    
     public static bool IsHealthy(Dog obj)
    {
        float temp= obj.Weight/obj.Height;
        if(temp>2.0)
        return false;
        else
        return true;
        // Console.WriteLine(obj.Name);
        // if()
        
    }
}


}

Related Solutions

Patient.cs : //namespace using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //application namespace namespace...
Patient.cs : //namespace using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //application namespace namespace ConsoleApp_Patient { class Patient //C# class { //private fields for patientid, lastname,firstname, age, and email. private int patientid; private string lastname; private string firstname; private int age; private string email; //public data items for each of these private fields with get and //set methods public int PatientID //Public field for patientid { get { return patientid; } set { patientid = value;//set patinetid }...
Patient.cs : //namespace using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //application namespace namespace...
Patient.cs : //namespace using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //application namespace namespace ConsoleApp_Patient { class Patient //C# class { //private fields for patientid, lastname,firstname, age, and email. private int patientid; private string lastname; private string firstname; private int age; private string email; //public data items for each of these private fields with get and //set methods public int PatientID //Public field for patientid { get { return patientid; } set { patientid = value;//set patinetid }...
Given code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public...
Given code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class Car { // fields private decimal _CurrentSpeedMPH; // the cars current speed private decimal _MaxSpeedMPH; // the upper limit, the car cannot exceed this value private bool _EngineRunning; // true means the engine has been started and is running, false says engine is off public Car(decimal maxSpeed) // constuctor, user chooses to set maxSpeed as they create the object { _MaxSpeedMPH = maxSpeed;...
Given Codes: Program.cs & Car.cs Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;...
Given Codes: Program.cs & Car.cs Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ClassLibrary1; namespace ConsoleCarsExcpeptions { class Program { static void Main(string[] args) { Car myCar = new Car(35); // call constructor and set speed max to 35 (tiny engine!!) string ErrorMessage = "All is well"; bool done = false; // loop control variable while (!done) { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("start = start engine, stop = stop engine"); Console.Write("accel = accelerate, brake = brake,...
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Assignment07 { class Dog { public void...
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Assignment07 { class Dog { public void bark(string dogsName) { int barking =5; while(barking < 5)    Console.WriteLine(dogsName + " is barking"); } public void run(string dogsName) { int running = 10; while(running > 10) Console.WriteLine(dogsName + " is running"); } } class Program { static void Main(string[] args) { Dog fido = new Dog(); fido.bark("Fido"); fido.run("Fido"); Console.Write("Hit any key to close"); Console.ReadKey(true); } } } need to create 2 while...
Question 1 Given the program below, what are the errors. #include <iostream> using namespace std; int...
Question 1 Given the program below, what are the errors. #include <iostream> using namespace std; int main() { int ind_square(int &); int x, *p; x=15; p = &x; ind_square(*p); } int ind_square(int &p) { *p = *p **p; } Question 1 options: C. No return for non-void function A. Indirection for the variables in ind_square requires pointer operand A and B B. Invalided use of address (&) symbol as a parameter for ind_squared A and C Question 2 Which statement...
C++ Given Code: #include <iostream> #include <string> using namespace std; int main() { //declare variables to...
C++ Given Code: #include <iostream> #include <string> using namespace std; int main() { //declare variables to store user input bool cont = true; //implement a loop so that it will continue asking until the user provides a positive integer // the following provides ONLY part of the loop body, which you should complete { cout <<"How many words are in your message? \n"; cout <<"Enter value: "; // get user input integer here    cout <<"\nInvalid value. Please Re-enter a...
NETWORK SYSTEM MANAGEMENT. Given the following attributes in a project management:  Project scope & feasibility...
NETWORK SYSTEM MANAGEMENT. Given the following attributes in a project management:  Project scope & feasibility  Documentation  Project planning  Testing and piloting  Risk minimisation Discuss briefly each of them and on how would you use them as the IT manager for the company. Provide a details information support your discussion. Remarks: Total 50 Marks for this questions.
Q1 ) i) A project of room temperature measurement system is given to you; in which...
Q1 ) i) A project of room temperature measurement system is given to you; in which you need to design every component of the measurement system. In connection to that, draw the block diagram of the temperature measurement system using passive transducer indicating all the essential elements with input and output of each element. Consider the calibration ratio of (5:1/5) in the display in order to fetch the output. ii) Analyze the reason, why DC wheat stone bride is not...
In this exercise, you will be given a system with their input/output relationships. Using MATLAB, determine...
In this exercise, you will be given a system with their input/output relationships. Using MATLAB, determine whether the system below are a) linear/non-linear b) time-invariant/timevariant, c) causal/noncausal, d) has memory/memoryless: y[n] = x2[n] Provide MATLAB code and graphs to show your work for the linearity and time-invariance testing
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT