Class Design
. Below is a set of birds and movements they can perform.
Birds:
Penguin:
• hopping: moves 2 ft
• flying: can't fly
Hawk:
• hopping: can't hop
• flying: moves 100 ft; won't fly if World.windSpeed > 40
Robin:
• hopping: moves 1 ft; won't hop if World.temperature < 0
• flying: moves 20 ft; won't fly if World.windSpeed > 20
Crow:
• hopping: moves 1 ft; won't hop if World.temperature < 0
• flying: moves 30 ft; won't fly if World.windSpeed > 25
Requirements:
• Create a class or set of classes in C# to represent the birds.
• Create an instance of each type of bird and add them all into a single collection. Have each bird hop and then fly in turn, each time after the World changes. After all birds have moved, print out the total distance that each one has moved. (See the comments in Main below marked // TODO).
• Fill in main() to generate the desired output (which is shown under main() below).
• Use best design practices. The priority is to create maintainable code.
using System;
using System.Collections.Generic;
namespace PCD
{
public class World
{
public static int temperature = 0; // celcius
public static int windSpeed = 0; // miles per hour
}
public class MainClass
{
static void Main(string[] args)
{
// TODO: create the birds here
World. = 20;
World. temperature windSpeed = 12;
// TODO: have each bird fly & hop
// a storm arrives!
World.temperature = -10;
World.windSpeed = 30;
// TODO: have each bird fly & hop
// TODO: print total distances
}
}
}
Desired output:
The penguin moved 4 ft.
The hawk moved 200 ft.
The robin moved 21 ft.
The crow moved 31 ft.
Questions by musclebai answers by musclebai
Showing Answers 1 - 1 of 1 Answers
Related Answered Questions
Related Open Questions
Class Design
Birds:
Penguin:
• hopping: moves 2 ft
• flying: can't fly
Hawk:
• hopping: can't hop
• flying: moves 100 ft; won't fly if World.windSpeed > 40
Robin:
• hopping: moves 1 ft; won't hop if World.temperature < 0
• flying: moves 20 ft; won't fly if World.windSpeed > 20
Crow:
• hopping: moves 1 ft; won't hop if World.temperature < 0
• flying: moves 30 ft; won't fly if World.windSpeed > 25
Requirements:
• Create a class or set of classes in C# to represent the birds.
• Create an instance of each type of bird and add them all into a single collection. Have each bird hop and then fly in turn, each time after the World changes. After all birds have moved, print out the total distance that each one has moved. (See the comments in Main below marked // TODO).
• Fill in main() to generate the desired output (which is shown under main() below).
• Use best design practices. The priority is to create maintainable code.
using System;
using System.Collections.Generic;
namespace PCD
{
public class World
{
public static int temperature = 0; // celcius
public static int windSpeed = 0; // miles per hour
}
public class MainClass
{
static void Main(string[] args)
{
// TODO: create the birds here
World. = 20;
World. temperature windSpeed = 12;
// TODO: have each bird fly & hop
// a storm arrives!
World.temperature = -10;
World.windSpeed = 30;
// TODO: have each bird fly & hop
// TODO: print total distances
}
}
}
Desired output:
The penguin moved 4 ft.
The hawk moved 200 ft.
The robin moved 21 ft.
The crow moved 31 ft.
Profile Answers by musclebai Questions by musclebai
Questions by musclebai answers by musclebai
Related Answered Questions
Related Open Questions