Questions
Add The following methods to the LinkedQueue class and create a test driver for each to...

Add The following methods to the LinkedQueue class and create a test driver for each to show they work correctly. In order to practice your linked list coding skills, code each of these methods by accessing the internal variables of the LinkedQueue, not by calling the previously defined public methods of the class. a. String toString () creates and returns a string that correctly represents the current queue. Such a method could prove useful for testing and debugging the class and for testing and debugging applications tha

t use the class. Assue each queued element already provides its own reasonable toString method. b. void remove (int count) removes the front count elements from the queue; throws QueueUnderflowException if less than count elements are in the queue. c. boolean swapStart () returns false if less than two elements are in the queue, otherwise reverse the order of the front two elements in the queue and returns true. d. boolean swapEnds() returns false if there are less than two elements in the queue, otherwise swaps the first and last elements of the queue and returns true.

LinkedQueue.java:

package ch04.queues;

import support.LLNode;

public class LinkedQueue<T> implements QueueInterface<T> {

    protected LLNode<T> front;

    protected LLNode<T> rear;

    protected int numElements = 0;

    public LinkedQueue(){

        front = null; rear = null;

    }

    public void enqueue(T element){

        LLNode<T> newNode = new LLNode<T>(element);

        if (rear == null)

            front = newNode;

        else

            rear.setLink(newNode);

        rear = newNode;

        numElements++;

    }

    public T dequeue(){

        if (isEmpty())

            throw new QueueUnderflowException("Dequeue attempted on empty queue.");

        else{

            T element;

            element = front.getInfo();

            front = front.getLink();

            if (front == null)

                rear = null;

            numElements--;

            return element;

        }

    }

}

LLNode.java:

//----------------------------------------------------------------------------

// LLNode.java by Dale/Joyce/Weems Chapter 2

//

// Implements <T> nodes for a Linked List.

//----------------------------------------------------------------------------

package support;

public class LLNode<T>{

    private LLNode<T> link;

    private T info;

    

    public LLNode(T info)

    {

        this.info = info;

        link = null;

    }

    

    public void setInfo(T info){

        // Sets info of this LLNode.

        this.info = info;

    }

    

    public T getInfo()

    // Returns info of this LLONode.

    {

        return info;

    }

    

    public void setLink(LLNode<T> link)

    // Sets link of this LLNode.

    {

        this.link = link;

    }

    public LLNode<T> getLink()

    // Returns link of this LLNode.

    {

        return link;

    }

}

QueueInterface.java

package ch04.queues;

public interface QueueInterface<T> {

    

    void enqueue(T element) throws QueueOverflowException1;

    T dequeue() throws QueueUnderflowException;

    boolean isFull();

    boolean isEmpty();

    int size();

}

In: Computer Science

use c++ Parking charge application: A parking garage charges a $20.00 minimum fee to park for...

use c++

Parking charge application: A parking garage charges a $20.00 minimum fee to park for up to 3 hours. The garage charges an additional $5.00 per hour for hour or part thereof in excess of 3 hours. The maximum charge for any given 24-hour period is $50.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charge for each of 3 customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should save the result in a array of Customer. The class customer is the following:

class customer{ string plate; float hour; float fee; }

Your program should use the function calculateCharges to determine the fee for each customer. You should print the result for the 3 customers in the following format:

Plate Hours Charge

132AAC 1.5 20.00

236URT 4.0 25.00

390ROP 24.0 50.00

TOTAL 29.5 95.00

In doing this question make sure to keep the array of customer as global variable.

In: Computer Science

You must implement the delete method. Below are the requirements: • The delete method takes a...

You must implement the delete method. Below are the requirements:

• The delete method takes a Price as an argument and removes the Price from the queue if it is present. (If the Price was not present, the method does nothing).

• The method returns true if the Price was deleted and false otherwise.

• The method must run in logarithmic time. This is a key requirement. Solutions that are linear or worse will not receive credit. (You may assume that the running time for TreeMap’s operations are similar to the LLRB class in the book. You can also read the API for TreeMap to see what the running times for the various methods are.)

• You may not modify the function headers of any of the functions already present.

• The only field you may add to the PriceQueue class is a single TreeMap. (See Java’s API for the TreeMap class. It is basically the same as the book’s RedBlackBST class)

• You may not change or remove the package declaration at the top of the files.

• The rest of the queue should continue to behave as expected. In particular, the remaining Prices should still come out of the queue in FIFO order.

