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
fady shaker
Level 7
Stuttgart
  • 21.03.2019
  • 1367views
  • 5comments

what is this bug ?

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

Create the Person class. A person should have a String name, int age, and char sex.
Create getters and setters for all the variables of the Person class.

Requirements:
  • The program must not read data from the keyboard.
  • The Person class must have a public static void main method.
  • The Person class should have 3 variables.
  • The Person class must have a String variable name.
  • The Person class must have an int variable age.
  • The Person class must have a char variable sex.
  • 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.
  • The class must have a setter for the variable sex.
  • The class must have a getter for the variable sex.
package com.codegym.task.task05.task0508; /* Getters and setters for the Person class */ public class Person { //write your code here public static void main(String[] args) { } private String name; private int age ; private char sex; public void Perosn(String name, int age , char sex) { this.name = name; this.age = age; this.sex = sex; } 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 void setsex(char sex) { this.sex = sex; } public char getsex() { return sex; } }
0
Comments (5)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Optimus2000
Level 14 , Abuja, Nigeria
7 May 2020, 20:35
None of your code should be written in the main method. They should be in the person class before the main method! the place where it says write your code here.
+1
parthasarathy t s
Level 6 , Mumbai, India
18 June 2019, 15:51
public class Person { private String name; private int age ; private char sex; /* public void Perosn(String name, int age , char sex) { this.name = name; this.age = age; this.sex = sex; }*/ 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 void setSex(char sex) { this.sex = sex; } public char getSex() { return sex; //write your code here }
0
Emanuele Gurini
Level 18 , Porto Recanati, Italia
22 March 2019, 17:33
Fady, check also line 20: "Perosn"
+1
Oleh
Level 32 , Kyiv, Ukraine
21 March 2019, 14:20
You need to use "camelCase" style for method`s names. Do every word (except first) start with big letter.
0
Oleh
Level 32 , Kyiv, Ukraine
21 March 2019, 14:25
Also you can try "alt + inset" bind for fast getters/setters
+1
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.