Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Supporting Files . Catiava a Course Concept(s) Covered . Using Objects Basic Class Structure Instance Variables Instance Methods Overloading . Class Variables Class Methods Composition

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Supporting Files . Catiava a Course Concept(s) Covered . Using Objects Basic Class Structure Instance Variables Instance Methods Overloading . Class Variables Class Methods Composition Instructions Create a folder called CSC1130 Aggregation yourlastname. Store all of the files for this lab in that folder. Once you have completed the lab, upload the zipped folder in Canvas You will need the code from Cat.java to complete this lab. Create four new files: Dog Java, Alligator.java, Zoo java and Driver.java. Write these classes according to the following specifications: Important: As you write each class, save and compile often Compile as often as is appropriate to narrow down any compiler errors to the smallest amount of new code. Do not create a new class until the current one you are working on compiles cleanly. Dog.java - use the Cat class as a template for your Dog class. Prior to writing the Dog class, read through the Cat class so that you have a general understanding of the code A Dog has all of the same instance and class variables as a Cat A Dog has all of the same Constructors and methods as a Cat, with the following exceptions: The default construction of a Dog creates a "Brown" dog. 1 year old, 15 pounds, with a "Friendly disposition The default grow method increments the age by 1, and the weight by 2 Alligator.java - use the Cat class as a template for your Alligator class. . An alligator has all of the same instance and class variables as a Cat, except the CLASSIFICATION variable holds "Reptile An alligator has all of the same Constructors and methods as a Cat, with the following exceptions: The default construction creates whatever characteristics you (as the programmer) want The default grow method increments the age by 1, and the weight by 5 The eat() method accepts a Cat parameter, prints "I like felines, and adds the weight of the Cat to the Alligator (you may need to change the Cat class to do this) Overload the eat() method so that a Dog can also be 'fed' to an Alligator. This method should print "Canines are ok, but I sure like to eat felines! - only eat half since Dogs are not as tasty", and adds half the dog's weight to the Alligator (you may need to change the Dog class to do this) Zoo.java A Zoo has 3 private instance variables: a Dog, a Cat, and an Alligator, along with public setter methods for each A Zoo has a public default constructor that creates a default Alligator, default Dog, and default Cat A Zoo has a public alternate constructor that accepts parameters to create an Alligator - the constructor creates a default Cat, a default Dog, and the Alligator per the parameters . A Zoo has a public printinventory method that prints the characteristics of each animal using the animal's printCharacteristics method Driver.java Instantiate a Zoo using the alternate constructor Print the characteristics of the Cat . Allow the user to change the Dog's color Print the characteristics of the Dog Feed the Cat to the Alligator Print the characteristics of the Alligator Feed the Dog to the Alligator Print the characteristics of the Alligator After the code works completely, answer the following questions (you do not need to turn in these answers, but be sure you understand them or ask about them): 1. Are there any examples of Composition in these classes? If so, list the classes which demonstrate the concept and list the specific lines of code. 2. Are there any examples of Overloading in these classes? If so, list the classes which demonstrate the concept and list the specific lines of code. 3. Identity at least two methods which have primitives in their argument lists, 4. Identify at least two methods which have references in their argument lists. public class Cat static final String CLASSIFICATION; static { CLASSIFICATION = "Mammal"; } private String color; private int age; private int weight; private String disposition; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 public Cat () { color = "Tortoise shell"; age = 1; weight = 18; disposition = "Aloof"; } public Cat (String c, int a, int w, String { color = c; age = a; weight = w; disposition = d; } 27 28 29 30 31 32 33 34 35 36 37 38 39 40 public void grow () { age++; } public void grow (int w) { age++; weight += w; } 41 41 42 public void grow (int a, int w) { age + a; weight += w; } public void setColor (String c) { color = c; } 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 public void setDisposition (String d) { disposition = d; } public void eat (String s) { System.out.println("I like " + s); } 62 63 64 65 66 67 68 69 70 71 72 73 public void printCharacteristics () { System.out.println(); System.out.println("I am a cat"); System.out.println("My classification is: " + CLASSIFICATION); System.out.println("My color is: + color); System.out.println("My age is: + age); System.out.println("My weight is: " + weight); System.out.println("My disposition is: " + disposition); } 11

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

Step: 3

blur-text-image

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions