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...
using System; using System.Data.SqlTypes; using System.Globalization; using System.Reflection.Metadata.Ecma335; using System.Runtime.Intrinsics.X86; using System.Security.Cryptography.X509Certificates; namespace ConsoleApp4 { class...
using System; using System.Data.SqlTypes; using System.Globalization; using System.Reflection.Metadata.Ecma335; using System.Runtime.Intrinsics.X86; using System.Security.Cryptography.X509Certificates; namespace ConsoleApp4 { class Program { static void Main(string[] args) { AO function = new AO(1000, 3); function.Find(); } } class AO { public a(long _max , long _least) { max = _max; least = _least; numm = new long[1000]; } public long max; public long least; public long[] numm; public long Find() { long per =0; long sum = 0; for(int i=1; i<=max; i++) {    for(int...
I need the following problem to be coded in python without using Numpy: Given input features...
I need the following problem to be coded in python without using Numpy: Given input features x1​, x2​,..., xi​ and corresponding weights w0​, w1​, w2​,...wi​. Write a function, called 'Perceptron', that returns the output value yi. For your function, use the following perceptron activation function: g(X,W)={1 if wTx>0;0 otherwise} The inputs X and W will be arrays of the input feature and weight values, respectively. All values will be integers. Your function will return gp​(X,W), which is a single integer...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT