Each response needs to be at least one paragraph. Thanks! 10. Please briefly des
ID: 3645902 • Letter: E
Question
Each response needs to be at least one paragraph. Thanks!10. Please briefly describe best practices as it relates to emthod names.
11. Does Encapsulation imply Data/Information Hiding in object-oriented programming or vice verca? Are these two terms the same? Please explain.
12. What is inheritance and what are the major benefits of using inheritance? What programming technique shall you follow when the base class emthods are not appropriate for the derived class object?
13. What are the differences between inhereting interface and inheriting implementation? How do inheritance hierarchies designed for inheriting interface differe from those designed for inheriting implementation?
14. Given the following list of classes, attributes and methods,
- identify which items are classes, which items are attributes and which items aremethods;
- identify which class each attribute and method belongs to; and
- suggest a class hierarch given you list of classes.
*Note - no particulare capitalization scheme is used in the list below to differentiate between classes, methods and attributes.
AdhereToBuilding, NumberOfPetals, Photosynthesize, EmitFragrance, Length, Plant, Height, DaysToGermination, Rose, Grow, LosePetals, ConsumeWater, FloweringSeason, Vine, Color, LeavesPerInch
Explanation / Answer
I can provide you with Q10 answer Composition can be used when we need to change the implementation dynamically at run time. The implementation detail about the class is abstracted always from the users. So, if the implementation needs to change, the users of the class will be immune from these changes. If we don’t want to take burden of maintaining previous behavior, we may like to go for inheritance. This is the criteria whether or not to use composition in an application Example: Option 1 (Inheritance): public class SalesList : List { //methods that add extra behavior List } Option 2 (Composition): public class SalesList { private List _list; //methods that add extra behavior to List } Advantage of option2: The implementation detail about the storage of the sales data is abstracted from the consumer. So, if the implementation needs to change (say a dictionary, for example), the consumer of the class will be immune from these changes. Write the code for an interface that models the behavior of a DVD player. Include at least three methods. public interface DVDPlayer { public static final int STOP = -1; public static final int PLAY = 1; public static final int PAUSE = 0; public void stop(); public void play(); public void pause(); } Consider the following information about a Vehicle/Car inheritance hierarchy and answer each of the following questions: i. Which would be the child class? Vehicle. As car it a vehicle ii. Which class would use the protected access modifier for its data members? Vehicle. As the members will be inherited to class car. iii. Assume a public Move() method was included in the Vehicle class but not in the Car class. Also assume that a Vehicle object, aVehicle, and a Car object, aCar, had been instantiated in a Main method. Write a statement to call the Move() method for each of the objects. If the object cannot call the method, explain why. public static void main(String[] args) { Vehicle aVehicle = new Vehicle(); Car aCar = new Car(); aVehicle. Move() // a statement to call the Move() method for vehicle class aCar. Move() // a statement to call the Move() method for car class } As vehicle is the super class, so the public Move() method will be inherited to car class. We can call move method from any of the objects. iv. Assume a protected (string) data member, name, and a method named setName was coded in the Car class, but not in the Vehicle class. Also assume that a Vehicle object, aVehicle, and a Car object, aCar, had been instantiated in a Main method. Write a statement to set the name to "Custom" for each of the objects. If the object cannot use the method, explain why. public static void main(String[] args) { Vehicle aVehicle = new Vehicle(); Car aCar = new Car(); aVehicle.setName (“Custom”);// Error aCar.setName (“Custom”); // a statement to set the name to "Custom" for car class } The statement aVehicle.setName (“Custom”); Will produce error as car is subclass and only it knows about a protected (string) data member, name, and a method named setName. Based on the previous question, instantiate two objects. One that has no parameters and one the passes all the parameters to the class. public static void main(String[] args) { Vehicle aVehicle = new Vehicle(); Car aCar = new Car(); // no parameters Car bCar = new Car(“Custom”); // the passes all the parameters } Code a partial and simplified Student Assignment class. The purpose of the class will be to provide the assignment description, maximum score, and actual score. Code the “get” and “set” methods just for the assignment description and maximum score. Also code the calcScore method that returns maximum score minus actual score. Don’t worry about all the other things that should be in a Student Assignment class //a partial and simplified Student Assignment class public class StudentAssignment { //assignment description, maximum score, and actual score String description; int maxScore, actualScore; //the “get” and “set” methods just for the assignment description and maximum score public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public int getMaxScore() { return maxScore; } public void setMaxScore(int maxScore) { this.maxScore = maxScore; } //the calcScore method that returns maximum score minus actual score public int calcScore() { return maxScore- actualScore; } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.