Skip to main content
added 67 characters in body
Source Link
Mark Bluemel
  • 1.6k
  • 1
  • 6
  • 10

I'm not sure how to approach this. You say you've been assigned a problem, so this feels very much like coursework/homework.

Assuming this homework is to be assessed, it's more helpful for the assessor to see your work than mine - they will then know how successful the tuition has been, and where your understanding needs more work.

On that basis I'm not going to give an alternative solution, but will make some general comments.

The intent of the question is clearly for you to show that you've grasped Object-oriented concepts, in Java terms, such as encapsulation, inheritance, polymorphism and so on. The assignment naturally lends itself to such an approach, but your solution largely misses the point in so many ways that I wonder whether you've been taught anything at all about these concepts.

Here's a few points to think about, and review in your learning material.

  1. An instance of an Animal knows how what color it is. It also knows many legs (and possibly wings) it has. What does that tell you about the move() method? (Keyword: Encapsulation.)
  2. Any Animal - whether Cat, Bug or Bird - has legs and a color. (Keyword: Inheritance - you probably should also review the concept of public/protected/private fields and methods.).
  3. Cats, Bugs and wingless Birds all move in the same way, but Birds with wings move differently. (Keyword: Polymorphism)
  4. What does "return a string" mean? Is that what you are doing?

I would suggest you review these points, and rework your code in line with your (hopefully improved) understanding of them. If you'd care to show us your revised code, please don't edit the original post but instead post your updated code as an answer or perhaps a new question.

I'm not sure how to approach this. You say you've been assigned a problem, so this feels very much like coursework/homework.

Assuming this homework is to be assessed, it's more helpful for the assessor to see your work than mine - they will then know how successful the tuition has been, and where your understanding needs more work.

On that basis I'm not going to give an alternative solution, but will make some general comments.

The intent of the question is clearly for you to show that you've grasped Object-oriented concepts, in Java terms, such as encapsulation, inheritance, polymorphism and so on. The assignment naturally lends itself to such an approach, but your solution largely misses the point in so many ways that I wonder whether you've been taught anything at all about these concepts.

Here's a few points to think about, and review in your learning material.

  1. An instance of an Animal knows how what color it is. It also knows many legs (and possibly wings) it has. What does that tell you about the move() method? (Keyword: Encapsulation.)
  2. Any Animal - whether Cat, Bug or Bird - has legs and a color. (Keyword: Inheritance - you probably should also review the concept of public/protected/private fields and methods.).
  3. Cats, Bugs and wingless Birds all move in the same way, but Birds with wings move differently. (Keyword: Polymorphism)

I would suggest you review these points, and rework your code in line with your (hopefully improved) understanding of them. If you'd care to show us your revised code, please don't edit the original post but instead post your updated code as an answer or perhaps a new question.

I'm not sure how to approach this. You say you've been assigned a problem, so this feels very much like coursework/homework.

Assuming this homework is to be assessed, it's more helpful for the assessor to see your work than mine - they will then know how successful the tuition has been, and where your understanding needs more work.

On that basis I'm not going to give an alternative solution, but will make some general comments.

The intent of the question is clearly for you to show that you've grasped Object-oriented concepts, in Java terms, such as encapsulation, inheritance, polymorphism and so on. The assignment naturally lends itself to such an approach, but your solution largely misses the point in so many ways that I wonder whether you've been taught anything at all about these concepts.

Here's a few points to think about, and review in your learning material.

  1. An instance of an Animal knows how what color it is. It also knows many legs (and possibly wings) it has. What does that tell you about the move() method? (Keyword: Encapsulation.)
  2. Any Animal - whether Cat, Bug or Bird - has legs and a color. (Keyword: Inheritance - you probably should also review the concept of public/protected/private fields and methods.).
  3. Cats, Bugs and wingless Birds all move in the same way, but Birds with wings move differently. (Keyword: Polymorphism)
  4. What does "return a string" mean? Is that what you are doing?

I would suggest you review these points, and rework your code in line with your (hopefully improved) understanding of them. If you'd care to show us your revised code, please don't edit the original post but instead post your updated code as an answer or perhaps a new question.

Source Link
Mark Bluemel
  • 1.6k
  • 1
  • 6
  • 10

I'm not sure how to approach this. You say you've been assigned a problem, so this feels very much like coursework/homework.

Assuming this homework is to be assessed, it's more helpful for the assessor to see your work than mine - they will then know how successful the tuition has been, and where your understanding needs more work.

On that basis I'm not going to give an alternative solution, but will make some general comments.

The intent of the question is clearly for you to show that you've grasped Object-oriented concepts, in Java terms, such as encapsulation, inheritance, polymorphism and so on. The assignment naturally lends itself to such an approach, but your solution largely misses the point in so many ways that I wonder whether you've been taught anything at all about these concepts.

Here's a few points to think about, and review in your learning material.

  1. An instance of an Animal knows how what color it is. It also knows many legs (and possibly wings) it has. What does that tell you about the move() method? (Keyword: Encapsulation.)
  2. Any Animal - whether Cat, Bug or Bird - has legs and a color. (Keyword: Inheritance - you probably should also review the concept of public/protected/private fields and methods.).
  3. Cats, Bugs and wingless Birds all move in the same way, but Birds with wings move differently. (Keyword: Polymorphism)

I would suggest you review these points, and rework your code in line with your (hopefully improved) understanding of them. If you'd care to show us your revised code, please don't edit the original post but instead post your updated code as an answer or perhaps a new question.