CodeGym
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
Shadow
Level 7
Hogsmead
  • 12.09.2020
  • 266views
  • 2comments

hellppp!!!!

Question about the task Getters and setters for the Dog class
Java Syntax,  Level 5,  Lesson 5
Under discussion

Create the Dog class. The dog should have a String name and int age.
Create getters and setters for all the variables of the Dog class.

Requirements:
  • The program must not read data from the keyboard.
  • The Dog class must have a String variable name.
  • The Dog class must have an int variable age.
  • The class must have a setter for the variable name.
  • The class must have a getter for the variable name.
  • The class must have a setter for the variable age.
  • The class must have a getter for the variable age.
package com.codegym.task.task05.task0503; /* Getters and setters for the Dog class */ public class Dog { private String name; private int age; public Dog (String name ,int age) { this.name = name; this.age = age; } public void setName(String name){ this.name = name; } public String getName(){ return name; } public void setAge(int age){ this.age = age; } public int getAge(){ return age; } public static void main(String[] args) { Dog d1 = new Dog(); d1.setName("smse"); d1.setAge(8); Dong d3 = new Dog(); d3.setName("Prince"); d3.setAge(9); System.out.println(d1.getName()); System.out.println(d1.getAge()); System.out.println(d2.getName()); System.out.println(d2.getAge()); } }
0
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Cosmos
Level 10 , Paris, France
12 September 2020, 20:09
You only need to creat getter and setters
0
Cosmos
Level 10 , Paris, France
12 September 2020, 20:07
You d’ont need to creat the constructor, remove it. public Dog (String name ,int age) { this.name = name; this.age = age; } And remove this Dog d1 = new Dog(); d1.setName("smse"); d1.setAge(8); Dong d3 = new Dog(); d3.setName("Prince"); d3.setAge(9); System.out.println(d1.getName()); System.out.println(d1.getAge()); System.out.println(d2.getName()); System.out.println(d2.getAge());
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.