Design, implement and test a Python class, called SphereAlly, to be used by a galactic non-profit coalition, known as the Sphere Alliance, whose mission it is to help out any fellow galactic spheres who may be in need. A sphere ally is a member sphere that has a number of attributes, including how much it contributes to the coalition from the sphere's resources (known as "fruits of labour" funds). The SphereAlly class definition should include the following class variables, attributes (instance variables) and methods. Class variables: TotalAlliancePopulation is a class variable that holds the total population of all sphere allies (initialized to 0) TotalFOLContributions is a class variable that holds the total "fruits of labour" contributions made by all of the sphere allies to the Sphere Alliance (initialized to 1000 sphere coins) Instance variables: sphereName is the name of the sphere ally (default value of "unknown") repName is the name of the representative that deals with all Sphere Alliance issues (default value of "unknown") population is the population of the sphere ally (default value of 0) Also include the following methods: a constructor method to create an object of the class SphereAlly (be sure to include the default values for the parameters); don't forget to update the class variables appropriately as well – note that to update the TotalFOLContributions, the constructor should call the addContribution method as defined below accessor methods for each of the following instance variables: sphereName, repName, population a mutator method called updatePopulation that takes, as a parameter, a floating point number representing the percentage increase or decrease in a sphere's population (decrease will be a number/multiplier less than one, and increase will be a number/multiplier greater than one) and computes the amount of increase or decrease in the population for that sphere; in addition, the method updates the class variable TotalAlliancePopulation and also the instance variable population representing the current population of the sphere; for example, a parameter of 0.9 and a current sphere population of 1000 will mean the population should change to 900 (90 percent of 1000) and the total alliance population would go down by 100; using another example, a parameter of 1.2 and a current sphere population of 1000 will mean the population should change to 1200 (120% percent of 1000) and the total alliance population would go up by 200 a method called addContribution that computes the contribution that the sphere ally makes to the Sphere Alliance and adds it to the TotalFOLContributions; this is based on the sphere's fruits of labour funds and the percentage that the sphere is willing to give to the Sphere Alliance, both of which must be initialized before this method is called in the constructor a method called computePerCapita that computes the average fruits of labour contribution by each individual included in the population of the sphere; note that the per capita fruits of labour is calculated by dividing the total fruits of labour of a sphere by its population. fruitsOfLabour is the general funds on hand (in sphere coins) that the sphere ally is able to maintain regularly (default value of 0.0) contribPer is the percentage of their fruits of labour funds that the sphere is willing to contribute to the Sphere Alliance upon joining the alliance (default value of 0.0); e.g., 0.02 means the ally will contribute 2% of their funds Also include a main function to test the defined class as follows: create 2 SphereAlly objects for both sphere allies, print the sphere name, representative’s name, the population, the sphere's contributions and the sphere's per capita FOL funds, with appropriate descriptive labels as shown in the sample output (hint: it may be useful to define a __str__() method for this) update the population of the first object print the updated population and the per capita FOL funds of the first sphere object, with appropriate descriptive labels, as shown in the sample output print the total alliance population, with an appropriate descriptive label print the total FOL contributions, with an appropriate descriptive label find and print the name of the sphere with the higher per capita FOL funds, with an appropriate descriptive label Call the file containing your class and main function, sphere_alliance.py. Sample input/output: Sphere Name: Sphereogamma Rep Name: Emma Gamma Population: 5100 Contributions: 200.00 sphere coin(s) Per Capita FOL Funds: 1.96 sphere coin(s) Sphere Name: Sphereodelta Rep Name: Pelta Delta Population: 8100 Contributions: 615.00 sphere coin(s) Per Capita FOL Funds: 2.53 sphere coin(s) The updated population for Sphereogamma is 5610.0 The updated per capita fruits of labour funds is 1.78. Total Population for all Sphere Allies: 13710.0 Total FOL Contributions from all Sphere Allies: 1815.00 sphere coin(s) Sphereodelta has higher per capita FOL funds.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Design, implement and test a Python class, called SphereAlly, to be used by a galactic non-profit coalition, known as the Sphere Alliance, whose mission it is to help out any fellow galactic spheres who may be in need. A sphere ally is a member sphere that has a number of attributes, including how much it contributes to the coalition from the sphere's resources (known as "fruits of labour" funds). The SphereAlly class definition should include the following class variables, attributes (instance variables) and methods.

