CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
Abdul
Level 20
Omaha
  • 29.11.2019
  • 1315views
  • 2comments

Please help, i don’t know what i'm doing wrong. I can't seem to be passing the last requirement.

Question about the task Robot wars
Java Core,  Level 3,  Lesson 11
Resolved


1. Familiarize yourself with the code.
2. Accept your fate and keep trying to understand the code.
3. ...
4. Rejoice that you've figured it out.
5. Adapt the code to the following new architecture and add new logic:
5.1. Make the AbstractRobot class abstract. Then move the attack and defend logic from the Robot class to the AbstractRobot class.
5.2. Edit the Robot class to utilize the AbstractRobot class.
5.3. Extend the BodyPart class with a new body part: BodyPart.CHEST.
5.4. Add the new body part to the implementation of the CanAttack and CanDefend interfaces (in the AbstractRobot class).

Requirements:
  • The AbstractRobot class must be abstract.
  • The AbstractRobot class must implement the CanAttack and CanDefend interfaces.
  • The Robot class must inherit the AbstractRobot class.
  • The logic defining the how a Robot behaves must be in the AbstractRobot class.
  • The BodyPart class must have and initialize a final static BodyPart variable called CHEST.
  • The new body part must be added to the logic for the attack and defend methods in the AbstractRobot class.
package com.codegym.task.task13.task1328; /* Robot wars */ public class Solution { public static void main(String[] args) { Robot amigo = new Robot("Amigo"); Robot enemy = new Robot("Enemy"); doMove(amigo, enemy); doMove(amigo, enemy); doMove(enemy, amigo); doMove(amigo, enemy); doMove(enemy, amigo); doMove(amigo, enemy); doMove(enemy, amigo); doMove(amigo, enemy); } public static void doMove(Robot robotFirst, Robot robotSecond) { BodyPart attacked = robotFirst.attack(); BodyPart defended = robotFirst.defend(); System.out.println(String.format("%%s attacked %s: its %s was attacked, and its %s was defended", robotFirst.getName(), robotSecond.getName(), attacked, defended)); } }
+1
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Guadalupe Gagnon
Level 37 , Tampa, United States
29 November 2019, 16:35solution
"5.1. Make the AbstractRobot class abstract. Then move the attack and defend logic from the Robot class to the AbstractRobot class." It looks like you just copied the logic to the AR class and didn't move it.
+3
Abdul
Level 20 , Omaha, United States
30 November 2019, 04:23
Got it, thanks.
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.