Pets need people

  • 3
  • Locked
"You become responsible forever for what you've tamed," said Antoine de Saint-Exupery through the mouth of the Little Prince's fox friend. Let's clean up our program and not leave any animal without a caregiver. We'll create a cat, a dog, and a fish. And a woman. And then we'll assign her as the owner of the fish, dog, and cat. We think she'll like this!
You can't complete this task, because you're not signed in.
Comments (40)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Dav
Level 2 , United States of America
27 June, 15:58
completed it by trial and error and the hints in the comments. I feel that I am missing some base knowledge in my mental model of variable declaration/initialization/connection. Otherwise it would have been apparent. It is possible it is knowledge gained through repetition. Which I hope it is otherwise will be a weakness in the future. :(
Jeff Kenney
Level 3 , United States
3 December 2021, 05:39
Okay, I got it. It took me a couples of tries, but when I figured it out, it's actually pretty simple. Hint: You can name each animal object whatever you want AS LONG AS the "Woman" object is listed FIRST 😉👍 Example: Cat fuzzy = new Cat(); fuzzy.owner = ownername; OR Cat.whiskers = new Cat(); whiskers.owner = ownername; See the pattern? 😉👌 Hint 2: Woman object only needs a name. Example: Woman beth = new Woman(); OR Woman sarah = new Woman();
Anonymous #10829459
Level 2 , Spain
15 October 2021, 15:46
lo primero es poner los objetos despues dejas espacio y debajo de todos los objetos poner las variables.. las tipo el perro es de la woman o dog.owner=woman... ojala les sirva yo me rompi el cerebro
Nuhazet
Level 4 , Santa Cruz de Tenerife, Spain
23 April, 08:13
Estaba asignado mal la propiedad, gracias amigo! Esta no se me olvida, buena rotura de cerebro
Harvey Roberts
Level 9 , Helsinki, Finland
26 August 2021, 06:15
Cought me out six times b4 I realised I had to create the woman first. Doh!
Luke
Level 5 , Brisbane, Australia
3 April 2021, 09:32
I wish there was a way to block the pop ups after verification.
Joe M
Level 41 , Owings Mills, United States
27 August 2020, 20:49
1) create a new Woman, save with a variable name, her name 2) create a new Cat, save with the cat's name 3) catname.owner = woman's name 4) create a new Dog, save with dog's name 5) dogname.owner = woman's name 6) create a new fish, save with fish name 7)fishname.owner = woman's name That's it. don't touch anything but the main method.
Raunak Adhikari
Level 12 , India
12 August 2020, 12:52
it is easy....first make the 4 objects.....then assign them to the owners...let me give you and example... Elephant elephant = new Elephant(); Man man = new Man(); elephant.owner = man; eazy peasy....
Liliane Top
Level 17 , Amsterdam, Netherlands
5 February 2020, 13:14
I don't understand what we're actually doing here. Are we assigning a value of a variable to a class?? when using dog.owner = woman;
Anonymous #10772950
Level 8 , Delhi
5 August 2021, 09:12
What you're doing here is assigning a value to a variable. Here dog is an object and inside it is a variable called 'owner'. If you examine the code for the class Dog you will find a variable called 'owner' declared there which is of a type Woman. So when you create the dog object, it automatically has a variable called 'owner' inside it (as Objects contain whatever is there in the class they are born from). It is this variable dog.owner that has to be given a value, so effectively you are setting the value of this 'owner' variable to woman when you type dog.owner = woman;
Richard Morris
Level 3 , Pittsburgh, United States
4 February 2020, 04:00
The Woman object is woman. Make woman the owner of the animals. That is the solution.
Henry Mendel
Level 4 , Galactic Rush, Israel
19 January 2020, 16:26
WHATS WRONG WITH THIS? package com.codegym.task.task02.task0213; /* Pets need people */ public class Solution { public static void main(String[] args) { Cat cat = new Cat(); Dog dog = new Dog(); Fish fish = new Fish(); Women women = new Women(); cat.owner = women; dog.owner = women; fish.owner = women; } public static class Cat { public Woman owner; } public static class Dog { public Woman owner; } public static class Fish { public Woman owner; } public static class Woman { } }
Henry Mendel
Level 4 , Galactic Rush, Israel
19 January 2020, 16:41
got my answer it was just a typo error Thanks