Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 2, Problem 13R
Explanation of Solution
Inheritance diagram:
Inheritance diagram is drawn from parent class to child class. The parent class is represented at the highest level and the child class is represented next level to highest.
- If the class does not contain the specifier then the default access specifier is used as “public”.
The following diagram represents the inheritance diagram for given data:
Explanation:
From the above inheritance diagram,
- Object is the parent class.
- In that parent class, there are three child classes such as “Goat”, “Pig” and “Horse”.
- The Goat class contains the methods milk() and jump() and it is not specified with any access specifier. So, the methods are defined with default access specifier public.
- The Pig class contains the member variable nose and methods eat() and wallow() and it is also not specified with any access specifier. So, the methods are defined with default access specifier public.
- The Horse class contains the member variable height and color and the methods run() and jump()...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Implement the classes according to the given class diagram. It shows both the composition and aggregation relationships.
Driver has a Vehicle and Engine is a part of that Vehicle.
[Note: consider the necessary data members, constructors, destructors and member functions accordingly]
Note: use OOP and C++
Create an interface Wheel with methods setWheels (int c) and getWheels () and a class Vehicle with abstract methods getColor () and getBrand (). Now, create a concrete class Taxi with additional method setDriver (String name) that inherits both Wheel and Vehicle. (Note: Concrete classes don’t have any abstract method)
Is it ever justified to declare a class abstract if it lacks abstract methods? Examine this.
Chapter 2 Solutions
Data Structures and Algorithms in Java
Ch. 2 - Give three examples of life-critical software...Ch. 2 - Give an example of a software application in which...Ch. 2 - Prob. 3RCh. 2 - Prob. 4RCh. 2 - Prob. 5RCh. 2 - Give a short fragment of Java code that uses the...Ch. 2 - Prob. 7RCh. 2 - Prob. 8RCh. 2 - Prob. 9RCh. 2 - Prob. 10R
Ch. 2 - Prob. 11RCh. 2 - Draw a class inheritance diagram for the following...Ch. 2 - Prob. 13RCh. 2 - Prob. 14RCh. 2 - If the parameter to the makePayment method of the...Ch. 2 - Prob. 16CCh. 2 - Most modern Java compilers have optimizers that...Ch. 2 - The PredatoryCreditCard class provides a...Ch. 2 - Modify the PredatoryCreditCard class so that a...Ch. 2 - Prob. 20CCh. 2 - Write a program that consists of three classes, A,...Ch. 2 - Prob. 22CCh. 2 - Prob. 23CCh. 2 - Write a Java class that extends the Progression...Ch. 2 - Redesign the Progression class to be abstract and...Ch. 2 - Use a solution to Exercise C-2.25 to create a new...Ch. 2 - Use a solution to Exercise C-2.25 to reimplement...Ch. 2 - Write a set of Java classes that can simulate an...Ch. 2 - Write a Java program that inputs a polynomial in...Ch. 2 - Write a Java program that inputs a document and...Ch. 2 - Prob. 31PCh. 2 - Write a Java program that simulates a system that...Ch. 2 - Define a Polygon interface that has methods area()...Ch. 2 - Prob. 35PCh. 2 - Write a Java program that can make change. Your...
Knowledge Booster
Similar questions
- Write the abstract class of Person having abstract methods of set name, get name, set age and get age. Also create two child classes Student: having Registration and CGPA Teacher: having Specialization and pay Create menu to add, display, update the values of Students and Teachers using polymorphism technique?arrow_forwardImplement the classes according to the given class diagram. It shows both the composition and aggregation relationships. Driver has a Vehicle and Engine is a part of that Vehicle. [Note: consider the necessary data members, constructors, destructors and member functions accordingly] Note: solve as soon as possible use C++ LANGUAGE Class diagram is givenarrow_forwardCan an abstract class have concrete (non-abstract) methods? Can a concrete class have abstract methods? Can you have an abstract class without abstract methods? Justify your answers.arrow_forward
- Implement abstraction on animal and car classes (in java) e.g animal and car is a abstract class.arrow_forwardWrite a generic class of Shape with the attribute of center and operation to calculate area. Inherit the classes of Circle, Triangle, and Square such that the operation to calculate area has dynamic late binding. Write these classes such that Shape is an abstract class whereas all others are concrete classesarrow_forwardYou are going to declare an abstract class called Player. In the abstract class Player, it should contain common methods found for both Human Player and Al Player. Talk with your team which classes in the Player class should be declared abstract and which ones are supposed to be non-abstract (regular methods). Both Human Player and Al Player should inherit the abstract Player class. Code:arrow_forward
- Use the aggregation (composition) concept to define and implement the class line(p1.x, p1.y, p2.x, p2.y) by using two points variables P1, and P2 of type point2D class defined in Q1. Beside the two points P1 and P2, the line class has the following functions: print(), MoveRel(Dx,Dy) (use the point2D’s MoveRel(Dx,Dy) function of the two points to achieve that), line(), line(x1,y1,x2,y2), line(P2D1,P2D2). * Your answerarrow_forwardWe have a parking office class for an object-oriented parking management system using java Add (implement )a function to the Parking Office class to return a collection of customer ids (getCustomerIds) using java I have attached two class diagrams with definitions of all related classes in our system (i.e car, customer, .....). N.B. Parking office methods in the class definition like register, getcustomer and addcharge have already been implemented, we just need an additional getcustomerID function as mentioned above Explain the code you wrote with a few wordsarrow_forwardWe have a parking office class for an object-oriented parking management system using java Add(implement) a method to the Parking Office class to return the collection of permit ids for a specific customer (getPermitIds(Customer)) using java I have attached two class diagrams with definitions of all related classes in our system (i.e car, customer, .....). N.B. Parking office methods in the class definition like register, getcustomer and addcharge have already been implemented, we just need an additional getPermitIds(Customer) method as mentioned above Explain your code in a few words Important- We have a method to return a collection of permit ids (getPermitIds), what we need is a method to return the collection of permit ids for a specific customer (getPermitIds(Customer))arrow_forward
- Experiment with two classes that have a straightforward derivation relationship. Insert println statements into the constructors of both the parent and child classes. In the child, do not explicitly call the function Object() { [native code] } of the parent. So, what happens? Why? Change the child's function Object() { [native code] } to explicitly call the parent's function Object() { [native code] }. What happens next?arrow_forwardI need help in improving my Passenger class and it's subclasses code. This is an elevator simulator that uses polymorphism and object-oriented programming to simulate the movement of elevators in a building with multiple types of passengers and elevators.The system has 8 elevators, each of which can be one of 4 types of elevators, with a certainpercentage of requests for each type. Similarly, each passenger can be one of 4 types, with adifferent percentage of requests for each type. The simulation should have 4 types of Passengers: Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements. VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators. Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by…arrow_forwardWhen one class includes objects that belong to another class, this is known as a whole-part relationship or composition. The conclusion is that a has-a connection exists. Consider the following lengthy assertion: getHireDate(), getYear(), and Outputsales.getHighestPaidEmployee() are some useful functions ().arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education