Sorry it took so long to get here, but it's time to create your first cat! Let's make it super cute.
Steps
What is a Cat?
In the catsoneday package, make a new public class: Cat!
Define a bunch of attributes for your cat. You probably want a String name, String sex, a String color, a String eyeColor, maybe a String furPattern, and an int weightInKg. Feel free to add more things we should know about cats.
Define a public constructor method for your cat. Make sure the method takes in parameters for each of your cat's attributes. Then make sure to set the cat's attributes to those parameters.
Define some public methods for actions a cat does. You probably want methods like purr, stretch, yawn, lounge, pounce, punch, and eat. Each of these methods should take no parameters and produce no outputs. Each one should print some text describing the cat's action.
Define a toString method that takes no parameters and outputs a String. The string output should describe the attributes of your cat. It could be something like "This cat is " + this.name + ". " + this.name + " is a " + this.sex + " cat with " + this.color + " fur and " + this.eyeColor + " eyes.". Get creative with it!
Making Our First Cat
Back in your App.java in the main method, create a new variable myCat of type Cat. Create a new instance of Cat, and set the parameters however you like.
Using System.out.println, print out a description of myCat. (Remember step 5 from earlier?)
After that, run of your cat's action methods.
Run ./gradlew run to see your cat in action! Isn't it cute?
Congratulations on your first cat! Make sure to give it lots of cuddles.
Goal
Sorry it took so long to get here, but it's time to create your first cat! Let's make it super cute.
Steps
What is a Cat?
catsoneday
package, make a new public class:Cat
!String name
,String sex
, aString color
, aString eyeColor
, maybe aString furPattern
, and anint weightInKg
. Feel free to add more things we should know about cats.purr
,stretch
,yawn
,lounge
,pounce
,punch
, andeat
. Each of these methods should take no parameters and produce no outputs. Each one should print some text describing the cat's action.toString
method that takes no parameters and outputs aString
. The string output should describe the attributes of your cat. It could be something like"This cat is " + this.name + ". " + this.name + " is a " + this.sex + " cat with " + this.color + " fur and " + this.eyeColor + " eyes."
. Get creative with it!Making Our First Cat
App.java
in themain
method, create a new variablemyCat
of typeCat
. Create a new instance ofCat
, and set the parameters however you like.System.out.println
, print out a description ofmyCat
. (Remember step 5 from earlier?)./gradlew run
to see your cat in action! Isn't it cute?Congratulations on your first cat! Make sure to give it lots of cuddles.