CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Start learning now
  • All questions
Denis
Level 22
Kharkiv
  • 26.06.2019
  • 858views
  • 1comment

Help me pls

Question about the task OOP: Fix inheritance problems
Java Core,  Level 5,  Lesson 2
Under discussion

Correct the containsBones method and all associated logic so that:
1. The program's behavior remains the same.
2. The containsBones method must return an Object and the value "Yes" instead of true, and "No" instead of false

Requirements:
  • The BodyPart class's containsBones method must return an Object.
  • The Finger class must be a descendant of the BodyPart class.
  • The Finger class's containsBones method must return an Object.
  • The BodyPart class's containsBones method should return "Yes".
  • The Finger class's containsBones method should return "Yes" if the BodyPart class's containsBones method returns "Yes" and the isArtificial flag is false. If this condition is not satisfied, then return "No".
  • The BodyPart class's toString method should return a string formatted as follows "<name> (name of the body part) contains bones" if the containsBones method returns "Yes" for the body part. If it returns "No", then the string should be formatted as "<name> (name of the body part) does not contain bones".
package com.codegym.task.task15.task1505; import javax.print.DocFlavor; import java.util.ArrayList; import java.util.List; public class Solution { public static interface LivingPart { Object containsBones(); } public static class BodyPart implements LivingPart { private String name; public BodyPart(String name) { this.name = name; } public Object containsBones() { return "Yes"; } public String toString() { String visszater = null; containsBones().equals("Yes") ? visszater = name + " contains bones" : visszater = name + " does not contain bones"; } } public static class Finger extends BodyPart { private boolean isArtificial; public Finger(String name, boolean isArtificial) { super(name); this.isArtificial = isArtificial; } public String containsBones() { if (super.containsBones() == "Yes" && !isArtificial) return "Yes"; return "No"; } } public static void main(String[] args) { printlnFingers(); printlnBodyParts(); printlnLivingParts(); } private static void printlnLivingParts() { if(new BodyPart("Hand").containsBones().equals("Yes")) System.out.println("Yes"); else System.out.println("No"); } private static void printlnBodyParts() { List<BodyPart> bodyParts = new ArrayList<BodyPart>(5); bodyParts.add(new BodyPart("Hand")); bodyParts.add(new BodyPart("Leg")); bodyParts.add(new BodyPart("Head")); bodyParts.add(new BodyPart("Body")); System.out.println(bodyParts.toString()); } private static void printlnFingers() { List<Finger> fingers = new ArrayList<Finger>(5); fingers.add(new Finger("Thumb", true)); fingers.add(new Finger("Forefinger", true)); fingers.add(new Finger("Middle finger", true)); fingers.add(new Finger("Ring-finger", true)); fingers.add(new Finger("Pinky", true)); System.out.println(fingers.toString()); } }
0
Comments (1)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Guadalupe Gagnon
Level 37 , Tampa, United States
14 November 2019, 19:11
!
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.