• The enqueue and dequeue methods should also run in logarithmic time while the size, peek, and isEmpty methods continue to run in constant time. Note, the enqueue method given to you runs in linear time because it scans the list to see if the price being added is already in the queue. You will need to replace this with a different way of checking that doesn’t take linear time. (Hint: Use the map!) • You will need to make changes to the Price class as well, but you can only add new functionality. You may not make any changes to the functions that are already there and they must continue to behave as before.

//// PRICE JAVA /////

public class Price {

private int dollars;

private int cents;

public Price(int dollars, int cents) {

if (dollars < 0 || cents < 0 || cents > 99)

throw new IllegalArgumentException();

this.dollars = dollars;

this.cents = cents;

}

public String toString() {

String answer = "$" + dollars + ".";

if (cents < 10)

answer = answer + "0" + cents;

else

answer = answer + cents;

return answer;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Price other = (Price) obj;

if (cents != other.cents)

return false;

if (dollars != other.dollars)

return false;

return true;

}

}

/////// PRICE QUEUE //////

import java.util.Iterator;
import java.util.NoSuchElementException;

public class PriceQueue implements Iterable<Price> {
private Node first; // beginning of queue
private Node last; // end of queue
private int n; // number of elements on queue
// TODO - Add a TreeMap that maps prices to the node before that price in the queue
// and maps the first price (nothing before it) to null
//
// NOTE: You will need to modify preexisting methods to maintain the invariant on the TreeMap

// helper linked list class
private static class Node {
private Price price;
private Node next;
}

/**
* Initializes an empty queue.
*/
public PriceQueue() {
first = null;
last = null;
n = 0;
}

/**
* Returns true if this queue is empty.
*
* @return {@code true} if this queue is empty; {@code false} otherwise
*/
public boolean isEmpty() {
return first == null;
}

/**
* Returns the number of Prices in this queue.
*
* @return the number of Prices in this queue
*/
public int size() {
return n;
}

/**
* Returns the Price least recently added to this queue.
*
* @return the Price least recently added to this queue
* @throws NoSuchElementException if this queue is empty
*/
public Price peek() {
if (isEmpty()) throw new NoSuchElementException("Queue underflow");
return first.price;
}

/**
* Adds the Price to this queue if it is not already present,
* otherwise it throws an IllegalArugmentException.
*
* @param price the Price to add
*
* @throws IllegalArgumentException if price is already in the queue.
*/
public void enqueue(Price price) {
   for(Price p : this)
       if (p.equals(price))
           throw new IllegalArgumentException();
Node oldlast = last;
last = new Node();
last.price = price;
last.next = null;
if (isEmpty()) first = last;
else oldlast.next = last;
n++;
}

/**
* Removes and returns the Price on this queue that was least recently added.
*
* @return the Price on this queue that was least recently added
* @throws NoSuchElementException if this queue is empty
*/
public Price dequeue() {
if (isEmpty()) throw new NoSuchElementException("Queue underflow");
Price price = first.price;
first = first.next;
n--;
if (isEmpty()) last = null; // to avoid loitering
return price;
}
  
  
/**
* Deletes a Price from the queue if it was present.
* @param price the Price to be deleted.
* @return {@code true} if the Price was deleted and {@code false} otherwise
*/
public boolean delete(Price price) {
   // TODO implelment me!!!
   // Make sure the running time is no worse than logrithmic!!!
   // You will want to use Java's TreeMap class to map Prices to the node
   // that precedes the Price in the queue
   throw new RuntimeException("Not Implemented!!!");
}

/**
* Returns a string representation of this queue.
*
* @return the sequence of Prices in FIFO order, separated by spaces
*/
public String toString() {
StringBuilder s = new StringBuilder();
for (Price price : this) {
s.append(price);
s.append(' ');
}
return s.toString();
}

/**
* Returns an iterator that iterates over the Prices in this queue in FIFO order.
*
* @return an iterator that iterates over the Prices in this queue in FIFO order
*/
public Iterator<Price> iterator() {
return new PriceListIterator(first);
}

// an iterator, doesn't implement remove() since it's optional
private class PriceListIterator implements Iterator<Price> {
private Node current;

public PriceListIterator(Node first) {
current = first;
}

public boolean hasNext() { return current != null; }
public void remove() { throw new UnsupportedOperationException(); }

public Price next() {
if (!hasNext()) throw new NoSuchElementException();
Price price = current.price;
current = current.next;
return price;
}
}
}

In: Computer Science

Define a class Product to hold the name and price of items in a grocery store....

Define a class Product to hold the name and price of items in a grocery store. Encapsulate the fields and provide getters and setters. Create an application for a grocery store to calculate the total bill for each customer. Such program will read a list of products purchased and the quantity of each item. Each line in the bill consists of: ProductName ProductPrice Quantity/Weight

