Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA: Create two more cats using two constructors that were not yet used and create an array of size 4 Cat data type, adding

IN JAVA: Create two more cats using two constructors that were not yet used and create an array of size 4 Cat data type, adding all 4 Cats into your array.

Print all information about all 4 Cats formatted in a table form using for-each loop.

Source Code:

package unit1;

enum Color {

WHITE, CREAM, FAWN, CINNAMON, CHOCOLATE, RED, LILAC, BLUE, BLACK, LAVENDER

}

public class Cat {

// Data fields

String name;

double age; // in years

Color color; // we will limit color choice

String type; // (domestic / feral)

static int numberOfCats;

// Constructors

public Cat() {}

public Cat(String name) {

this.name = name;

}

public Cat(String name, double age, Color color, String type) {

super();

this.name = name;

this.age = age;

this.color = color;

this.type = type;

}

Cat(String name, String breed) {

this.name = name;

System.out.println(breed);

}

// Custom Methods

public static int getNumberOfCats() {

return numberOfCats;

}

String eat() {

return "favorite food";

}

boolean play(String toy) {

return false;

}

}

--------------------------------------------------------------------------------

package catclient;

import unit1.Cat;

public class TestCat {

public static void main(String[] args) {

Cat prince = new Cat();

Cat betty = new Cat("Betty");

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago