Here\'s provided class Question 3: Wool Farming (40 points) For this question, y
ID: 3803217 • Letter: H
Question
Here's provided class
Question 3: Wool Farming (40 points) For this question, you will write several classes, and then create and use instances of those classes in order to simulate a sheep farm. (a) (7 points) Write a class Dog. A Dog has the following private attributes A string name breed. A String The dog class also contains the following public methods: A constructor that takes as input the name and breed of the dog getName which returns the name of the dog A herd method that returns the number of sheep the dog can herd. This will depend on the type of dog doing the herding. All dogs of the Collie breed can herd 20 sheep, while all Shepherds can herd 25 sheep. Kelpies and Teruvens can each herd up to 30 sheep. All other breeds of dogs can herd 10 sheep. For example, a Dog of breed White Shepherd or belgian shepherd, or just shepherd would be able to herd 25 sheep Hint: Think about you can use the toLowerCase C) and contains() methods to do this check in a case-insensitive manner. (b) (8 points) Write a class Sheep. A Sheep has the following private attributes A string name An int age A boolean hasWoolExplanation / Answer
Answer
a
Below is the required code:
class Dog
{
private:
String name;
String breed;
public Dog()
{
name = "";
breed = "";
}
public String getName()
{
System.out.println("Enter the name of the dog::");
this.name = Scanner.nextline();
return name;
}
public int herd()
{
int herd_size=0;
System.out.println("Enter the breed of the dog::");
this.breed = Scanner.nextline();
if(breed == "Collie")
herd_size = 20;
else if(breed == "Shepherds")
herd_size = 25;
else if(breed == "Teruvens")
herd_size = 30;
else
herd_size = 20;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.