Course Content
Java Extended
Java Extended
Challenge














Task
I warned you that there would be a lot of practice.
Now your task is to do the opposite. In the main
method, there is already code for creating multiple objects of the Cat
class, initializing their fields, and calling a method. Your task is to write the Cat
class so that it meows when the meooow()
method is called. You can also create a translator from cat language to English, as was done in the example with the Dog
class. But that is optional.
Main.java
- 1. In the
Cat
class, create fields namedname
,age
, andcolor
. Keep in mind thatname
andcolor
should have the typeString
, whileage
should have the typedouble
; - 2. Next, in the
Cat
class, create a method with a return type ofvoid
that will display "Meow" on the screen; - 3. Optionally, you can add the following syntax:
"Meow (that means 'Hey, my name is " + name + "!')"
package com.example;
class Cat {
String name;
double age;
String color;
void meooow() {
System.out.println("Meow (that means 'Hey, my name is " + name + "!')");
}
}
public class Main {
public static void main(String[] args) {
Cat Michael = new Cat();
Michael.name = "Mikey";
Michael.age = 0.5;
Michael.color = "Black";
Michael.meooow();
Cat Garfield = new Cat();
Garfield.name = "Garfield";
Garfield.age = 4.7;
Garfield.color = "Red";
Garfield.meooow();
}
}














Everything was clear?
Section 4. Chapter 5