联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> CS作业CS作业

日期:2025-02-13 09:55

Assignment 4 - Emoji Carousel

Due Date: April 8th, 2024 at 23:55

Percentage overall grade: 5%
Penalties: No late assignments allowed
Maximum Marks: 100

Pedagogical Goal: Refresher of Python and hands-on experience with algorithm coding, input validation, exceptions, ANSI escape codes, queues, doubly linked lists and data structures with encapsulation.

Read the whole document before starting to solve the Assignment problem.

Submit only your work. While you can collaborate and help each other, do not share code. If you collaborate, acknowledge your collaborator in the code comments.

Follow the Software Quality Requirements.

Assignment Specifications:

Assignment 4 FAQ
Problem: Emoji Carousel

You are an employee at Zoogle Inc., and fortunately, you are part of an R & D team responsible for creating blueprints for various features of their popular operating system. They never had a “Circular Image Carousel” feature built into their OS. Your job is to create a bare-bones interpretation of that idea using a Circular Doubly-Linked List.

For this assignment, instead of images, you will use emojis from a JSON file (Remember them from CMPUT 174? Refer to the refresher at the bottom of the assignment description).

Each element of this carousel will be a doubly-linked list node, which will have a reference to the next/”right” node, previous/”left” node, and data about what is in that node.

The doubly-linked list node class should have methods to:

1. Initialize the attributes of the class

2. Retrieve the data stored in it

3. Change the data stored in it

4. Get the previous/left node

5. Get the next/right node

6. Set the previous/left node

7. Set the next/right node

Any other required methods can be created as per your needs. Appropriate Exceptions should be raised if necessary.

Your carousel will be a fixed-length modified doubly-linked list — Going right/next on the last element will take you back to the first one, and going left/previous on the first element will take you to the last element. There are multiple ways to create an efficient class for this, but the class should have methods for initializing, adding a node, removing a node, and getting the active/current node. Initializing proper attributes is also based on your understanding of the project. The class should be named CircularDoublyLinkedList or DoublyLinkedList.

You have to create a visual depiction with shapes and emojis. For this task, you will use a dataset of emojis in a JSON file and a art.txt file with the shapes you need in order to create a visual representation.

The art.txt file has the ASCII art needed for the visual representation. All the figures are essential and should be present in your version of art.py as they handle different cases of visual representation of the carousel. With slight modifications and formatting, you can put emoticons in the place of “().” (Hint: You might need to look up how to print symbols which are part of escape sequences)

Remember that you are not required to read this .txt file; copy-paste the content into a new “art.py” file and create appropriate functions for use in the carousel.py file.

To use the JSON file, import the JSON module in your carousel.py file, read the file with the appropriate encoding, and extract the data into a suitable data type for further use.

User Interface Implementation

You must implement the following methods in the Carousel class:

· add: Responsible for adding a new node to the circular doubly-linked list.

· goLeft and goRight: Functions to navigate the carousel by moving to the previous or next node.

· delete: Removes the current node from the carousel.

· getInfo: Retrieves and displays information about the current node, including its Name, Symbol, and Class.

· quit: Allows the user to exit the program at any point.

Remember to Initialize the circular doubly-linked list with a compulsory attribute max_size. This max_size should be a constant of value 5.

Additionally, here is the scenario to keep in mind:

1. Initially, when there’s nothing in the carousel, the user will be prompted to enter “ADD” to add a node or “Q” to quit.

Type any of the following commands to perform. the action:

ADD: Add a emoji frame.

Q: Quit the program

>> add

What do you want to add?

>> tiger 

1. After the first addition, the carousel will be displayed with only one frame. with the emoji. Again, the user will be prompted to enter an input with two additional options, specifically “DEL” for delete and “INFO” for information.

 

1. The user can go left or right after adding the second frame.  Two more options: L: Move left and R: Move right will now be included in the menu.  The carousel will display three frames, the left frame. being the previous node and the right frame. being the next node. 
Note: Upon entering the emoji for the second node, your output shows the first node on both the leftmost and rightmost sides, with the second one in the center. This is so because our doubly-linked list wraps around. Please note that your double-linked list data structure DOES NOT have duplicate nodes.  

 