The list of items will be terminated by the “end” keyword. The data will look like this: Juice 10 7 Apples 3 3.5 Cereal 5 3 Gum 1 15 Pears 3.5 5 ends The program should read the data from the console, calculate the total price of the items purchased and print it out. For each line create an object of class Product and initialize its fields in the constructor. Then calculate the price for given quantity using the getter of the object.

In: Computer Science

use c++ Every programmer must grapple with certain classic problems, and the Towers problem is one...

use c++

Every programmer must grapple with certain classic problems,
and the Towers problem is one of the most famous of these. Legend has it that
in a temple in the Far East, priests are attempting to move a stack of disks from one peg to another.
The initial stack had 64 disks threaded onto one peg and arranged from bottom to top by decreasing
size. The priests are attempting to move the stack from this peg to a second peg under the constraints
that exactly one disk is moved at a time, and at no time may a larger disk be placed above a smaller
disk. A third peg is available for temporarily holding the disks. Supposedly the world will end when
the priests complete their task, so there is little incentive for us to facilitate their efforts.
Let’s assume that the priests are attempting to move the disks from peg 1 to peg 3. We wish to
develop an algorithm that will print the precise sequence of disk-to-disk peg transfers.
If we were to approach this problem with conventional methods, we’d rapidly find ourselves
hopelessly knotted up in managing the disks. Instead, if we attack the problem with recursion in
mind, it immediately becomes tractable. Moving n disks can be viewed in terms of moving only
n – 1 disks (and hence the recursion) as follows:
a) Move n – 1 disks from peg 1 to peg 2, using peg 3 as a temporary holding area.
b) Move the last disk (the largest) from peg 1 to peg 3.
c) Move the n – 1 disks from peg 2 to peg 3, using peg 1 as a temporary holding area.
The process ends when the last task involves moving n = 1 disk, i.e., the base case. This is
accomplished by trivially moving the disk without the need for a temporary holding area.
Write a program to solve the Towers of Hanoi problem. Use a recursive function with four
parameters:
a) The number of disks to be moved
b) The peg on which these disks are initially threaded
c) The peg to which this stack of disks is to be moved
d) The peg to be used as a temporary holding area
Your program should print the precise instructions it will take to move the disks from the
starting peg to the destination peg. For example, to move a stack of three disks from peg 1 to peg 3,
your program should print the following series of moves:
1 → 3 (This means move one disk from peg 1 to peg 3.)
1 → 2
3 → 2
1 → 3
2 → 1
2 → 3
1 → 3*/

In: Computer Science

Fundamentals of Big Data Analytics • Critical Success Factors for Big Data Analytics. • Enablers of...

Fundamentals of Big Data Analytics
• Critical Success Factors for Big Data Analytics.
• Enablers of Big Data Analytics
• Challenges of Big Data Analytics
• Business Problems Addressed by Big Data Analytics
Top 5 Investment Bank Achieves Single Source of the Truth
Questions for Discussion
4. How can Big Data benefit large-scale trading banks?
5. How did MarkLogic’s infrastructure help ease the leveraging of Big Data?
6. What were the challenges, the proposed solution, and the obtained results?

In: Computer Science

Binary Search Trees with Lazy Deletion Implement binary search tree class with lazy deletion that has...

Binary Search Trees with Lazy Deletion

Implement binary search tree class with lazy deletion that has TreeNode as nested class in Java.

Design the class, TreeNode to have following class variables:

int key; // All Keys are in the range 1 to 99

TreeNode leftChild;

TreeNode rightChild;

boolean deleted;

Your program method must have routines to do the following operations.

1. insert

//Should insert a new element to a leaf node. If new element is aduplicatethen do nothing. If the new element is previously deleted one, then do not add other copy just mark the previous deleted as valid now

2. delete

//Should not remove the element from the tree. It should just mark the element as deleted.

Lazy deletion, meaning you will not be deleting the node but only mark it for deletion. It is ok to display the deleted node put an * before it to indicate it is deleted.

3. findMin

//Should return the minimum element, butif it is marked deleted return appropriate minimum

4. findMax

//Should return the maximumelement, butif it is marked deleted return appropriate maximum

5. contains

//Should return true if a particular element is in the tree and is not marked as deleted

6. In order tree Traversal

//Should print the in order traversal of the tree. Indicating with * symbol for elements that are marked deleted

7. Height ( returns the height of the tree)

//Return the height of the tree, count all the elements even the ones that are marked as deleted

8. No Of nodes ( returns number of nodes + number of deleted nodes)

