Objectives:
• Use an object with a list
• Use a list of objects

Write a class that encapsulates data for a sales person. Class SalesPerson has an ID number (int), a name (string), and a list of sales (float). It provides a constructor init that initializes ID and name, and initializes the list of sales to an empty list. Member methods for SalesPerson include:

• getter methods for ID and name. (Setters for these are not necessary.)

• enterSale(aSale) enters the parameter value into the list of sales.

• totalSales() returns Salesperson's sum total sales.

• getSales () returns a list of all sales – it must return a copy of the list, not an alias.

• metQuota(quota), a boolean method that returns True if the total sales meet or exceed the quota provided, and False if not.

• compareTo (otherPerson) that compares this Salesperson (self) to another (provided as a parameter) based on the values of their total sales amounts.

• a str() method that displays the ID, name, and total sales.

Test SalesPerson thoroughly before continuing.

Write a class to keep track of the sales made by different sales persons. Class SalesForce maintains a list of SalesPerson objects. The constructor has no parameters and should initialize the list. Member methods for SalesForce include:

• addData(fileName) accepts a file name as its only parameter. It inputs information for all salespersons from that file. Each line of the file with contain data in the form:
ID name Sales amounts.
Note that each line contains the id, name and sales amounts for one Salesperson. Each Salesperson may have 0 or more sales.

• quotaReport (quota) prints each salesperson's ID, name and total sales and whether or not the salesperson met the sales quota.

• topSalesPerson () prints the name and total sales amount of the salesperson with the highest sales amount. instead?  returns the Salesperson object representing the individual with the highest sales amount.

• individualSales (id) prints the sales record (all of his sales) and the total of his sales for the employee with the ID specified. If there is no employee with the given ID, the method prints an appropriate message.

We have provided SalesTestDriver, which contains a main method that inputs the name of the file from which the sales information is to be read, instantiates an object of type SalesForce, invokes the SaleForce getData() method with the file name, invokes the SaleForce quotaReport() method with a quota amount, invokes the SaleForce topSalesPerson() method and invokes the SalesForce individualSales() method a couple of times. Test data are provided in the file salesdata.txt.

Dont really have a clue how to write
Any help would be greatly appriciative

Recommended Answers

All 4 Replies

There are many Python tutorials around, just Google. Also the vegaseats sticky message threads and the code snippets archive can be helpful.

SalesPerson

This should give you a start:

# create a simple class SalesPerson

class SalesPerson:
    # self keeps track of the instance
    def __init__(self, id, name, sales_list=[]):
        self.id = id
        self.name = name
        self.sales_list = sales_list


# tom's list of sales for the last four months
sales_list_tom = [2345.77, 1879.13, 2873.11, 897.44]
# create an instance for tom
# SalesPerson(id, name, sales_list)
tom = SalesPerson(1234, "Tom Hotski", sales_list_tom)

# bob's list of sales for the last four months
sales_list_bob = [7345.12, 6551.65, 4773.88, 8984.05]
# similarly create an instance for bob
bob = SalesPerson(1340, "Bob Lardo", sales_list_bob)

# test
print(tom.id)
print(tom.name)
print(tom.sales_list)

print('-'*50)

print("Total sales of %s = $%6.2f" % (bob.name, sum(bob.sales_list)))

'''my output >>>
1234
Tom Hotski
[2345.77, 1879.13, 2873.11, 897.44]
--------------------------------------------------
Total sales of Bob Lardo = $27654.70
'''

Lardmeister is doing it just right Python way, unfortunately looks like you are expected to mutilate it with unnecessary getters, against conventions naming, unnecessary functions (see line 29 of Lardmeister, clear enough for me)....

It is by the way __str__ method not str. And it does not display but returns string representation.

Tony is right, looks like the problem was a holdover from another less modern language given by an uninspiring teacher. Actually, boring teacher would be more to the point.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.