Question
PLEASE HELP ME TO ANSWER THOSE QUESTIONS PLEASE AND THANK YOU Do Not allow your lines to be longer than the line of = characters.
PLEASE HELP ME TO ANSWER THOSE QUESTIONS PLEASE AND THANK YOU
Do Not allow your lines to be longer than the line of "=" characters. ======================================================================== 1. What is the effect of declaring a class to be abstract?
======================================================================== 2. What is the effect of declaring methods to be abstract?
======================================================================== 3. How many classes can one class extend?
======================================================================== 4. How many Interfaces can one class implement?
======================================================================== 5. Can an abstract class be instantiated?
======================================================================== 6. What was the hardest part of this lab for you and why was it hard.
Pet abstract Dog - name: String - owner: String #birthDate: Date #breed: String #weight: double + Dog(Date, String, double) + abstract getBirthdate(): Date + abstract getBreedo: String + abstract getWeight): double + abstract compare Toint + Petr Date. String, double, String, String) * GetBirthdate(): Date + getBreed String .getWeight: double - getName(): String .getOwner : String to String : String + compareToo: int In a more feature rich UML Editor we would show an abstract class by using italics. 4 Changing the Dog Class 1. Declare the Dog class to be abstract. 2. Change the properties from private to protected. 3. Copy the documentation and full code for the three accessors. Paste them right under the constructor in Pet and add the override notation suggested by NetBeans. 4. Back in Dog class, we need to change the accessors to abstract and delete both the documentation and the implementation for each one. An abstract method has the form: public abstract returnType methodName (parameterList); Change get BirthDate(), getBreed(), get Weight() to match that syntax diagram. 5. Next we need to delete the toString() method. But wait! The super.toString() that is currently in Pet should be replaced with what is currently in Dog. Here is what the toString() in Dog should look like. @Override public String toString() { StringBuilder str = new StringBuilder(); String eol = System.lineSeparator(); // end of line for this os str.append(String.format("%40 %40 %40 %-25s", birthDate.getDay(), birthDate.getMonth(), birthDate.getYear(), breed)); str.append(eol); str.append(String.format("%7.2f", weight)); return str.toString(); } And here is what the new Pet toString() should look like: @Override public String toString() { StringBuilder str = new StringBuilder(); String eol = System.lineSeparator(); // end of line for this OS str.append(String.format("%40 %40 %40 %-25s", birthDate.getDay(), birthDate.getMonth(), birthDate.getYear(), breed)); str.append(eol); str.append(String.format("%7.2f%-15s%-12s", weight, name, owner)); return str.toString(); } Cut and paste from Dog to Pet until your Pet toString() matches that. Then delete the toString() method in Dog and its documentation. 6. Since Dog is the class that implements Comparable, but is now abstract it makes no sense to implement the compareTo() here. Abstract classes cannot be instantiated and therefore we don't have anything to sort, but in order to force subclasses to implement one, we will make this one abstract. Do to the compareTo() method what you did to the accessors. 7. Lastly, since Dog is now abstract and cannot be instantiated, the unit test is no longer even possible. Delete the main method and its documentation. 8. Dog should be down to about 35 lines now. Declaration of 3 protected properties, the constructor with documentation which we didn't touch, and 4 abstract methods. 5 Time to Run and Test Again Time to click the green arrow on the tool bar and See if Plato still wins! Well? Did he? 6 Polymorphism Demonstration One of the reasons that small classes and inheritance makes OOP so wonderful is reuse. We are going to work on a different project now. Download and unzip, and open Vet ClinicDriver application. The Dog and Pet are already there, I've added one class called Shelter Dog (they 3 don't have an owner name). There is usually a little more difference between subclasses, but the point of this exercise is to demonstrate polymorphism. You should remember from your reading that an object of a subclass is also an instance of its super class. Hopefully you will understand when we are finished with this part of the lab. 7 Add a Patient Class This one will be quite small. Add implements ComparableStep by Step Solution
There are 3 Steps involved in it
Step: 1
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