A. A list data structure unlike stacks and queues ensure items are added and removed from any location within the list. This is useful for manipulating some forms of storage or processing requirements. a. Nodes in a list can be added in two ways. Using diagrams, explain the two (2) forms of adding a new node to an existing list. [4 marks]
b. Using diagrams, explain how the head pointer can be implemented in a single list such that it does not have to change during additions and deletions. Your resulting list should have five (5) regular nodes. [3 marks]
c. Provide the algorithm and supporting diagram for updating your list with a single node at the front of the List. Name the currently added node “Q”. Your resulting list will now have six (6) regular nodes. [3 marks]
Create a GUI application “Address Book” which can be used to store and search the information of different people. The information can be: name, phone no, email, street address etc. Your project should have the following features:
1. A GUI where user can input the information of a particular people
2. A file where all information are stored. (You will have to append new info to the file. Otherwise the previous information will be lost.
3. A GUI in which the user will be able to see all the information, sorted by name. The information must come from the file where you stored user information. (Hint: use JTextArea to show all user info)
4. A GUI where the user will be able to search a person using his name or phone no. The search result should show the info of all the matched person
5. A GUI where the user will be able to edit the information of a specific person.
import java.util.EmptyStackException;
public class IntStackTest implements IntStack{ private int top = -1;
private int[] data;
private static final int DEFAULT_CAPACITY = 10;
public IntStackTest() {
data = new int[DEFAULT_CAPACITY];
}
public void push(int item) {
if (top == data.length - 1) resize(2*data.length);
data[++top] = item; }
public int pop() {
//if (isEmpty()) throw new EmptyStackException();
return data[top--]; }
private void resize(int newCapacity) { int[] newData = new int[newCapacity]; for (int i = 0; i <= top; i++) {
newData[i] = data[i]; }
data = newData; }
public static void main(String[] args) { int x;
IntStack s = new IntStackTest(); s.push(7);
s.push(4);
s.push(18);
4
x = s.pop(); System.out.println("pop() ---> " + x ); x = s.pop(); System.out.println("pop() ---> " + x ); x = s.pop(); System.out.println("pop() ---> " + x );
} }
A. Provide a graphical representation of the Stack when the above code is run
A. A single linked list provides pointers to the next node in the sequence.
Consider the below structure of the linked list and answer the questions that follow:
Assuming the front is the 1st node and the back is the Nth node, state and explain the running times for the below:
i. Find a node from the front. [2 marks]
ii. Find a node from the back. [2 marks]
iii. Insert a node at the front. [2 marks]
iv. Insert a node at the back. [2 marks]
v. Erase a node from the front. [2 marks]
vi. Erase a node from the back. [2 marks]
For this assignment, you are required to understand the Problem Frames and then model the following requirements using problem frames:
For an e-commerce store, an item is added to the shopping cart, as soon as, the "Add-to-Cart" button is pressed, however, whether the item can be processed for payment, will depend on whether the item is in inventory or not, when the customer is trying to make the payment. If the item is not in inventory, when the customer is trying to pay for it, then the customer should be informed, and the item is removed from the customer's cart.
B. Consider a problem to find the student who had the highest GPA for the 2020/2021 academic year. Using the below data set, answer the questions that follow: StudentGPA[2,2.5,4,4,4,3,3.5,3.3,3.1,2.1] i. Explain how a binary search algorithm can be used to solve this problem. [2.5 marks] ii. Explain how a sorting algorithm can be used to solve this problem. [2.5 marks] iii. Write the algorithm using the binary implementation. [2.5 marks] iv. Write the algorithm using the sorting implementation. [2.5 marks
Write a class named Pet,which should have the following data attributes:
a.__name(for the name of a pet)
__animal_type(for the type of animal that a pet is.Example values are ‘Dog’,
‘Cat’,and ‘Bird’)
__age(for the pet’s age)
The Pet class should have an__init__method that creates these attributes.
It should also have the following methods:
b.set_name:This method assigns a value to the__name field.
set_animal_type:This method assigns a value to the__animal_type field.
set_age:This method assigns a value to the__age field.
get_name:This method returns the value ofthe__name field.
get_animal_type:This method returns the value of the__animal_type field.
get_age:This method returns the value of the__age field.
3.Write an Employee class that keeps data attributes for the following pieces of
information:
a.Employee name
b.Employee number
Next,write a class named ProductionWorker that is a subclass of the Employee class.
The Production Worker class should keep data attributes for the following information:
c.Shiftnumber(an integer,such as 1 for morning shift,2 for evening shift)
d.Hourly payrate
Write the appropriate accessor and mutator methods for each class.
The organisation you work for has asked you to create an interactive application that will assist with the allocation of employees to a cell phone network provider and phone number generation. You are required to prompt a user for three employee names which will randomly assign the employee to either the Vodacom, MTN or Cell C network. The employees also require a randomly generated phone number. The start of each phone number will begin with the following, depending on the network provider: NETWORK PROVIDER START Vodacom 072 MTN 083 Cell C 084 The remaining numbers of the phone number must be randomly generated.
“Gola Ganda” shop, Gola Gandas of all shapes and sizes. Gola gandas of three sizes: Small, Medium and Large.
A customer can add as many toppings on it as they want, the toppings could be more “Sauce”, Condensed Milk, Nutella, etc . Every topping has a different cost, and the cost of each topping will be added on top of the cost of the size of gola ganda.
if a small gola ganda cost, 50 rupees, and a topping of condensed milk cost 10 rupees, and a topping of Nutella cost 20 rupees, and if a customer has ordered a small gola ganda with condensed milk and Nutella then the total cost will be 80 rupees (50 for small gola ganda, 10 for condensed milk, and 20 for Nutella).
Your job is to design a system that can calculate the final cost of the gola ganda.
task is the following:
• Identify the design pattern that can be used over here
• Justify your choice
• Make a class diagram (using UML Notation)
• Implement the classes in JAVA
• Test your implementation