Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CAT CLASS 1. Create a Cat class. The cat is a noble creature that has the follow

ID: 3542280 • Letter: C

Question

CAT CLASS

1. Create a Cat class. The cat is a noble creature that has the following attributes:

a. name

b. breed

c. color

d. number of legs

e. weight

f. litter type //scoopable, crystals, regular, none

// These are the only valid values. Use an Enum called LitterType. (See page 194, Special Topic 5.3 Enumeration Types)

2. We need multiple constructors for Cat

a. A zero parameter constructor

b. A constructor where number of legs defaults to 4 and litter type defaults to regular

c. A constructor where the number of legs is defaulted to 4. The rest are passed as explicit parameters

d. A constructor that has all of the attributes as explicit parameters

3. The Cat also has methods associated with the class.

a. Getters and Setters for ALL attributes

b. A method that totals all of the cat

Explanation / Answer

import java.util.ArrayList;

import java.util.Random;

import java.lang.Math;



public class CatTester

{

/**

* @param args

*/

public static void main(String[] args)

{

ArrayList<Cat> catList = new ArrayList<Cat>();

/*Random randLegs = new Random();

for (int i = 0; i < 7; i++)

{

int rm = randLegs.nextInt(6) + 1;

System.out.println(randLegs);

}

*/

Cat ozzy = new Cat(Litter.SCOOPABLE);

ozzy.setName("Ozzy");

ozzy.setBreed("Manx");

ozzy.setColor("Black");

ozzy.setWeight(13.0);

ozzy.setNumOfLegs(4);

Cat minnie = new Cat(Litter.SCOOPABLE);

minnie.setName("Minnie");

minnie.setBreed("Tabby");

minnie.setColor("Orange");

minnie.setWeight(11.5);

minnie.setNumOfLegs(4);

Cat bub = new Cat(Litter.NONE);

bub.setName("Bub");

bub.setBreed("Munchkin");

bub.setColor("Grey");

bub.setWeight(10.0);

bub.setNumOfLegs(4);

Cat finster = new Cat(Litter.CRYSTALS);

finster.setName("Finster");

finster.setBreed("Bengal");

finster.setColor("Black");

finster.setWeight(12.6);

finster.setNumOfLegs(2);


Cat tucker = new Cat(Litter.SCOOPABLE);

tucker.setName("Tucker");

tucker.setBreed("Maine Coon");

tucker.setColor("Light Brown");

tucker.setWeight(9.5);

tucker.setNumOfLegs(3);


Cat fuddles = new Cat(Litter.CRYSTALS);

fuddles.setName("Fuddles");

fuddles.setBreed("California Spangled");

fuddles.setColor("Grey");

fuddles.setWeight(12.3);

fuddles.setNumOfLegs(5);


Cat snickerdoodles = new Cat(Litter.CRYSTALS);

snickerdoodles.setName("Snickerdoodles");

snickerdoodles.setBreed("York Chocolate");

snickerdoodles.setColor("Dark Brown");

snickerdoodles.setWeight(11.0);

snickerdoodles.setNumOfLegs(4);


Cat butters = new Cat(Litter.NONE);

butters.setName("Butters");

butters.setBreed("Turkish Angora");

butters.setColor("White");

butters.setWeight(13.5);

butters.setNumOfLegs(3);


Cat sneaker = new Cat(Litter.SCOOPABLE);

sneaker.setName("Sneaker");

sneaker.setBreed("Ragdoll");

sneaker.setColor("Brown");

sneaker.setWeight(15.5);

sneaker.setNumOfLegs(4);


Cat misty = new Cat(Litter.NONE);

misty.setName("Misty");

misty.setBreed("Scottish Fold");

misty.setColor("Tri-Colored");

misty.setWeight(20.5);

misty.setNumOfLegs(4);

/*Cat Figs = new Cat(Litter.CRYSTALS);

misty.setName("Figs");

misty.setBreed("Calico");

misty.setColor("Tri-Colored");

misty.setWeight(15.2);

//misty.numOfLegs();

Cat PicoDeGato = new Cat(Litter.NONE);

misty.setName("Pico de Gato");

misty.setBreed("Burmese");

misty.setColor("Brown");

misty.setWeight(20.5);

//misty.setNumOfLegs(4);

Cat Schnickelfritz = new Cat(Litter.NONE);

misty.setName("Schnickelfritz");

misty.setBreed("Norwegian Forest Cat");

misty.setColor("White");

misty.setWeight(20.5);

//misty.setNumOfLegs(4);

Cat CaptainSkittlehook = new Cat(Litter.NONE);

misty.setName("Captain Skittlehook");

misty.setBreed("Siberian");

misty.setColor("Tri-Colored");

misty.setWeight(20.5);

//misty.setNumOfLegs(4);*/


catList.add(ozzy);

catList.add(minnie);

catList.add(bub);

catList.add(finster);

catList.add(tucker);

catList.add(fuddles);

catList.add(snickerdoodles);

catList.add(butters);

catList.add(sneaker);

catList.add(misty);

  

for (Cat cats : catList)

{

System.out.println(cats);

}

  

  

int[] addedCat = new int[4];

{

addedCat[0] = (int) ((6 * Math.random()) + 1);

addedCat[1] = (int) ((6 * Math.random()) + 1);

addedCat[2] = (int) ((6 * Math.random()) + 1);

addedCat[3] = (int) ((6 * Math.random()) + 1);

}

System.out.print("Random legged cats :");

for (int i = 0; i <= 6; i++)

{

System.out.print(addedCat[i] + " " );

}

  

System.out.println("Total number of cat's legs: " + totalLegs());


}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote