iut-cse/OOKata

Santa's List

Ela-Zaman opened this issue · 0 comments

Overview

Santa has been using the same system to keep track of Wicked or Nice people for years now. His system has become slow and needs to be updated. He has asked you to demonstrate your ability to use OOP to construct a gift tracking system for him.

Task

  1. Create a system to store details of people in on his list. Each Person should have the following details stored):
    Name , Location,Gift they would like,If they have been wicked or nice
  2. Allow Santa to
    • enter a new person onto the list
    • Remove a person from the list
    • Update or change the person's details on the list
  3. The system should produce 2 lists, each list should be presented in a suitable way and display the total number of people on the list:
    • one wicked
    • one nice
  4. Santa is on a budget this year, change your system so that any wicked people are automatically given a lump of coal as a gift.
  5. As Santa delivers each gift, he would like the system to allow him to search for a person and record that the gift has been delivered.
  6. Santa has had problems with the taxman this year, so he would like the system to record how much each gift was. Adapt your system to store the cost of the gift, it would be nice if the system could assign the cost of the gift automatically - but Santa would be happy to enter the price himself.
  7. He would then like an analysis of how many of each gift has been given, the total amount he has spent on each of the gift types.

Example

Here is an example in python of the class definition (CONSTRUCTOR) for the person

# Language: Python
class Person():
    def __init__ (self,name,location,prsentidea,nice):
        self.name = name
        self.location = location
        self.prsentidea = prsentidea
        self.nice = nice

        self.giftgiven = "N"
        self.costofgift = 0

Withing the constructor you can also add code which will run automatically - this code could be added below the properties

# Language: Python
if self.prsentidea.lower() == "train":
            self.costofgift = 100
        elif self.prsentidea.lower() == "pc":
            self.costofgift = 50
        else:
            self.costofgift = 20

You could also add some methods to update if the gift had been given or to update the price of the gifts

# Language: Python
def updategift(self):
        self.giftgiven = "Y"

    def updatepriceofgift(self):
        if self.prsentidea.lower() == "train":
            self.costofgift = 100
        elif self.prsentidea.lower() == "pc":
            self.costofgift = 50
        else:
            self.costofgift = 20

Here a sample of the code to create an object of type person

# Language: Python
inputlocation = input("please enter persons location : ")
inputpresentidea = input("please enter persons present : ")
inputnice = input("please enter if the persons nice? : ")
persontoadd = person(inputname,inputlocation,inputpresentidea,inputnice)
listofpeople.append(persontoadd)

Source

https://www.tes.com/teaching-resource/christmas-coding-challenge-using-oop-12223499


Reminders

  • React to the problem if you find it interesting and helpful. This will help others to easily identify good problems to solve.
  • Feel free to comment about the problem. Is the description unclear? Do you think it is too easy or too difficult than what is mentioned? Comment about it.
  • Discussion about the solution is OK. But do not paste a solution here. Give a link to the solution instead.
  • Do you have an interesting problem? Post it.