Question
1. Run the SimpleTest program that simply creates a CatManager instance and then prints out Done!. You will notice that the program fails. You need
1. Run the SimpleTest program that simply creates a CatManager instance and then prints out "Done!". You will notice that the program fails. You need to add something to the constructor in CatManager to fix the problem. What did you need to add?
2. Fill in the methods that are missing code in CatManager. These are currently commented out so you will need to uncomment them. Run Lab1Driver to test your code. You will need to uncomment code there too.
3. In the current version of Lab1Driver, the CatMgr.add method is not being tested. Add code that creates a Cat object and adds it to the CatMgr object in Lab1Driver. Put it AFTER the code that prints out the number of tabby and spotted cats, and BEFORE the code that asks for a name of a cat to search for. Test your code by searching for the name of the cat you added to the CatMgr.
4. If you wanted to change the CatMgr.add method so that there can never be two cats with the same name on the list, what would you do? You don't have to actually implement this - just write down your idea.
PICS FOR THE CODE ARE -
+ Package Explorer X CUS1156Fall2022Lab1 JRE System Library [JavaSE-17] src Week1 cus1156fall2022lab1-anmol Cat.java CatManager.java Lab1Driver.java xSimpleTest.java Week2 A A .... 0 BankAccount.... J BankAccount... Hamster.java Big.java Cat.java X*CatManager.... Lab1Driver.java SimpleTest.java 1 2= /** 4 *This class represents one cat. A cat has a * name and a color and can meow one or more times 5 * fun 6 * @author Bonnie MacKellar 7 */ 8 9 public class Cat{ 10 11 private String name; private String color; 12 13 /** 14 15 */ 16 * create a Cat with no name or color public Cat() 17 { } 18 19 20 /** 21 22 * @param name * @param color 24 */ 25 26 * Create a Cat with the specified name and color the color of the Cat public Cat(String name, String color) { this.name = name; the name of the Cat 27 this.color = color; } 29 30 private void meow () { /** } System.out.println("Meow!"); * The Cat prints outs its name and meows the specified * number of times * @param howMany - the number of times to meow */ public void manyMeows (int howMany) { /** } System.out.println(name + int count=0; while (count++ < howMany) meow(); * Prints out the name of the Cat */ public void printMyName() { /** } says "); System.out.println("my name is " + name); * returns the name of the Cat * @return the name of the Cat */ public String getName() { return name; 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 0 1 0 * Sets the name of the Cat to the specified name * @param name - the name of the Cat public void setName(String name){ this.name = name; returns the color of the Cat * @return the color of the Cat public String getColor() { return color; 56 57 58 59 60 } 61 62 /** 63 64 65 */ 66 67 68 } 69 700 /** 71 72 73 */ 740 75 76 } 77 78 /** 79 80 81 */ 82 83 84 } 85 } 86 * sets the color of the Cat to the specified color * @param color the color of the Cat public void setColor(String color) { this.color = color; Writable Smart Insert 1:1:0 RE G
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Since the Arraylist was not initialized thats why its showing NullPointerExceptio...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started