Skip to main content
edited tags
Link
swap interface tag for homework tag, update title
Link
Dan Oberlam
  • 8k
  • 2
  • 33
  • 74

Does this Model animals using inheritance in Java code for the Socrates Object Oriented problem need any changes or improvements

add tag, formatting of problem description
Source Link
Dan Oberlam
  • 8k
  • 2
  • 33
  • 74

You've gone back in time to 500BC Athens and Socrates wants you to build him an app to help classify animals.

  1. Build the classes Animal, Cat, and Bug.
  2. Define the properties "color" and "leg_number" on the relevant and necessary classes. Have them be initialized within a constructor.
  3. Add the functionality that would allow us to call a method "move" with the Cat and Bug classes. Have the method return a string "I'm moving with " + leg_number + " legs!", with the "leg_number" being leg_number as set on the class.
  4. Add a new class called Bird. Add the property "wing_number". Add the functionality that would allow us to call a method "move" with the Bird class. Have the method return the string "I'm moving with " + leg_number + " legs!" if wing_number doesn't have an applicable value. If wing_number does have an applicable value, return the string "I'm flying".

You've gone back in time to 500BC Athens and Socrates wants you to build him an app to help classify animals.

  1. Build the classes Animal, Cat, and Bug.
  2. Define the properties color and leg_number on the relevant and necessary classes. Have them be initialized within a constructor.
  3. Add the functionality that would allow us to call a method move with the Cat and Bug classes. Have the method return a string "I'm moving with " + leg_number + " legs!", with the leg_number being leg_number as set on the class.
  4. Add a new class called Bird. Add the property wing_number. Add the functionality that would allow us to call a method move with the Bird class. Have the method return the string "I'm moving with " + leg_number + " legs!" if wing_number doesn't have an applicable value. If wing_number does have an applicable value, return the string "I'm flying".

The code works fine. However, I am concerned about whether I should have used an interface or an abstract class instead of a superclasssuper class. I'm not sure I understand how to determine which to use when. If I should have used something different, can you explain and tell me how I should be implementing the move method or the properties?

You've gone back in time to 500BC Athens and Socrates wants you to build him an app to help classify animals.

  1. Build the classes Animal, Cat, and Bug.
  2. Define the properties "color" and "leg_number" on the relevant and necessary classes. Have them be initialized within a constructor.
  3. Add the functionality that would allow us to call a method "move" with the Cat and Bug classes. Have the method return a string "I'm moving with " + leg_number + " legs!", with the "leg_number" being leg_number as set on the class.
  4. Add a new class called Bird. Add the property "wing_number". Add the functionality that would allow us to call a method "move" with the Bird class. Have the method return the string "I'm moving with " + leg_number + " legs!" if wing_number doesn't have an applicable value. If wing_number does have an applicable value, return the string "I'm flying".

The code works fine. However, I am concerned about whether I should have used an interface or an abstract class instead of a superclass. I'm not sure I understand how to determine which to use when. If I should have used something different, can you explain and tell me how I should be implementing the move method or the properties?

You've gone back in time to 500BC Athens and Socrates wants you to build him an app to help classify animals.

  1. Build the classes Animal, Cat, and Bug.
  2. Define the properties color and leg_number on the relevant and necessary classes. Have them be initialized within a constructor.
  3. Add the functionality that would allow us to call a method move with the Cat and Bug classes. Have the method return a string "I'm moving with " + leg_number + " legs!", with the leg_number being leg_number as set on the class.
  4. Add a new class called Bird. Add the property wing_number. Add the functionality that would allow us to call a method move with the Bird class. Have the method return the string "I'm moving with " + leg_number + " legs!" if wing_number doesn't have an applicable value. If wing_number does have an applicable value, return the string "I'm flying".

The code works fine. However, I am concerned about whether I should have used an interface or an abstract class instead of a super class. I'm not sure I understand how to determine which to use when. If I should have used something different, can you explain and tell me how I should be implementing the move method or the properties?

fixed issue with part of problem missing due to greater than and less than signs
Source Link
apex2022
  • 161
  • 1
  • 5
Loading
Source Link
apex2022
  • 161
  • 1
  • 5
Loading