CodeGym /Courses /New Java Syntax /Practice creating objects

Practice creating objects

New Java Syntax
Level 10 , Lesson 2
Available

"Hi, Amigo! Here are some tasks that involve creating classes and objects."

10
Task
New Java Syntax, level 10, lesson 2
Locked
Cat carnage (1)
You have an empty Cat class created by students at the secret CodeGym lab. A cat (Cat class) must have a name (String name), age (int age), weight (int weight), and strength (int strength).
10
Task
New Java Syntax, level 10, lesson 2
Locked
Cat carnage (2)
Your job is to realize cats in the flesh — in the image and likeness of the Cat class, or more accurately, using it as a template. The number of cats shall be three. Fill these three with life, or in other words, specific data.
10
Task
New Java Syntax, level 10, lesson 2
Locked
Cat carnage (3)
Implement the boolean fight(Cat anotherCat) method: think up a mechanism for cat fighting depending on their weight, age, and strength. Compare each attribute separately so that the winner is the one with the best performance in regards to the most attributes. The method should determine whether the
10
Task
New Java Syntax, level 10, lesson 2
Locked
Cat carnage (4)
Using the three created cats, hold three fights between pairs of cats. To hold a fight, use the boolean fight(Cat anotherCat) method. Display the result of each fight on a new line.
Comments (75)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
larsintech Level 15, Switzerland Expert
8 December 2024
Really unclear instructions for Cat carnage (3) in terms of comparison
24 February 2023
The (Cat anotherCat) was new for me.
Michael Amann Level 22, United States of America, United States
13 April 2022
Where did Integer.compare come from? 🤯
Anonymous #10948087 Level 6, Spain
8 March 2022
No la entiendes porque no se ha explicado. En Java (y en otros lenguajes como C, C++ y C#) hay un operador que se llama ternario: (condicion) ? valor_si_verdadero : valor_si_falso; Es una especie de if/else comprimido. Si se cumple la condición, se ejecuta valor_si_verdadero; en caso contrario, se ejecuta valor_si_falso. Espero que te ayude.
Mindre Mercedes Bautista Level 6, Rome, Italy
8 March 2022
gracias. ahora lo entiendo.
9 July 2021
I don't like that you don't have to create classes here. I know the title of the page says "Practice creating objects" but in the individual tasks it says "Create the Person class." but the class is already written. In the previous lessons one had to re-type a whole program just for practice. I think it's easy enough as of now to write the class as well. The average number of attempts for this task is 1.18 and it reflects that it's too easy :).
Jonaskinny Level 25, Redondo Beach, United States
10 February 2022
Unsolicited advice --> I created a class demonstrating all the == between various string constructs, decimal/octal/binary/unicode ... why not give yourself simple tasks like creating the class in another editor for each assignment? Also, I'm not a fan of IDE reliance, so maybe couple that practice with using commandline, jdk and a text editor only. Write sh or bat(if on windows) to set CLASSPATH and JAVA_HOME and execute your programs using ant etc. There is a ton you can do along the way if you think it's too easy. You'll also get better at tailing logs etc so when you get a position you will not be reliant on an IDE or a web-based compiler ;)
Oleg Level 8, Kiev, Ukraine
24 March 2021
what is line "return score>2" does mean?
Angelo Tratsis Level 8, Boston, United States
15 April 2021
great question. You don't have to write if statement. Automatically if its true will return true otherwise false
Mrrobot993 Level 9, Italy
15 October 2021
Means that (score>2) == true? return true
gabe Level 6, Greenville, United States
3 November 2020
why does sally have so many cats?
freewilly Level 5, Philadelphia, United States
2 November 2020
char datatypes expect a single quotation 2-bit value, e.g. 'm' String datatypes expect a double quotation, e.g. "m"
Libby Level 20, United Kingdom
4 January 2021
Thanks for this information
Chung Kang Level 6, Houston, United States
27 August 2020
I got confused with Character vs char
Angel Li Level 9, Fremont, United States
16 October 2020
Character is the "wrapper" class of char. You use wrapper classes to make objects and when declaring the generics of stuff like Maps, Arrays, etc.
Agent Smith Level 38
10 August 2020
If you have trouble with Implement the fight method, check how your code handles these additional cases: 1) If both cats have exactly same values. 2) If cat1 has 2 better values and 1 worse than cat2. 3) If cat1 has 1 better value and 2 worse than cat2.