0% found this document useful (0 votes)
10 views3 pages

Python-EV

The document outlines two programming tasks: creating a Pagination class for handling paginated content and a CoffeeShop class for managing coffee shop orders. The Pagination class must include methods for navigating through pages and handle edge cases for page numbers, while the CoffeeShop class should manage orders, menu items, and provide various functionalities related to order fulfillment and menu management. Both classes emphasize object-oriented programming principles and method chaining.

Uploaded by

cajim40510
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Python-EV

The document outlines two programming tasks: creating a Pagination class for handling paginated content and a CoffeeShop class for managing coffee shop orders. The Pagination class must include methods for navigating through pages and handle edge cases for page numbers, while the CoffeeShop class should manage orders, menu items, and provide various functionalities related to order fulfillment and menu management. Both classes emphasize object-oriented programming principles and method chaining.

Uploaded by

cajim40510
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Lab (6)

1) Pagination Class with OOP


Your task is to create a class to handle paginated content in a website. A
pagination is used to divide long lists of content in a series of pages.

The pagination class will accept 2 parameters:

1. items (default: []): A list of contents to paginate.

2. pageSize (default: 10): The amount of items to show in each page.

So, for example we could initialize our pagination like this:

And then use the method getVisibleItems to show the contents of the paginated list.
You will have to implement various methods to go through the pages such as:

• prevPage

• nextPage

• firstPage

• lastPage

• goToPage

Here's a continuation of the example above using nextPage and lastPage:

Notes

• The second argument (pageSize) could be a float, in that case just convert it to
an int (this is also the case for the goToPage method)

• The methods used to change page should be chainable, so you can call them one
after the other like this: p.nextPage().nextPage()

• Please set the p.totalPages and p.currentPage attributes to the appropriate number
as there cannot be a page 0.

• If a page is outside of the totalPages attribute, then the goToPage method should go
to the closest page to the number provided (e.g. there are only 5 total pages,
but p.goToPage(10) is given: the p.currentPage should be set to 5; if 0 or a negative
number is given, p.currentPage should be set to 1).
2) Coffee Shop

Write a class called CoffeeShop, which has three instance variables:

1. name: a string (basically, of the shop)


2. menu: a list of items (of dict type), with each item containing the item (name of
the item), type (whether a food or a drink) and price.
3. orders: an empty list

and seven methods:

1. add_order: adds the name of the item to the end of the orders list if it exists on
the menu, otherwise, return "This item is currently unavailable!"
2. fulfill_order: if the orders list is not empty, return "The {item} is ready!". If
the orders list is empty, return "All orders have been fulfilled!"
3. list_orders: returns the item names of the orders taken, otherwise,
an empty list.
4. due_amount: returns the total amount due for the orders taken.
5. cheapest_item: returns the name of the cheapest item on the menu.
6. drinks_only: returns only the item names of type drink from the menu.
7. food_only: returns only the item names of type food from the menu.

IMPORTANT: Orders are fulfilled in a FIFO (first-in, first-out) order.

You might also like