Hi everyone!
I have a method which I want to calculate a quality of a ball. A man has 3 pets: a dog, a cat and a puppy. he has a red ball he throws to one of his pets. if the pet owner throw the ball to the dog, I want the ball quality to lower by 2 but if it is the puppy the quality will lower only by 1. when the ball quality is 0 then the pet owner has to buy a new ball. interact(in ball: ball) method has to be in the Dog and the Puppy class
UML for the ball
BALL
-color : string
-quality : int
+Ball(int string: color =“red”)
+lower_quality(int tal: int)
+ToString() : string
class Ball
{
private string color;
private int quality;
public string Color { get => color; set => color = value; }
public Ball(string _color)
{
color = _color;
}
public void Lower_quality(int _quality)
{
quality = 100;
quality = _quality;
Console.WriteLine( quality);
}
public override string ToString()
{
return string.Format("The ball is " + Color);
}
}
class Petowner
{
private int joppesAge;
private List<Animal> pets = new List<Animal>();
private string animal;
private string favoriteFood;
Ball ball = new Ball("Red");
public void AddPet()
{
pets.Add(new Dog(3, "Max", "Beef", "Siberian husky"));
pets.Add(new Cat(1, "Tara", "Fish", "Perser"));
pets.Add(new Puppy(0, 4, "Cherry", "Chicken", "Pomeranian"));
}
public virtual void CheckOnBall()//Idon't know how to do it. Help!
{
ball.Lower_quality(100);
Console.ReadKey();
}
}
class Dog : Animal
{
public Dog(int petAge, string petName, string favoriteFood, string breed) : base(petAge, petName,
favoriteFood, breed)
{
}
public interact(in ball : ball)//?????
public override string ToString()
{
return string.Format(petName + " is" + petAge + " years old and is a " + breed + ". " +
petName + "s favorite food is " + favoriteFood + ".");
}
}
}
class Puppy : Dog
{
private int puppyAgeByMounth;
public Puppy(int petAge, int puppyAgeByMounth, string petName, string favoriteFood, string
breed) : base(petAge, petName, favoriteFood, breed)
{
this.puppyAgeByMounth = puppyAgeByMounth;
}
public int PuppyAgeByMounth
{
get { return puppyAgeByMounth;}
set { puppyAgeByMounth = value;}
}
public interact(in ball: ball)//????
public override string ToString()
{
return string.Format(petName + " is " + puppyAgeByMounth + " mounths and is " + breed +
". " + petName + "s favorite food is " + favoriteFood + ".");
}
}