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
Ankita Patra
Level 5
Bhubaneshwar
  • 05.07.2019
  • 756views
  • 3comments

Everything looks fine.Still don't know what's wrong here!!

Question about the task Initializing cats
Java Syntax,  Level 5,  Lesson 7
Under discussion


Create a Cat class with five initializers:
- Name,
- Name, weight, age
- Name, age (standard weight)
- Weight, color (unknown name, address and age, i.e. a homeless cat)
- Weight, color, address (someone else's pet)

The initializer's job is to make the object valid.
For example, if the weight is unknown, then you need to specify some average weight.
A cat can't weigh nothing.
The same applies to age and color.
But there may or may not be a name (i.e. name might be null).
The same applies to the address (it might be null).

Requirements:
  • The program must not read data from the keyboard.
  • The Cat class must have a String variable name.
  • The Cat class must have an int variable age.
  • The Cat class must have an int variable weight.
  • The Cat class must have a String variable address.
  • The Cat class must have a String variable color.
  • The class must have an initialize method that takes a name as an argument, but initializes all variables except the address.
  • The class must have an initialize method that takes a name, weight, and age as arguments, but initializes all variables except the address.
  • The class must have an initialize method that takes a name and age as arguments, and initializes all variables except the address.
  • The class must have an initialize method that takes a weight and color as arguments, and initializes all variables except the name and address.
  • The class must have an initialize method that takes a weight, color, and address as arguments, but initializes all variables except the name.
package com.codegym.task.task05.task0510; /* Initializing cats */ public class Cat { //write your code here private String name ="Mitten"; private String address=null; private String color="white"; private int age=5; private int weight=10; public void initialize(String name) { this.name=name; this.color=color; this.age=age; this.weight=weight; } public void initialize(String name,int weight,int age) { this.name=name; this.age=age; this.weight=weight; this.color=color; } public void initialize(String name,int age){ this.name=name; this.color=color; this.age=age; this.weight=weight; } public void initialize(int weight,String color){ this.weight=weight; this.color=color; this.age=age; } public void initialize(int weight,String color,String address){ this.weight=weight; this.color=color; this.address=address; this.age=age; } public static void main(String[] args) { } }
0
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Martin Adamec
Level 20 , Nachod, Czechia
17 November 2019, 16:01
Name should behave the same way as address (it should be null unless it's passed by the initialize method) in line 10
private String name =null;
0
maciek
Level 8 , Stockholm, Sweden
9 July 2019, 12:30
everything describe in requirements: what is as argument what is as initialize.
0
Nithin
Level 35 , Hyderabad, India
5 July 2019, 15:06
in line 39 you haven't passed "age" as an argument in the method.so in line 43 initialize age with some arbitrary number like
this.age = 10;
because age can't be null as per requirements of this task. similarly for the next method in line 46.
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.