Class variables:

  • TotalAlliancePopulation is a class variable that holds the total population of all sphere allies (initialized to 0)

  • TotalFOLContributions is a class variable that holds the total "fruits of labour" contributions made by all of the sphere allies to the Sphere Alliance (initialized to 1000 sphere coins)

    Instance variables:

  • sphereName is the name of the sphere ally (default value of "unknown")

  • repName is the name of the representative that deals with all Sphere Alliance issues (default value of

    "unknown")

  • population is the population of the sphere ally (default value of 0)

    Also include the following methods:

  • a constructor method to create an object of the class SphereAlly (be sure to include the default values for the parameters); don't forget to update the class variables appropriately as well – note that to update the TotalFOLContributions, the constructor should call the addContribution method as defined below

  • accessor methods for each of the following instance variables: sphereName, repName, population

  • a mutator method called updatePopulation that takes, as a parameter, a floating point number

    representing the percentage increase or decrease in a sphere's population (decrease will be a number/multiplier less than one, and increase will be a number/multiplier greater than one) and computes the amount of increase or decrease in the population for that sphere; in addition, the method updates the class variable TotalAlliancePopulation and also the instance variable population representing the current population of the sphere; for example, a parameter of 0.9 and a current sphere population of 1000 will mean the population should change to 900 (90 percent of 1000) and the total alliance population would go down by 100; using another example, a parameter of 1.2 and a current sphere population of 1000 will mean the population should change to 1200 (120% percent of 1000) and the total alliance population would go up by 200

  • a method called addContribution that computes the contribution that the sphere ally makes to the Sphere Alliance and adds it to the TotalFOLContributions; this is based on the sphere's fruits of labour funds and the percentage that the sphere is willing to give to the Sphere Alliance, both of which must be initialized before this method is called in the constructor

  • a method called computePerCapita that computes the average fruits of labour contribution by each individual included in the population of the sphere; note that the per capita fruits of labour is calculated by dividing the total fruits of labour of a sphere by its population.

  • fruitsOfLabour is the general funds on hand (in sphere coins) that the sphere ally is able to maintain regularly (default value of 0.0)

  • contribPer is the percentage of their fruits of labour funds that the sphere is willing to contribute to the Sphere Alliance upon joining the alliance (default value of 0.0); e.g., 0.02 means the ally will contribute 2% of their funds

Also include a main function to test the defined class as follows:

  • create 2 SphereAlly objects

  • for both sphere allies, print the sphere name, representative’s name, the population, the sphere's

    contributions and the sphere's per capita FOL funds, with appropriate descriptive labels as shown in the

    sample output (hint: it may be useful to define a __str__() method for this)

  • update the population of the first object

  • print the updated population and the per capita FOL funds of the first sphere object, with appropriate

    descriptive labels, as shown in the sample output

  • print the total alliance population, with an appropriate descriptive label

  • print the total FOL contributions, with an appropriate descriptive label

  • find and print the name of the sphere with the higher per capita FOL funds, with an appropriate

    descriptive label
    Call the file containing your class and main function, sphere_alliance.py.

    Sample input/output:

    Sphere Name: Sphereogamma Rep Name: Emma Gamma Population: 5100 Contributions: 200.00 sphere coin(s) Per Capita FOL Funds: 1.96 sphere coin(s) Sphere Name: Sphereodelta Rep Name: Pelta Delta Population: 8100 Contributions: 615.00 sphere coin(s) Per Capita FOL Funds: 2.53 sphere coin(s) The updated population for Sphereogamma is 5610.0 The updated per capita fruits of labour funds is 1.78. Total Population for all Sphere Allies: 13710.0 Total FOL Contributions from all Sphere Allies: 1815.00 sphere coin(s) Sphereodelta has higher per capita FOL funds.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY