wing code provides the expected output. [addGrandSlams() method should work any number of parameters assuming that  the parameter number will be an even number and greater than 1] class Player:      total_player = 0      def __init__(self,nam

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

Design TennisPlayer class which inherit from Player class so that the 
following code provides the expected output.
[addGrandSlams() method should work any number of parameters assuming that 
the parameter number will be an even number and greater than 1]

class Player:
     total_player = 0

     def __init__(self,name,country):
         self.name = name
         self.country = country

     def __str__(self):
         return  'Name: '+self.name+'\nCountry Name: '+str(self.country)


# Write your codes here.
# Do not change the following lines of code. Order of the year in printing 
grand slams doesn’t matter.
p1 = TennisPlayer("Rafael Nadal", Spain)
print("==============================")
p1.addGrandSlams('Wimbledon',2021, 'French Open',2021,'Australian 
Open',2020)
print("==============================")
print(p1)
print("==============================")
p2 = TennisPlayer("Andy Murray", 'UK')
print("==============================")
p2.addGrandSlams('Wimbledon',2017, 'US Open',2008,'Australian 
Open',2017,'Australian Open',2018)
print("==============================")
print(p2)
print("==============================")
print('Total Players: ', Player.total_player)

OUTPUT:
New Tennis Player Added -Rafael Nadal from Spain
==============================
==============================
Name: Rafael Nadal
Country Name: Spain
Grand Slams:
2021: ['Wimbledon','French Open']
2020: ['Australian Open']
==============================
New Tennis Player Added - Andy Murray from UK
==============================
==============================
Name: Andy Murray
Country Name: UK
Grand Slams:
2018: ['Australian Open']
2017: ['Wimbledon','Australian Open']
2008: ['US Open']
==============================
Total Players: 2

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage