Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior.
Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X.
It captures the data and actions that are common to all team members. The team member class is not specific to any kind of team member. Name the class appropriately for its purpose. It defines what is common about all team members, for example a string variable to hold a name.
This class definition must include the following:
Define a constructor function to create objects built from this class. The statements in the block of this function must declare and initialize all TeamMember class variables.
Declare and initialize a class data variable to hold the name of the character as a string. Set its initial value to an empty string.
Define another Python class that inherits from the team member class X, so it will get all data and functions from X For this writeup we will call this class SeniorX. This class is a more specific type of team member that is senior ranking Name the class appropriately for its purpose.
This class definition must include the following:
One function as a constructor. In the block declare/initialize all class data variables, defined here or inherited.
Declare/initialize a data variable that means something unique to this type of team member (your choice).
Define a function for giving an order to a junior member this function accepts as parameter a junior team member type object.
In the indented block of statements do the following:
Print out the order being given (a string. You can use a constant string like ’Do a push up’), and the name of the junior member that will receive the order.
Call the order receiving function on the junior member object, passing in the order.
Define another Python class that inherits from the team member class X For this writeup we will call this class JuniorX. This class is a more specific type of team member that is a junior team member who takes orders from senior members.
The indented block for this function must include:
One constructor function. The block of statements for this function must set the value of all class data variables, defined here or inherited.
In the constructor declare/initialize one data variable unique to this type of team member (your choice).
Define a function for receiving an order from a senior member: This function accepts as parameter a string of orders. In the statement block for this function definition complete the order by printing it out along with the name of the junior member who is completing the order.
Outside and after your class definitions, write a main function definition to demonstrate using the classes. Its header line would be like def main (): In the indented block for main, write statements that do the following:
• Call the senior team member constructor function to create a senior team member object and save it in a variable.
• Call the junior team member constructor function to create a junior team member object and save it in a variable.
• Call the order giving function from a senior member object, passing in the junior member object.
Finally, using SQL figure out how to save one of your objects into a database within your code’s directory and then retrieve it back out of the database, then print out its contents.
So the task in hand is to create three classes such that :
the code for the same is :
text code for the same is :
#uncomment below to use db fucntions.
"""from sqlalchemy import Column, Integer,String
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import
declarative_base
#uncomment these lines to create a database:
#engine = create_engine('mysql://user:password@server')
#engine.execute("CREATE DATABASE dbname")
#engine.execute("USE dbname")
engine = create_engine('mysql:////folder/databasename') #to
connect to the already formed database.
Base = declarative_base(bind=engine) #to bind the database and
engine api.
class Member(Base): #class to fill the column of our
table.
__tablename__ = 'member'
mid = Column(Integer, primary_key=True)
fn = Column(String(20))
ln = Column(String(20))
age = Column(Integer) #to set the attribute types.
def __init__(self, senior):
self.mid = senior.mid
self.fn = senior.fn
self.ln = senior.ln
self.age = senior.age #sets the attribute values.
Base.metadata.create_all() #creates the schema / table for above mentioned table specification.
Session = sessionmaker(bind=engine) #creates a session
to run the add or retrieve.
s = Session() """
class TeamMember: #creates a generic class
def __init__(self,mid,fn,ln,age): #constructor to initialize basic
details like id , name , age
self.mid = mid
self.fn = fn
self.ln = ln
self.age = age
self.year = "" #unique identifier for senior or junior type member
(string)
def get_mid(self): #fucntion to print id.
print("MemberId: "+str(self.mid))
def get_name(self): #function to print name
print("Name: "+self.fn+" "+self.ln)
def get_age(self): #function to print age
print("age: "+str(self.age))
def __repr__(self): #string reputation built-in function to return
year as string.
return self.year
class SeniorMember(TeamMember): #SeniorMember class inheriting
TeamMember class
def __init__(self,mid ,fn,ln,age):
super().__init__(mid,fn,ln,age) #calling super class
constructor
self.year = "Senior" #assigning unique identifier.
def give_order(self,junior): #fucntion to give order to junior
member
order = input("Enter the order you want to give to "+junior.fn+"
"+junior.ln+": ") #taking order as input.
junior.recieveorder(order) #calling recieveorder fucntion of
JuniorMember class.
class JuniorMember(TeamMember): #JuniorMember class inheriting
TeamMember class to represent junior memeber.
def __init__(self,mid,fn,ln,age):
super().__init__(mid,fn,ln,age)
self.year = "Junior" #assigning unqiue identifier.
def recieveorder(self,order): #function to take an order as string
and print it.
print(self.fn+" "+self.ln+" has recieved order as:
"+str(order))
def main(): #driver fucntion.
adam = SeniorMember(1,"Adam","Frisk",18) #creating an objec of
SeniorMember class.
john = JuniorMember(2,"John","Snow",12) #creating an objec of
JuniorMember class.
adam.get_name() #getting name and other details.
adam.get_age()
print(adam)
john.get_name()
john.get_age()
print(john)
adam.give_order(john) #calling give_order function through adam
object and passing john as JuniorMember class object.
#uncomment below code to use db functions.
# ad = Member(adam) #creating an objec of Member class and passing
the SeniorMember class object to store.
# s.add_all(ad) #creating a list of objects to be stored
# s.commit() # adding to the database.
# for m in s.query(Member): #for all the objects stored in member
class / table
# print(str(m.mid)+" "+m.fn+" "+m.ln+" "+str(m.age)) #prints the
information from the db
main()
Write three object-oriented classes to simulate your own kind of team in which a senior member...
Write a class called Player that has four data members: a string for the player's name, and an int for each of these stats: points, rebounds and assists. The class should have a default constructor that initializes the name to the empty string ("") and initializes each of the stats to -1. It should also have a constructor that takes four parameters and uses them to initialize the data members. It should have get methods for each data member. It...
- Classes Write a C++ program that creates a class called Date that includes three pieces of information as data members, namely: month (type int) day (type int) year (type int). Program requirements: - Provide set and a get member functions for each data member. - For the set member functions assume that the values provided for the year and day are correct, but in the setMonth member function ensure that the month value is in the...
Write method createTeams() that Has no parameters Has return type void Instantiate the member variable of type ArrayList<Team> Instantiates two instances of class Team one for TeamOne one for TeamTwo set names for each team as appropriate add each instance to the ArrayList<Team> member variable Instantiate the member variable of class Scanner passing “System.in” as the argument to the constructor Using System.out.println() static method, prompt the user for the human player’s name Instantiate an instance of class String set equal...
In object-oriented programming, the object encapsulates both the data and the functions that operate on the data. True False Flag this Question Question 101 pts You must declare all data members of a class before you declare member functions. True False Flag this Question Question 111 pts You must use the private access specification for all data members of a class. True False Flag this Question Question 121 pts A private member function is useful for tasks that are internal...
A Java Program Purpose: Work with Abstract classes. Purpose: Abstract classes are import because they ensure than any children which inherit from it must implement certain methods. This is done to enforce consistency across many different classes. Problem: Implement a class called Student. This class needs to be abstract and should contain a String for the name, and a String for the major (and they should be private). The class must have a constructor to set the name and major....
You are a senior team lead for a fledgling software engineering firm. In order to meet a tight deadline, you have hired a freelance programmer to remotely assist you and your small team. To ensure that this freelancer can deliver usable code, you ask them to submit a simple header file named test.h that contains a definition for a class named Test. You specify that this Test class must contain one private, bool-typed member variable named b and a corresponding...
In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...
About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...
1. Write a program which have a class named as “Student”, while the data members of the class are,a. char name[10],b. int age;c. string color;d. string gender;e. double cgpa;and the member function “print()”, is just to display these information.1. You need to create 3 objects of the “Student” class.2. Initialize one object by the default constructor having some static values.3. Initialize the second object by the parameterized constructor, while you need to pass values for initialization.4. Initialize the third object...
8). Name five of the fundamental ter ns which encompass object-oriented programming 9). Write a class called NumberOfGoals that represents the total number of goals scored by a ootball team. The NumberOfGioals class should contain a single integer as data, representing the number of goals scored. Write a constructor to initialize the number of goals to Zero. 10). Write a set of instructions to prompt the user for an int value and input it using the Scanner class into the...