//Return and print size of the tree, count all the elements even the ones that are marked as deleted. And also return the number of deleted elements.

The Java program should prompt user with options to do one of the above routines.

In: Computer Science

A programmer that you work with, Peter, is a jerk. He is responsible for an array...

A programmer that you work with, Peter, is a jerk. He is responsible for an array that is a key part of an important program and he maintains a sum of the array value.He won't give you access to this array; however, your boss has told you that you need to get input from the user and then place it into the array.Each evening Peter will scan the code and remove any illegal references to his array.

Using pointers, access Peter's array without him knowing it and place three values that you got from the user ONLY AT POSITIONS 3, 6, and 9. Recalculate the sum value and update it.

STARTER CODE BELOW:

#include <stdio.h>

#include

<stdlib.h>

int main(){

int petersArray[10] = {100,200,300,400,500,600,700,800,900,1000}; i

int petersArraySum = 0;

printf("Peter's Array:\n");

for (int loop = 0; loop < 10; loop++) {

printf("%d ",petersArray[loop]);

petersArraySum += petersArray[loop];

}

printf("\n");

printf("Peter's Array Sum: %d\n\n",petersArraySum);

return 0;

In: Computer Science

IP adress is 195.20.1.0/24 Design the network as per the requirements below: -        The company is composed...

IP adress is 195.20.1.0/24
  1. Design the network as per the requirements below:

-        The company is composed of 3 Branches, namely: Head Office (HO), Northern Governorate Branch (NGB) and Southern Governorate Branch (SGB).

-        Each branch is represented by a router. Utilize 1841 routers.

-        These branches are separated by WAN links where the HO is connected to both branches.

-        HO has 2 LANs and NGB and SGB have 1 LAN each. Use 2960 switches.

-        Utilize any Class C address and assign the appropriate IP addresses for the interfaces and end devices.

-        Place 5 hosts in each LAN.

-        Label your network.

Rubrics:

3 points – correct LAN design

4 points – correct LAN addresses

3 points – correct serial link addresses

TOTAL= 10 points

  1. Configure the network by Static Routing.

3 points – correct Router LAN port configuration

2 points- correct Router WAN port configuration

3 points – correct end devices addresses

2 points – complete network convergence

TOTAL= 10 points

In: Computer Science

python: people = { "Molan": { "age": 46, "seIdentity": "Dan Jukes", "supowers": [ "Radiaon Immunity", "Turni...

python:

people = {

"Molan": {

"age": 46,

"seIdentity": "Dan Jukes",

"supowers": [

"Radiaon Immunity",

"Turni tiny",

"Radiati blast"

]

},

"Etlame": {

"age": 1800,

"seIdentity": "Unknown",

"supowers": [

"Immortality",

"Heat Immunity",

"Inferno",

"Teleportation",

"Interdi travel"

]

}

#output all people ages as set

# out old people age from dict with name

In: Computer Science

C++ Please create 4 different files with this respective names main.cpp , Pokemon.h , Pokemon.cpp Move.h...

C++

Please create 4 different files with this respective names

  • main.cpp , Pokemon.h , Pokemon.cpp Move.h

16.5 Homework 5

Introduction

Students will create a C++ program that simulates a Pokemon battle mainly with the usage of a while loop, classes, structs, functions, pass by reference and arrays. Students will be expected to create the player’s pokemon and enemy pokemon using object-oriented programming (OOP).

Scenario

You’ve been assigned the role of creating a Pokemon fight simulator between a player’s Pikachu and the enemy CPU’s Mewtwo.

You need to create a simple Pokemon battle simulation that will run until one of the pokemon’s health points (HP) reaches 0. In the simulation, the player’s Pikachu will battle the enemy Mewtwo. The Mewtwo will always be the first one to attack, then you’ll attack, and so on until the simulation ends (one of the players runs out of health points). Additionally, Mewtwo will only use one attack on the player, whereas the player's Pikachu has 3 attack options. They can either use “Thundershock”, “Quick Attack”, or “Electro Ball”. Once the battle is over, you will be greeted with the message “You win” or “You lose” depending on whether or not the player’s pokemon won the battle.

Instructions to complete the assignment

Your code must perform these major operations:

  • Utilize a while loop to continuously get each person’s turn (player and CPU)
  • Use OOP to create a Pokemon object, allowing 3 attacks which are to be made using functions
  • Use an array to hold the move structs in your Pokemon class
  • Using print statements that reflect the status of the battle

Move.h (Move Struct) Each move struct must have the following attributes:

  • Name (string)
  • Damage (int)

Pokemon.h and Pokemon.cpp (Pokemon Class) Each pokemon class must have the following (pritvate) attributes:

  • Name (string)
  • Health (int)
  • Moves (Array of 3 Moves)
  • isConfused (boolean)

And will have the following (public) member functions:

  • Class constructor. The class constructors takes in name as parameter (Mewtwo or Pikachu) and creates the pokemon object accordingly with the right values for health and available attacks (details in the list below). Note that Mewtwo only gets one attack, so 2 elements of the Moves array will remain empty.
  • Mutators (setHealth, setIsConfused, setMoves). In particular, setMoves set all moves at once and requires 6 parameters, a string and a point value for each move, in this order: string move1, int damage1, string move2, int damage2, string move3, int damage3
  • Accessors (getHealth, getIsConfused)
  • Void type function move(int index, Pokemon& target): this function uses as parameter the index of the attack to use (from 0 to 2) and a reference to the pokemon who is being attacked. The health of the target will be reduced according to the attack received. If Electro Ball is used, the target's health does not change but they get confused and skip the next turn.
  • Void type function displayMoves: This function presents the user with a list of available moves, in this format:
Thunderbolt, Electro Ball, or Quick Attack

Pokemon stats

  • Pikachu (274 HP)
    • Thunderbolt (-125 HP)
    • Electro Ball (Confuses a pokemon, target skips a turn)
    • Quick Attack (-90 HP)
  • Mewtwo (322 HP)
    • Psycho Cut (-90 HP)

main.cpp

In the main file, create two pokemon objects (a Mewtwo and a Pikachu) and a loop with the following sequence of actions:

  • Mewtwo attacks Pikachu
  • Pikachu displays moves
  • User selects move
  • Pikachu attacks Mewtwo

Please Test the files.......

Console Input/Output

• Sample input 1

Thunderbolt    
Electro Ball
Thunderbolt
Thunderbolt

Sample output 1

Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Thunderbolt
Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Electro Ball
It confused Mewtwo!
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Thunderbolt
Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Thunderbolt
You win

Sample input 2

Thunderbolt
Quick Attack
Electro Ball
Quick Attack

Sample output 2

Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Thunderbolt
Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Quick Attack
Mewtwo used Psycho Cut
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Electro Ball
It confused Mewtwo!
Thunderbolt, Electro Ball, or Quick Attack
Pikachu used Quick Attack
Mewtwo used Psycho Cut
You lose

In: Computer Science

Discuss the impact of computer science on various aspects of modern society, such as art, health...

Discuss the impact of computer science on various aspects of modern society, such as art, health services, learning, Security, Privacy etc...(paragraph)

In: Computer Science

You are to write a program using Java that will simulate a slot machine with four...

You are to write a program using Java that will simulate a slot machine with four wheels. It will determine the amount of money won for each spin. The four wheels spin and stop showing a value between 0 and 9 inclusive. It costs $2 to play.

•You win $500 (but not the $2 you bet) if you get 4 wheels the same.

•You win $10 (but not the $2 you bet) if you get exactly 3 of a kind.

•You win $5 (but not the $2 you bet) if you get two pairs.

•You win $2 if you get 2 wheels the same (That is, you break even).

•You win nothing and lose your $2 bet if you get no matches.

Your program must use 4 methods:

1.One to randomly generate the 4 wheel values.

2.One to output the result of the spin.

3.One to compute the win or loss and print the correct message

4.Finally, one to output new balance and a nice line break graphic as seen below.

Input and Output:Your program will randomly generate a starting balance between $100 and $200 inclusive. Your program will randomly generate four integers (1 for each wheel).Your program will output a description of the input combination and the amount you won or lost.Your program will output your new balance after each spin.

Please help

In: Computer Science

It is very important to see oppression as a structural issue without taking on individual guilt...

It is very important to see oppression as a structural issue without taking on individual guilt for historical injustices. Explain what this means and why it is important. Why does this matter? Be sure to include the concept of the "luxury of obliviousness" in your answer. (Can someone answer this as long as possible)

In: Computer Science

Software Engineering Process Models Question 4 (a) Give a description of the waterfall process model. In...

Software Engineering Process Models
Question 4
(a) Give a description of the waterfall process model. In your answer you should describe the main tasks that are conducted, and the order in which they are carried out. You may want to include a diagram to clarify your answer.
[7 marks]
(b) Describe one advantage and one disadvantage of adopting the waterfall process model in comparison to other process models.
[4 marks]
(c) Describe the key principles which underlie Agile software development.
[8 marks]
(d) Risk management is an important part of software project planning. Describe what is meant by a risk and give two examples of risks which could seriously affect a project.
[4 marks]

In: Computer Science