Assignment 2: Classes (and dogs)

Check out the empty repository here and commit your final .cs file to submit.

https://cssvn.utrgv.edu/svn_etomai/201810_3328/assn02_classes/<your username>

Write a console application which implements two classes: Dog and FoodItem.

The Dog class should have the following data members: name and weight.

The FoodItem class should have the following data members: name and calories.

Make sure the data members are private. Access the members using properties.

The Dog class should have the following member methods:

  • eatFood(FoodItem f), a method which increases the dog’s weight by some function of the calories of the food item f. (i.e., eating 1000 calories shouldn’t increase the weight by 1000 lbs.)
  • walk(), a method which reduces the Dog’s weight by some amount.
  • eatDog(Dog d), a method where the Dog eats the Dog d. The Dog’s weight should go up by the weight of Dog d.
  • The FoodItem and Dog classes should both have parameterized constructors. Parameterized constructors are constructors where the data members are passed as parameters, e.g. new FoodItem(Hamburger, 600).

Once the classes have been created, in the main body of the program, create two Dog objects and a FoodItem object. In the console window, do the following:

  1. Show a Dog’s weight and name.
  2. Have that Dog eat a FoodItem
  3. Show the Dog’s weight again
  4. Have the Dog go for a walk to lose weight
  5. Show the Dog’s weight again
  6. Show the second Dog’s weight
  7. Have the first Dog eat the second Dog
  8. Show the first Dog’s weight.

The console output should look something like this: