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
~mK
Level 7
Princeton, NJ
  • 23.12.2019
  • 891views
  • 2comments

Whats wrong here. It compiles

Question about the task This age doesn't work for me…
Java Syntax,  Level 4,  Lesson 1
Under discussion

Think about what the program is doing.
Fix the programming error so that person.age changes value.

Hint:
carefully review the adjustAge method.

Requirements:
  • The program should display text on the screen.
  • The Person class should have a public int field called age.
  • The Person class's adjustAge method should display text on the screen.
  • The Person class's adjustAge method must have only one int parameter named age, and the method must be void.
  • The main method should call the adjustAge method only once.
  • The Person class's adjustAge method should increase the Person's age by 20.
package com.codegym.task.task04.task0401; /* /* The Person class should have a public int field called age. 3. The Person class's adjustAge method should display text on the screen. 4. The Person class's adjustAge method must have only one int parameter named age, and the method must be void. 5. The main method should call the adjustAge method only once. 6. */ public class Solution { public static void main(String[] args) { Person person = new Person(); person.age = 20; person.adjustAge(person.age); } } class Person { public int age = 20; public void adjustAge(int age) { // The Person class's adjustAge method should increase the Person's age by 20. this.age = this.age + age; System.out.println("Adjusted age: " + this.age); } }
0
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
~mK
Level 7 , Princeton, NJ, usa
27 December 2019, 23:36
Thanks Boss! I know you are helping a lot of us.
+1
Guadalupe Gagnon
Level 37 , Tampa, United States
23 December 2019, 22:44
While you did solve the task, you ended up removing code that should not have been. Reset the tasks and fix only the adjustAge() method. Changes to the starting code, unless specifically told to by the requirements, is one of the more prominent ways that fail tasks. I've done it myself too, so I understand. I will copy and paste my code into a note pad for safe keeping and reset tasks to see if I had made any changes accidentally.
+2
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.