Consider a Person class (which keeps track of a Person’s name) and a Student class (which keeps track of a Student’s name and student ID number). State the relationship between the two classes as either an is-a or a has-a relationship (similar to the last sentence of each paragraph in the above Model).

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

4. Consider a Person class (which keeps track of a Person’s name) and a Student class (which keeps track of a Student’s name and student ID number). State the relationship between the two classes as either an is-a or a has-a relationship (similar to the last sentence of each paragraph in the above Model).

### "Is-a" versus "Has-a"

A large program will often be built out of multiple classes. Often, these classes will have a “has-a” relationship. For example, a game program might include three classes: PlayingCard, Suit, and Rank. A PlayingCard object **has a** Suit and **has a** Rank, which are handled in a Java program as instance variables.

#### Diagram Explanation

The diagram below illustrates the `PlayingCard` class and its components:

```
         ______________________
        |        PlayingCard     |   <- Class Name
        |______________________|
        | - cardRank: Rank        |   <- Data Fields
        | - cardSuit: Suit          |
        |______________________|
        | + setRank(Rank rank): void |   <- Methods
        | + setSuit(Suit suit): void     |
        | + getRank(): Rank            |
        | + getSuit(): Suit               |
        |______________________|
```

This diagram is divided into three sections:
1. **Class Name**: The name of the class (`PlayingCard`).
2. **Data Fields**: Instance variables (`cardRank` and `cardSuit`), which are of types `Rank` and `Suit`.
3. **Methods**: Functions that can be used to set and get the values of `cardRank` and `cardSuit` (`setRank`, `setSuit`, `getRank`, and `getSuit`).

Less often, you might have two classes which have an “is-a” relationship, where one class is a more general class, while the second class is a more specialized version of the original class. A blackjack program might have a `BlackJackCard` class which **is a** `PlayingCard`. Notice the relationship is not symmetrical: every `BlackJackCard` **is a** `PlayingCard`, but not every `PlayingCard** is a** `BlackJackCard`.
Transcribed Image Text:### "Is-a" versus "Has-a" A large program will often be built out of multiple classes. Often, these classes will have a “has-a” relationship. For example, a game program might include three classes: PlayingCard, Suit, and Rank. A PlayingCard object **has a** Suit and **has a** Rank, which are handled in a Java program as instance variables. #### Diagram Explanation The diagram below illustrates the `PlayingCard` class and its components: ``` ______________________ | PlayingCard | <- Class Name |______________________| | - cardRank: Rank | <- Data Fields | - cardSuit: Suit | |______________________| | + setRank(Rank rank): void | <- Methods | + setSuit(Suit suit): void | | + getRank(): Rank | | + getSuit(): Suit | |______________________| ``` This diagram is divided into three sections: 1. **Class Name**: The name of the class (`PlayingCard`). 2. **Data Fields**: Instance variables (`cardRank` and `cardSuit`), which are of types `Rank` and `Suit`. 3. **Methods**: Functions that can be used to set and get the values of `cardRank` and `cardSuit` (`setRank`, `setSuit`, `getRank`, and `getSuit`). Less often, you might have two classes which have an “is-a” relationship, where one class is a more general class, while the second class is a more specialized version of the original class. A blackjack program might have a `BlackJackCard` class which **is a** `PlayingCard`. Notice the relationship is not symmetrical: every `BlackJackCard` **is a** `PlayingCard`, but not every `PlayingCard** is a** `BlackJackCard`.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Reference Types in Function
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
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education