The Doctor program described in Chapter 5 combines the data model of a doctor and the operations for handling user interaction. Restructure this program according to the model/view pattern so that these areas of responsibility are assigned to separate sets of classes. The program should include a Doctor class with an interface that allows one to obtain a greeting, a signoff message, and a reply to a patient’s string. To implement the greeting, define a method named greeting for the Doctor class. To implement the signoff message, define a method named farewell for the Doctor class. Both greeting and farewell should return a string with a greeting or farewell message respectively. The reply function is defined for you, it should be added as a method for the Doctor class. The rest of the program, in a separate main program module, handles the user’s interactions with the Doctor object. Develop this program with a terminal-based user interface. Note: The program should output in the following format: Hello, how can I help you today? > I am sick You seem to think that you are sick? > Yes And what do you think about this? > I am not feeling good Did I just hear you say that you are not feeling good? > Yes Why do you believe that Yes? > My nose is running I would like to hear more about that. > I have a headache too You seem to think that you have a headache too? > Correct Go on. > It doesn't stop Did I just hear you say that It doesn't stop? > Correct Go on. > That's it And what do you think about this? > quit Have a nice day

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

The Doctor program described in Chapter 5 combines the data model of a doctor and the operations for handling user interaction. Restructure this program according to the model/view pattern so that these areas of responsibility are assigned to separate sets of classes.

The program should include a Doctor class with an interface that allows one to obtain a greeting, a signoff message, and a reply to a patient’s string.

To implement the greeting, define a method named greeting for the Doctor class. To implement the signoff message, define a method named farewell for the Doctor class. Both greeting and farewell should return a string with a greeting or farewell message respectively. The reply function is defined for you, it should be added as a method for the Doctor class.

The rest of the program, in a separate main program module, handles the user’s interactions with the Doctor object. Develop this program with a terminal-based user interface.

Note: The program should output in the following format:

Hello, how can I help you today?

> I am sick

You seem to think that you are sick?

> Yes

And what do you think about this?

> I am not feeling good

Did I just hear you say that you are not feeling good?

> Yes

Why do you believe that Yes?

> My nose is running I would like to hear more about that.

> I have a headache too

You seem to think that you have a headache too?

> Correct Go on.

> It doesn't stop

Did I just hear you say that It doesn't stop?

> Correct Go on.

> That's it

And what do you think about this? > quit Have a nice day!

```python
"""
File: doctor.py
Project 5
Conducts an interactive session of nondirective psychotherapy.
Adds a history list of earlier patient sentences, which can
be chosen for replies to shift the conversation to an earlier topic.
"""

import random

history = []

# All doctors share the same qualifiers, replacements, and hedges.

qualifiers = ['Why do you say that ', 'You seem to think that ',
              'Did I just hear you say that ',
              'Why do you believe that ']

replacements = {'i': 'you', 'me': 'you', 'my': 'your',
                'we': 'you', 'us': 'you', 'am': 'are',
                'you': 'i', 'you': 'I'}

hedges = ['Go on.', 'I would like to hear more about that.',
          'And what do you think about this?', 'Please continue.']

def reply(sentence):
    """Implements three different reply strategies."""
    probability = random.randint(1, 5)
    if probability in (1, 2):
        # Just hedge
        answer = random.choice(hedges)
    elif probability == 3 and len(history) > 3:
        # Go back to an earlier topic
        answer = "Earlier you said that " + \
                 changePerson(random.choice(history))
    else:
        # Transform the current input
        answer = random.choice(qualifiers) + changePerson(sentence)
    # Always add the current sentence to the history list
    history.append(sentence)
    return answer

def changePerson(sentence):
    """Replaces first person pronouns with second person pronouns."""
    words = sentence.split()
    replyWords = []
    for word in words:
        replyWords.append(replacements.get(word, word))
    return " ".join(replyWords)

def main():
    """Handles the interaction between patient and doctor."""
    print("Good morning, I hope you are well today.")
    print("What can I do for you?")
    while True:
        sentence = input("\n>> ")
        if sentence.upper() == "QUIT":
            print("Have a nice day!")
            break
        print(reply(sentence))

# The entry point for program execution
if __name__ == "__main__":
    main()
```
Transcribed Image Text:```python """ File: doctor.py Project 5 Conducts an interactive session of nondirective psychotherapy. Adds a history list of earlier patient sentences, which can be chosen for replies to shift the conversation to an earlier topic. """ import random history = [] # All doctors share the same qualifiers, replacements, and hedges. qualifiers = ['Why do you say that ', 'You seem to think that ', 'Did I just hear you say that ', 'Why do you believe that '] replacements = {'i': 'you', 'me': 'you', 'my': 'your', 'we': 'you', 'us': 'you', 'am': 'are', 'you': 'i', 'you': 'I'} hedges = ['Go on.', 'I would like to hear more about that.', 'And what do you think about this?', 'Please continue.'] def reply(sentence): """Implements three different reply strategies.""" probability = random.randint(1, 5) if probability in (1, 2): # Just hedge answer = random.choice(hedges) elif probability == 3 and len(history) > 3: # Go back to an earlier topic answer = "Earlier you said that " + \ changePerson(random.choice(history)) else: # Transform the current input answer = random.choice(qualifiers) + changePerson(sentence) # Always add the current sentence to the history list history.append(sentence) return answer def changePerson(sentence): """Replaces first person pronouns with second person pronouns.""" words = sentence.split() replyWords = [] for word in words: replyWords.append(replacements.get(word, word)) return " ".join(replyWords) def main(): """Handles the interaction between patient and doctor.""" print("Good morning, I hope you are well today.") print("What can I do for you?") while True: sentence = input("\n>> ") if sentence.upper() == "QUIT": print("Have a nice day!") break print(reply(sentence)) # The entry point for program execution if __name__ == "__main__": main() ```
The image shows a blank text editor screen with a file open named "doctor.py". The editor appears to be a simple programming environment, likely one that supports Python coding due to the file extension ".py". There are no visible graphs, diagrams, or code present in the text editor at the moment. The interface includes basic elements like a tab to identify the open file and a toolbar for file management. The absence of content suggests it is ready for new Python code to be written.
Transcribed Image Text:The image shows a blank text editor screen with a file open named "doctor.py". The editor appears to be a simple programming environment, likely one that supports Python coding due to the file extension ".py". There are no visible graphs, diagrams, or code present in the text editor at the moment. The interface includes basic elements like a tab to identify the open file and a toolbar for file management. The absence of content suggests it is ready for new Python code to be written.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Developing computer interface
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
  • SEE MORE 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