undefined

Practice creating objects

Java Syntax
Level 5 , Lesson 5
Available

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

undefined
2
Task
Java Syntax, level 5, lesson 5
Locked
Creating a cat
Sally Johnson has 500 cats, and another couple hundred furry creatures come to visit them as guests. So Sally decided to create a special cat photo album to record their features: name, age, weight and strength. "Why strength?" you ask. You'll see why we need strength in the next task. For now, we'll implement the Cat class.
undefined
4
Task
Java Syntax, level 5, lesson 5
Locked
Implement the fight method
Theo Baslim, a retired colonel, saw active combat as a young man, but now he is bored. When he learned that his neighbor Sally Johnson had acquired five hundred cats, and he offered to arrange bloodless feline battles (she wouldn't go for bloody battles). There's just one small detail: we need to implement a mechanism for cats to fight based on weight, age and strength.
undefined
4
Task
Java Syntax, level 5, lesson 5
Locked
Getters and setters for the Dog class
Let's create a Dog class. A dog should have a name and age, and getters and setters for these variables. A getter is a method that returns a variable's current value to the caller. A setter is a dog breed. However, though we are talking about dogs at the moment, this term actually isn't about dogs: in the context of programming, a setter is a method that sets a variable to a new value.
undefined
2
Task
Java Syntax, level 5, lesson 5
Locked
The Three "Muscateers"
A couple of tasks ago, students at the secret CodeGym center created the class Cat. Now it's time to actually create some cats in the image and likeness of the Cat class, or rather using the class as a pattern. There should be three cats. Breathe life (or specific data) into this trio.
undefined
4
Task
Java Syntax, level 5, lesson 5
Locked
Feline carnage
If you think all cats are cute fur balls, you probably haven't encountered alley cats in a heated struggle for supremacy in a certain area. It's time for you to meet them. More precisely, it's time to simulate a decisive battle between the three most powerful cats in the neighborhood. For combat, we will use the boolean fight(Cat anotherCat) method.
undefined
2
Task
Java Syntax, level 5, lesson 5
Locked
People
Creating a person is a huge responsibility. But it's not our place to teach you that. We need to describe and show how to create different classes, and your task is to understand these concepts and put them into practice. In particular, let's create a Person class. A person should have a name, age, address, and sex. Have we forgotten anything?
undefined
8
Task
Java Syntax, level 5, lesson 5
Locked
Arithmetic mean
The arithmetic mean is a value that is often used in statistics. A hospital's average temperature is precisely calculated using the formula for the arithmetic mean. And now we've come to the critical part: write a program that takes numbers from the keyboard, sums them, and then calculates the mean until the user enters the number -1.
undefined
2
Task
Java Syntax, level 5, lesson 5
Locked
Getters and setters for the Person class
We create a pair of methods (get and set) for each variable to allow other classes to change their values. The get method's task is to return the current value of the variable to the caller. The set method's task is to set a new value for the variable. Let's create a Person class with a name, age, and sex, and define getters and setters for all the fields.
Comments (65)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Oleg Level 8 Kiev Ukraine
24 March 2021
what is line "return score>2" does mean?
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"
Chung Kang Level 6 Houston United States
27 August 2020
I got confused with Character vs char
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.
Rose Level 14 Richardson United States
22 June 2020
Hint: put all variables double and you will get a double result.
Peter Schrijver Level 22 Hilversum Netherlands
22 May 2020
(double) / (int) will give you a (double) result
Nastya Level 19 Moscow Russia
6 May 2020
Hint: System.out.println((float) sum / count);
Deborah Wenrich Level 7 Pembroke Pines United States
6 March 2020
Hi Jeff, I jumped off the deep end too to learn java. I'm learning to celebrate the little things that I remember like System.out.print() and naming strings and integers. Some days it's easy other days its hard, but all the time, I'm having fun. Learning java programming makes me happy. Hang in there Jeff, you'll go on to get it and be fine.
Darina Cherepanova Level 6 Sofia Bulgaria
15 February 2020
Did you guys understand construction " ? 1 : 0" used in task "Feline carnage" ?