BDA100代写,BDA100作业代写,python程序代写
This assignment is designed to reinforce the subject material covered in the learning modules and encourage students to work consistently throughout the semester. The assignment gives student the opportunity to demonstrate their skill in:
• Solving fairly complex problem involving the design of more than one user defined class.
• Using list to maintain a collection of objects and allow management of them.
• Managing an application which involves a collection of objects.
• Writing and using methods which enable objects to show desired behaviors.
• Using and complying with a supplied specifications for classes to be written.
• Retrieving data from and writing data to files.
• Using good programming style.
The assignment assesses the following learning outcomes:
CLO 3: Construct programs to solve computing problems using programming and object- oriented concepts
B. Overview
Crisis Relief Services (CRS) is an NGO (Non Government Organization) that aims to help people who are facing crises arising from natural disasters such as flood and earthquakes. The CRS staff consists of managers and administrators, and they are governed by a Board of Directors. CRS has a large pool of volunteer. When a natural disaster occurs, one of the CRS staff will take the lead to organize a trip to the disaster area to provide relief services.
For this assignment, you are going to develop an application which helps CRS staff to manage his/her volunteers. The problem focuses on a container class of user-defined objects and the main features being assessed include your ability to handle several classes working together, the dynamic adding of new objects to a list and searching the list for particular objects.
C. Task
You are to write two source files as described below:
• The first file named crsApp.py, should contain the following two classes:
• The first is a class called volunteer which defines a simple object type representing a registered volunteer.
• The second class called volunteerList defines objects which are containers of food objects.
• The second file named crsDriver.py defines a Python application, with main method, which creates one volunteerList object and allows the various methods of volunteer to be called. This class will be an interactive application using the keyboard and the screen to interact with a human operator. It will not do calculations itself but will immediately pass user inputs as arguments to methods of volunteerList class.
NOTE: The final application will only execute correctly when both files have been defined completely and correctly but don't wait until you have completely written the two classes before you start testing your code.
The files
The files you will require are:
Class volunteer [saved in crsApp.py]
Each volunteer recorded will have 4 instance variables:
• name of the volunteer (a string, restricted to a maximum of 20 characters)
• age of the volunteer (an integer)
• type of volunteer (a string, valid value would be ‘f’/ ‘F’ for flood, ‘p’/’P’ for pandemic,
‘e’/’E’ for earthquake, and ‘t’/’T’ for tsunami)
• hour of contribution (an integer)
The methods of class volunteer should include:
❑ An initialiser (constructor) method (__init__) which accepts FOUR attributes for a volunteer - name, age, type of volunteer and hour contribution. The method should initialise its object's attributes with these parametric values. Note that the volunteer’s age and hour must be valid (positive value). User will be asked to input the age and hour value again until a valid value is given.
❑ Areader(getter)methodforeachofthefourattributes.Thatis,asimple'getter'method for the name, age, volunteer type and hour.
❑ A writer (setter) method for each of the attributes. Note that the age and hour will only be changed if the corresponding setter method receives a positive age and hour value.
❑ A method named contributionCounter which accept one parameter (hour of contribution) and return the contribution in minutes based on the hour input by user. The minutes of contribution is calculated based on the following:
minutes = hour * 60
For example, 2 hours of contribution is equivalent to 120 minutes (2x60).
A method __eq__ that takes another volunteer as parameter, and returns true if both volunteers are the same, false otherwise. Two volunteers are considered equal if they are in the same type.
❑ Amethod__lt__thattakesvolunteerasparameterandanothervolunteer,trueiftheage of this volunteer is lesser than the other parametric volunteer.
❑ Amethod__le__thattakesanothervolunteerasparameter,andreturnstrueifthehour of this volunteer is lesser than the other parametric volunteer.
❑ A string method (__str__) which returns a single string containing the details of a volunteer. Such a string can be formed by concatenating the values of the four attributes name, age, volunteer type and hour in the format:
One sample output is as shown below:
Lo Ming Yee aged 18 is a tsunami volunteer which has contributed 5 hours.
It is recommended that once you have written the volunteer class, you create a tiny program to test it. The testing program should be used to create one or two volunteer objects and call some of the volunteer methods. Run the test program to check your work.
Class foodList [written and saved in the same file as volunteer in crsApp.py]
This class is to be defined in the same file as class Volunteer. It declares a class of object which maintains a list of volunteer objects. It will contain methods which enable the list to show the appropriate behaviors as required by the menu.
The volunteerList class should have a CSR group name (of type string) which the list of volunteer belongs to, and a collection of volunteer objects, no additional attribute is required.
The volunteerList class must also contain some methods which allow the collection of volunteer to be managed. The methods of class volunteerList should include:
1. An initialiser (constructor) (__init__) with one argument of type string, which is used to initialise the CSR group name which the volunteer belongs to. The constructor should also initialise an empty list for volunteers’ details.
2. Getter (reader) methods for accessing the attributes, name and volunteer list, but only setter (writer) method for name.
3. A method named addVolunteer which accepts an argument object of class volunteer. This method will store a reference to this volunteer object into the list.
4. A method named removeVolunteer that takes an integer representing the index of the volunteer in the list to withdraw from the volunteer list.
5. A method named noOfVolunteer which returns the number of volunteer currently stored in the list.
6. A method named displayVolunteer which returns detail of volunteer stored in the list as string.
7. A method named totalhour that does not accept any argument but returns the total hour for all the volunteer in the list.
8. A method highesthour which finds and returns the detail of volunteer with the highest hour. Details returned include name, age, volunteer type and hour – one volunteer per line. If there is more than one volunteer with same highest contribution hour, this volunteer will also be displayed. There is a possibility to have more than one volunteer displayed.
9. A method named findVolunteerByType which finds volunteer based on its type. This method accepts a character as the type of volunteer. If there is no such type of volunteer in the collection, returns "not found", otherwise returns a string giving details of all the volunteer in the required type. Details returned include name, age, and hour only – one volunteer per line.
10. A method named totalhourByType that accepts one argument, type of volunteer and returns the total hour for all the volunteer with that particular type in the list.
11. A method saveToFile that accepts a string representing the filename to save, and all volunteer will be saved to a text file, one per line, with each attribute separated by comma.
12. A method loadFromFile that accepts a string representing the filename where the data is to load from.
When you have written the volunteerList class - test it by creating a volunteerList object and invoking the methods from a small test program.
csrDriver.py
The aim of this file is to provide a user-interface for a modest application which uses a volunteerList container class. The user-interface is written as a 'console' application using the normal screen and keyboard to interact with a user via a simple text-based menu.
The user-interface should create a single volunteerList object and provide a menu of choices to the user.