1. As more nodes are added, moving left and right should work endlessly as the list wraps around i.e if we were to move left, our display would look like as follows:

 

1. Deletion of nodes works the same; if more than one node is in the list, the display should have three frames; only one frame. should be visible when only one frame. is left.
At most 3 frames should be displayed: the current frame, one on the left and one on the right.

2. The current (↓↓) always points to the middle frame. that is being displayed.  If delete is chosen, the current frame. will be removed from the doubly linked list and not displayed. The new current frame. would be the one on the left. If the frame. removed were the only one left in the carousel, no frame. would be displayed, just like when you run your code the first time.

Addition of Nodes

There are two scenarios for adding nodes to the carousel:

Adding a Node when the Doubly Linked List is Empty:

· In this case, no specific input is required from the user regarding the insertion position.

· The first node is added directly.

Adding a Node when there is more than one node in the Doubly Linked List:

· Users can navigate the carousel using the goLeft and goRight methods to change the current node.

· After positioning to the desired node, the user is prompted to specify whether they want to insert the new node to the left (L) or right (R) of the current node. If the carousel has available capacity, the selected emoji is inserted at the chosen position.

· However, if the carousel is at full capacity, an exception should be raised with the message "You cannot add emojis! Carousel is Full."

Please follow this scenario to understand the process of inserting a node.

1. The user must add nodes. The user should be able to search the emojis using their names. (In the example below, the user is searching for a tiger emoji)

 

1. Check if the word entered by the user exists in the emojis' names. If not, then prompt the user again to enter a word.

(Optional-will not be marked) For a slightly advanced way to find the emoji that matches the word entered by the user, you can implement the pseudo spell checker based on Levenshtein distance. Your task is to find the emoji's name out of the JSON data closest to the user input and then confirm if that’s the emoji the user is looking for.

 

1. Once the emoji matches the word, the relevant data (Class, Symbol, Name; not precisely in this order) should be retrieved and added to the new node.

2. This new node should be added to the appropriate location per user inputs. The first node should be added without asking the user for location, as there’s nothing inside the list. If the list is not empty, the user should be prompted to specify left or right so that the node can be added to the left or right side of the current/active node.

Example of Node being added the first time:

Example of a Node being added the second time onward:

“DEL” is supposed to remove the active/current node. After a successful deletion, the current node will be the one to the left of the deleted node.

As previously stated, “INFO” stands for information, and that’s what it’s supposed to display. The information of the node should be presented in the following order: Name, Symbol, and Class. After showing the information, the user should be prompted to press any key to move forward. There should be a brief time gap of 1 second between the information display and asking for input.

You must use the os and time modules to make the demonstration presentable and less cluttered. You can use a time delay of one second to create an illusion of loading and clear the screen after executing commands of a functionality.

Here is a video demonstration:

Notice the pauses in the video. Those are the points where you have to implement the time delays. Also, make a note of the screen clearing and mimic the visual representation to the best of your ability.

JSON Refresher

This section serves as a short introduction and/or refresher to JSON. In Python, you can work with JSON data using the json module. It provides a way to encode and decode JSON data, allowing you to convert between JSON text and Python data structures. In this example, we will read from the following Pokémon JSON:

{

  "name": "Pikachu",

  "type": "Electric",

  "abilities": ["Static", "Lightning Rod"],

  "stats": {

    "hp": 35,

    "attack": 55,

    "defense": 40,

    "speed": 90

  }

}

To parse this JSON data, you can use the json.load() function to read the data directly from the file and store it in a dictionary (assume the JSON data is stored in a file named pokemon.json):

import json

with open('pokemon.json', 'r') as file:

    pokemon = json.load(file)

    print(pokemon['type'])

    print(pokemon['stats']['attack'])

After executing the above code, “Electric” and “55” are printed to the terminal. This is information directly from Pikachu’s JSON data entry.

Additionally, look up json.loads function on google if you want to learn more.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp