Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 2, Problem 12R
Draw a class inheritance diagram for the following set of classes:
- Class Goat extends Object and adds an instance variable tail and methods milk() and jump().
- Class Pig extends Object and adds an instance variable nose and methods eat(food) and wallow().
- Class Horse extends Object and adds instance variables height and color, and methods run() and jump().
- Class Racer extends Horse and adds a method race().
- Class Equestrian extends Horse and adds instance variable weight and isTrained, and methods trot() and isTrained().
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Draw a class inheritance diagram for the following set of classes:
• Class Goat extends Object and adds an instance variable tail and methods milk() and jump().
• Class Pig extends Object and adds an instance variable nose and methods eat(food) and wallow().
• Class Horse extends Object and adds instance variables height and color, and methods run() and jump().
• Class Racer extends Horse and adds a method race().
• Class Equestrian extends Horse and adds instance variable weight and isTrained, and methods trot() and
isTrained().
Draw a class diagram consisting of a base class named Person and a derived class named Student consist of :
Encapsulation
Polymorphism
Inheritance
Base classes vs Derived classes
Protected Access vs Packaged Access & Abstract Methods and Classes
Class Relationships Exercises
1. In Java, we use inheritance for "is-a" relationships. Containment, on the other hand, indicates that one object has another object. These are "has-a" relationships.
For the following relationships, determine if they are a "is-a" or a "has-a" relationship:
o bicycle - vehicle
o car - engine
o pizza - topping
o food - pizza
o dog - mammal
2. Share with someone else 3 other examples for each of the following relationships:
o Inheritance ("is-a" relationship)
o Containment ("has-a" relationship)
3. public class PersonInfo {
protected String firstName;
protected String birthdate;
}
public class ChildInfo extends PersonInfo {
private String schoolName;
}
public class MotherInfo extends PersonInfo {
private String spousename;
private ChildInfo children1;
private ChildInfo children2;
private ChildInfo children3;
...
}
A. Draw the relationships for the classes above using UML. If a class inherits from another class, draw an open arrow pointing to the base class…
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...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Experiencing MIS
Porter’s competitive forces model: The model is used to provide a general view about the firms, the competitors...
Management Information Systems: Managing the Digital Firm (15th Edition)
Write an SQL statement to display the name and breed of all pets, sorted by PetName.
Database Concepts (8th Edition)
Convert the following if-else-if statement into a switch statement: if (choice == 1) { System.out.println(You s...
Starting Out with Java: Early Objects (6th Edition)
The article mentions that quantum computers will have tremendous processing power and revolutionize a number of...
Using MIS (10th Edition)
A file that contains a Flash animation uses the __________ file extension. a. .class b. .swf c. .mp3 d. .flash
Web Development and Design Foundations with HTML5 (8th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Design a class diagram by using a program:arrow_forwardQ: Write a full java application program to implement the following classes using inheritance, then apply instanceOf operator and dynamic binding Person: Variables:( Fname,Lname)/method: constructor /printInfo()/tostring() Student: Variables: (Id) / method: constructor/Print()/tostring() ITStudent: Variables: (ml,m2,m3)/ method: constructor/avg()/tostring()arrow_forward1. An inheritance principle is used to explore and extend the Course class. The UML of the Course is presented below: Course - courseName : String - sectionNumber : int - instructorName : String - numberOfStudentsEnrolled : int #Course() #Course(courseName : String) #Course(courseName : String, sectionNumber: int, instructorName : String) +getCapacity() : int +getCourseName() : String +setCourseName(courseName : String) : void +getSectionNumber() : int +setSectionNumber(sectionNumber : int) : void +getlnstructorName() : String +setlnstructorName(instructorName : String) : void +getNumberOfStudentsEnrolled() : int +toString(): String Part 1.1. Implement the abstract class Course strictly according to its UML one-to-one (do not include anything extra, do not miss any data fields or methods). Add comments to your program and mark where data fields, constructors, getters, setters and toString() are located, and which method is abstract or static (if any). Note: No methods should have any…arrow_forward
- 1. Using inheritance design and implement the following classes. Write a complete program to set attributes values of the objects of Employee and Worker classes. Employee name Employee() getname() Worker salary Worker() getsalary()arrow_forwardJavaarrow_forwardDraw a UML class diagram for the following three classes to show their structures and relationships.arrow_forward
- The mechanism of deriving a class from another derived class is known as? A. Polymorphism B. Single Inheritance C. Multilevel Inheritance D. Message Passing Justify your answer with explanationsarrow_forwardINTRO JAVA Problem 1 Implement a superclass Person. Make two classes, Student and Instructor, that inherits from Person. A person has a name and a year of birth. A student has a major, and an instructor has a salary. Write the class declarations, the constructors, and the methods toString & equals for all classes. Supply a test program for these classes and methods. Problem 2 Make a class Employee with a name and salary. Make a class Manager that inherits from Employee. Add an instance variable, named department, of type String. Make a class Executive inherit from Manager. Implement toString and equals methods for all classes; supply a test program that tests these classes and methods toString() method should print all the properties of the class; as Name and DOB is same for both student and instructor, you can implement it in the superclass "Person" Problem 1 Create 3 students Student1 : Name James, DOB: 01/01/2000, Major: English Student2: Name Jane, DOB:…arrow_forwardUsing c++ Design a Wacky class that can be used to generate a message based on the information passed to it. The class should have a single integer private member variable: int num; Design the complete class so that if: an object is created with no parameters; num is initialized to 10. an object is created with 1 parameter that is an integer; num is initialized to the integer that is passed *2 an object is created with 1 parameter that is a double; num is initialized to the double *4 an object is created with 2 parameters, a char and a string; it prints the message "That's WACKY!"arrow_forward
- Q# In the company example, a supervisor has a supervisee. This “has-a” relationship is called: Group of answer choices 1. parent 2. composition 3. extending 3. inheritancearrow_forwardConsider the following detailed inheritance hierarchy diagram: (ATTACHED IN IMAGE) The person constructor has two string parameters, a first name, and the last name. The constructor initializes the e-mail address to the first letter of the first name followed by the first five letters of the last name followed by @jc.com. If the last name has fewer than five letters, the e-mail address will be the first letter of the first name followed by the entire late name followed by @jc.com A) Implement the person constructor: B) Override Object's toString method for the Person class. The toString method should return the present state of the object. Assume that the constructor writer for the previous part of this problem works as intended. C) Write both the Person and Student class headers so that the Student is a subclass of Person.arrow_forwardDefining Classes Write and document the definition for the Money class. The Money class represents an amount in U.S. dollars. Money Class e Fields cents : int dollars : int e Methods getValue() : double Money(int d, int c) setCents(int c) : void setDollars(int d) : void toString() : String • Each Money object has two int instance variables: dollars and cents. • The class has one constructor that takes two int parameters. The first int represents whole dollars, and the second int represents cents. • The class has one accessor method named getValue() which returns the amount as a double. (Just divide cents by 100.0 and add it to dollars. Return that amount.) • The class has two mutator methods-setDollars() and setCents()–that modify the corresponding instance variables. • The class has a toString() method that returns the amount as a String in the form: $ 2345.75. Use concatenation to produce the output. Do not worry about the decimal places.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY