Question

Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a...

Lab Assignment :

In this lab, you are going to implement QueueADT interface that defines a queue.
Then you are going to use the queue to store animals.

1. Write a LinkedQueue class that implements the QueueADT.java interface using links.

2. Textbook implementation uses a count variable to keep track of the elements in the queue. Don't use variable count in your implementation (points will be deducted if you use instance variable count). You may use a local integer variable to count number of nodes.

3. Use the SinglyLinkedNode class to implement the queue with links.

4 Methods dequeue and first in your LinkedQueue class must throw an EmptyQueueException when queue is empty. You must write the EmptyQueueException class.

5.Use an application to create a queue of animals. Create mammal and reptile objects, store them in the queue, remove the animals, request first animal and display the queue. You can use the provided AnimalGUI application or you can create your own.

Provided Files:

QueueADT

SinglyLinkedNode

AnimalGUI

Animal, Reptile, Mammal classes

QueueADT:

package collections;
import exceptions.*;

public interface QueueADT<T>{

public void enqueue (T element);


public T dequeue()throws EmptyQueueException ;


public T first()throws EmptyQueueException ;

public boolean isEmpty();


public int size();


public String toString();
}

SinglyLinkedNode:

package collections;
public class SinglyLinkedNode<T> {

/** element stored at this node */
private T element = null;
/** Link to the next node in list */
private SinglyLinkedNode<T> next;

/**
* Creates an empty node
*/
public SinglyLinkedNode() {
next = null;
element = null;
}

/**
* Creates a node storing the specified element
* @param element element to be stored
*/
public SinglyLinkedNode(T element) {
this.element = element;
next = null;
}

/**
* Creates a node storing the specified element and the specified node
* @param element Item to be stored
* @param next Reference to the next node in the list
*/
public SinglyLinkedNode(T element, SinglyLinkedNode<T> next) {
this.element = element;
this.next = next;
}

/**
* Returns the element stored at this node
* @return T element stored element at this node
*/
public T getElement() {
return element;
}

/**
* Set the reference to the stored element
* @param element The item to be stored at this node
*/
public void setElement(T elem) {
element = elem;
}

/**
* Returns the next node
* @return SinglyLinkedNode<T> reference to next node
*/
public SinglyLinkedNode<T> getNext() {
return next;
}

/**
* Sets the reference to the next node in the list
* @param next The next node
*/
public void setNext(SinglyLinkedNode<T> node) {
next = node;
}
}

AnimalGUI:

package gui;

import animals.*;
import collections.*;
import exceptions.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class AnimalGUIStart extends JFrame implements ActionListener {


//DECLARE LINKEDQUEUE OBJECT
/**
* GUI component for getting the name
*/
private GetInputPanel namePanel;
/**
* GUI component for getting the weight
*/
private GetInputPanel weightPanel;
/**
* GUI component for getting the age
*/
private GetComboPanel agePanel;
/**
* GUI component for getting the number of legs
*/
private GetComboPanel lengthPanel;
/**
* GUI component for getting the color
*/
private GetInputPanel colorPanel;
/**
* Button for adding a reptile to the collection
*/
private JButton addReptileButton;
/**
* Button for adding a reptile to the collection
*/
private JButton addMammalButton;
/**
* Button for viewing the next animal in the queue
*/
private JButton nextAnimalButton;
/**
* Button for displaying animals in the collection
*/
private JButton displayAnimalsButton;
/**
* A temporary GUI component for validating data
*/
private JTextArea verifyArea ;
/**
* Button for removing an animal from the collection
*/
private JButton removeAnimalButton;

/**
* Creates a new instance of AddAnimalFrame which is contains panels and other
* GUI components
*/
public AnimalGUIStart() {
super("Queue of Animals");
createGUI();
}

/**
* main() instantiates an object
*
* @param argv
*/
static public void main(String[] argv) {
AnimalGUIStart animalFrame = new AnimalGUIStart();
animalFrame.setSize(450, 550);
animalFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

/**
* A method to create GUI components
*/
private void createGUI() {
Container c = this.getContentPane();
c.setLayout(new BorderLayout(5, 5));

JPanel inputPanel = new JPanel(); //contains GUI to input animals info
inputPanel.setLayout(new GridLayout(5, 1));
namePanel = new GetInputPanel(20, " Animal's Name: ");
inputPanel.add(namePanel);
weightPanel = new GetInputPanel(6, " Animal's Weight (lb): ");
inputPanel.add(weightPanel);
agePanel = new GetComboPanel(" Animal's Age (years):", 125);
inputPanel.add(agePanel);
lengthPanel = new GetComboPanel("Reptile's Length (cm)", 1000);
inputPanel.add(lengthPanel);
colorPanel = new GetInputPanel(20, "Mammal's skin/fur color");
inputPanel.add(colorPanel);

JPanel buttonPanel = new JPanel(); //contains buttons
buttonPanel.setLayout(new GridLayout(1, 5, 5, 5));
addReptileButton = new JButton("Add Reptile");
addMammalButton = new JButton("Add Mammal");
nextAnimalButton = new JButton("Next Animal");
displayAnimalsButton = new JButton("Display Animals");
removeAnimalButton = new JButton("Remove Animal");
addReptileButton.setToolTipText("Press to add Reptile");
addMammalButton.setToolTipText("Press to add Mammal");
buttonPanel.add(addReptileButton);
buttonPanel.add(addMammalButton);
buttonPanel.add(removeAnimalButton);
buttonPanel.add(nextAnimalButton);
buttonPanel.add(displayAnimalsButton);

c.add(inputPanel, BorderLayout.NORTH);
c.add(buttonPanel, BorderLayout.CENTER);
verifyArea = new JTextArea(18, 25);
c.add(verifyArea, BorderLayout.SOUTH);
JScrollPane scrollPane = new JScrollPane(verifyArea);
c.add(scrollPane, BorderLayout.SOUTH);
addReptileButton.addActionListener(this);
addMammalButton.addActionListener(this);
displayAnimalsButton.addActionListener(this);
nextAnimalButton.addActionListener(this);
removeAnimalButton.addActionListener(this);

setVisible(true);
pack();
}

/**
* Responds to the "Display" and "Add" buttons
*
* @param ev The button press event
*/
@Override
public void actionPerformed(ActionEvent ev) {
  
Object object = ev.getSource();
if (object == addReptileButton) {
//create a Mammal
//store mammal in the queue
//catch exceptions
  
} else if (object == addMammalButton) {
//create a Mammal
//store mammal in the queue
//catch exceptions
} else if (object == removeAnimalButton) {
//remove animal
//catch EmptyQueue exception
} else if (object == nextAnimalButton) {
//get the first animal
//catch EmptyQueue exception
} else {

//display animals in the queue
  
}
}

/**
* A panel prompting for String input. It contains a label and a text field.
*/
class GetInputPanel extends JPanel {

private final JTextField inputField; //used for the user input

/**
* Constructor sets up a label and the text field
*
* @param size the size of the input text field
* @param prompt the message specifying expected input
*/
public GetInputPanel(int size, String prompt) {
inputField = new JTextField(size);
JLabel label = new JLabel(prompt);
add(label);
add(inputField);
}

/**
* Gets the text from the text field
*
* @return Returns the text from the text field
*/
public String getText() {
return inputField.getText();
}

/**
* Converts the text field value into a number and displays an error message
* when inputed data contains non digit characters
*
* @return the integer represented by the user input
*/
public double getValue() {
double value = 0.0;
try {
value = Double.parseDouble(inputField.getText());
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "Invalid characters in number",
"Input Error", JOptionPane.ERROR_MESSAGE);
}
return value;
}
}

/**
* This panel represents a panel with a label and a combo box.
*/
class GetComboPanel extends JPanel {

JLabel label; //explains the purpose of the combo box
JComboBox ageCombo; //used for the user input

/**
* Constructor sets up a panel with a label and a combo box.
*
* @param message the text indicating the purpose of the combo box
* @param numChoices the range of choices displayed in the combo box
*/
public GetComboPanel(String message, int numChoices) {
label = new JLabel(message);
String[] age = new String[numChoices];

for (int i = 0; i < age.length; i++) {
age[i] = i + 1 + "";
}
ageCombo = new JComboBox(age);

add(label);
add(ageCombo);
}

/**
* Gets the value from the combo box
*
* @return value selected from the combo box
*/
public int getValue() {
int a;
a = Integer.parseInt((String) ageCombo.getSelectedItem());
return a;
}
}
}

Animal, Reptile, Mammal classes:

import exceptions.*;
import javax.swing.JTextArea;
public class Animal {
/** create Name of the Animal*/
protected String name;
/** create weight of the Animal*/
protected double weight;
/** create age of the Animal*/
protected int age;
/**
* Creats a new instance variable
* @param name Name of the animal
* @param weight Weight of the animal
* @param age Age of the animal
* @throws InvalidWeightException
* @throws InvalidNameException
*/

public Animal(String name, double weight, int age)
throws InvalidWeightException, InvalidNameException {
if (name.length() < 2) {
throw new InvalidNameException("The name must be at least two character");
}
this.name = name;
if (weight <= 0) {
throw new InvalidWeightException("The wight must be greater than zero");
}
this.weight=weight;
this.age = age;
}
/**
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
* gets the name of the animal
* @return the string contains name
*/
public String getName() {
return name;
}
/**
* @param weight
*/
public void setWeight(double weight) {
this.weight = weight;
}
/**
* gets the weight of the animal
* @return the string contains weight
*/
public double getWeight() {
return weight;
}
/**
* @param age
*/
public void setAge(int age) {
this.age = age;
}
/**
* gets the age of the animal
* @return the string contains age
*/
public int getAge() {
return age;
}
/**
* display the information about the animal in the textArea
* @param output a text area for display
*/
public void display(JTextArea output) {
output.append("name" + name + "weight" + weight + "age" + age);
}
/**
* @return a string containing contents of the object's fields
*/
@Override
public String toString() {
return ("\n Animal Name: " + name + "\t weight:" + weight
+ "\t age:" + age);
}
}

import exceptions.InvalidNameException;
import exceptions.InvalidWeightException;
import javax.swing.JTextArea;
public class Mammal extends Animal {

private String hairColor;

/**
*
* @param name
* @param weight
* @param age
* @param hairColor
* @throws InvalidWeightException
* @throws InvalidNameException
*/
public Mammal(String name, double weight, int age, String hairColor)
throws InvalidWeightException, InvalidNameException {
super(name, weight, age);
this.hairColor = hairColor;
}

/**
* @param hairColor
*/
public void setColor(String hairColor) {
this.hairColor = hairColor;
}

/**
* gets the color of the mammal
*
* @return the color of the mammal
*/
public String getColor() {
return hairColor;
}

/**
* Displays a Mammal in the textArea
*
* @param output a text area to display an information about the animal
*/
@Override
public void display(JTextArea output) {
super.display(output);
output.append("\t hair/fur color: " + hairColor);
}

/**
* Returns a string representation of the Mammal object
*
* @return a string containing contents of the object's fields
*/
@Override
public String toString() {
return (super.toString() + "\t hair/fur color: " + hairColor);
}
}

import exceptions.InvalidNameException;
import exceptions.InvalidWeightException;
import javax.swing.JTextArea;
public class reptile extends Animal {

private int length;

/**
*
* @param name
* @param weight
* @param age
* @param length
* @throws InvalidWeightException
* @throws InvalidNameException
*/
public reptile(String name, Double weight, int age, int length)
throws InvalidWeightException, InvalidNameException {
super(name, weight, age);
this.length = length;
}
/**
*
* @param length
*/
public void setLength(int length) {
this.length = length;
}
/**
*
* @return the length of reptile
*/
public int getLength() {
return this.length;
}
/**
*
* @param output a text area to display an information about the animal
*/
@Override
public void display(JTextArea output) {
super.display(output);
output.append("length" + length);
}
/**
*
* @return a string representation of the reptile object
*/
@Override
public String toString() {
return (super.toString() + "length" + this.length);
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
Note: Due to the size limit, I’m attaching only LinkedQueue and AnimalGUIStart.java which are the only files with major modifications. I have adjusted display(JTextArea) methods of Animal, Mammal and reptile classes to display text more clearly (just added comma and a space between each fields)
EDIT: I’m getting character limit exceeded error, so I’m pasting the text as plain text which will cause loss of formatting and indentations. Sorry for that. But the code will work with no issues.


// LinkedQueue.java


package collections;

import exceptions.EmptyQueueException;
import animals.Animal;

public class LinkedQueue implements QueueADT<Animal> {
   // node pointing to the first animal
   private SinglyLinkedNode<Animal> front;

   @Override
   public void enqueue(Animal element) {
       // adding as front if front is null
       if (front == null) {
           front = new SinglyLinkedNode<Animal>(element);
       } else {
           // finding last node
           SinglyLinkedNode<Animal> temp = front;
           while (temp.getNext() != null) {
               temp = temp.getNext();
           }
           // adding as the next of current last node
           temp.setNext(new SinglyLinkedNode<Animal>(element));
       }

   }

   @Override
   public Animal dequeue() throws EmptyQueueException {
       // throwing exception if empty
       if (front == null) {
           throw new EmptyQueueException("The Queue is empty!");
       }
       // removing first animal and returning it
       Animal animal = front.getElement();
       front = front.getNext();
       return animal;
   }

   @Override
   public Animal first() throws EmptyQueueException {
       // throwing exception if empty
       if (front == null) {
           throw new EmptyQueueException("The Queue is empty!");
       }
       // returning first animal without removing it
       Animal animal = front.getElement();
       return animal;
   }

   @Override
   public boolean isEmpty() {
       return front == null;
   }

   @Override
   public int size() {
       int size = 0;
       // looping and counting the number of animals in the queue
       SinglyLinkedNode<Animal> temp = front;
       while (temp != null) {
           size++;
           temp = temp.getNext();
       }
       return size;
   }

   @Override
   public String toString() {
       // returns a String containing complete animals in the queue, for
       // testing purposes
       String data = "";
       SinglyLinkedNode<Animal> temp = front;
       while (temp != null) {
           data += temp.getElement();
           temp = temp.getNext();
           if (temp != null) {
               data += "\n";
           }
       }
       return data;
   }
}

//updated AnimalGUIStart.java


package gui;

import animals.*;
import collections.*;
import exceptions.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class AnimalGUIStart extends JFrame implements ActionListener {

   // DECLARE LINKEDQUEUE OBJECT
   private LinkedQueue queue;
   /**
   * GUI component for getting the name
   */
   private GetInputPanel namePanel;
   /**
   * GUI component for getting the weight
   */
   private GetInputPanel weightPanel;
   /**
   * GUI component for getting the age
   */
   private GetComboPanel agePanel;
   /**
   * GUI component for getting the number of legs
   */
   private GetComboPanel lengthPanel;
   /**
   * GUI component for getting the color
   */
   private GetInputPanel colorPanel;
   /**
   * Button for adding a reptile to the collection
   */
   private JButton addReptileButton;
   /**
   * Button for adding a reptile to the collection
   */
   private JButton addMammalButton;
   /**
   * Button for viewing the next animal in the queue
   */
   private JButton nextAnimalButton;
   /**
   * Button for displaying animals in the collection
   */
   private JButton displayAnimalsButton;
   /**
   * A temporary GUI component for validating data
   */
   private JTextArea verifyArea;
   /**
   * Button for removing an animal from the collection
   */
   private JButton removeAnimalButton;

   /**
   * Creates a new instance of AddAnimalFrame which is contains panels and
   * other GUI components
   */
   public AnimalGUIStart() {
       super("Queue of Animals");
       createGUI();
   }

   /**
   * main() instantiates an object
   *
   * @param argv
   */
   static public void main(String[] argv) {
       AnimalGUIStart animalFrame = new AnimalGUIStart();
       animalFrame.setSize(450, 550);
       animalFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }

   /**
   * A method to create GUI components
   */
   private void createGUI() {
       Container c = this.getContentPane();
       c.setLayout(new BorderLayout(5, 5));

       JPanel inputPanel = new JPanel(); // contains GUI to input animals info
       inputPanel.setLayout(new GridLayout(5, 1));
       namePanel = new GetInputPanel(20, " Animal's Name: ");
       inputPanel.add(namePanel);
       weightPanel = new GetInputPanel(6, " Animal's Weight (lb): ");
       inputPanel.add(weightPanel);
       agePanel = new GetComboPanel(" Animal's Age (years):", 125);
       inputPanel.add(agePanel);
       lengthPanel = new GetComboPanel("Reptile's Length (cm)", 1000);
       inputPanel.add(lengthPanel);
       colorPanel = new GetInputPanel(20, "Mammal's skin/fur color");
       inputPanel.add(colorPanel);

       JPanel buttonPanel = new JPanel(); // contains buttons
       buttonPanel.setLayout(new GridLayout(1, 5, 5, 5));
       addReptileButton = new JButton("Add Reptile");
       addMammalButton = new JButton("Add Mammal");
       nextAnimalButton = new JButton("Next Animal");
       displayAnimalsButton = new JButton("Display Animals");
       removeAnimalButton = new JButton("Remove Animal");
       addReptileButton.setToolTipText("Press to add Reptile");
       addMammalButton.setToolTipText("Press to add Mammal");
       buttonPanel.add(addReptileButton);
       buttonPanel.add(addMammalButton);
       buttonPanel.add(removeAnimalButton);
       buttonPanel.add(nextAnimalButton);
       buttonPanel.add(displayAnimalsButton);

       c.add(inputPanel, BorderLayout.NORTH);
       c.add(buttonPanel, BorderLayout.CENTER);
       verifyArea = new JTextArea(18, 25);
       c.add(verifyArea, BorderLayout.SOUTH);
       JScrollPane scrollPane = new JScrollPane(verifyArea);
       c.add(scrollPane, BorderLayout.SOUTH);
       addReptileButton.addActionListener(this);
       addMammalButton.addActionListener(this);
       displayAnimalsButton.addActionListener(this);
       nextAnimalButton.addActionListener(this);
       removeAnimalButton.addActionListener(this);
       // initializing linked queue
       queue = new LinkedQueue();

       setVisible(true);
       pack();
   }

   /**
   * Responds to the "Display" and "Add" buttons
   *
   * @param ev
   * The button press event
   */
   @Override
   public void actionPerformed(ActionEvent ev) {

       Object object = ev.getSource();
       if (object == addReptileButton) {
           // create a reptile
           try {
               reptile r = new reptile(namePanel.getText(),
                       weightPanel.getValue(), agePanel.getValue(),
                       lengthPanel.getValue());
               queue.enqueue(r);
               verifyArea.setText(r+" is enqueued");
           } catch (Exception e) {
               verifyArea.setText(e.getMessage());
           }

       } else if (object == addMammalButton) {
           // create a Mammal
           try {
               Mammal m = new Mammal(namePanel.getText(),
                       weightPanel.getValue(), agePanel.getValue(),
                       colorPanel.getText());
               queue.enqueue(m);
               verifyArea.setText(m+" is enqueued");
           } catch (Exception e) {
               verifyArea.setText(e.getMessage());
           }
       } else if (object == removeAnimalButton) {
           // remove animal
           try {
               Animal animal=queue.dequeue();
               verifyArea.setText(animal+" is dequeued");
           } catch (EmptyQueueException e) {
               verifyArea.setText(e.getMessage());
           }
           // catch EmptyQueue exception
       } else if (object == nextAnimalButton) {
           // get the first animal
           try {
               Animal animal=queue.first();
               verifyArea.setText(animal+" is the next animal");  
           } catch (EmptyQueueException e) {
               verifyArea.setText(e.getMessage());
           }
           // catch EmptyQueue exception
       } else {
           verifyArea.setText("");
           int count=queue.size();
           for(int i=0;i<count;i++){
               try {
                   Animal animal=queue.dequeue();
                   animal.display(verifyArea);
                   verifyArea.append("\n");
                   queue.enqueue(animal);
               } catch (EmptyQueueException e) {
               }
              
           }
           // display animals in the queue

       }
   }

   /**
   * A panel prompting for String input. It contains a label and a text field.
   */
   class GetInputPanel extends JPanel {

       private final JTextField inputField; // used for the user input

       /**
       * Constructor sets up a label and the text field
       *
       * @param size
       * the size of the input text field
       * @param prompt
       * the message specifying expected input
       */
       public GetInputPanel(int size, String prompt) {
           inputField = new JTextField(size);
           JLabel label = new JLabel(prompt);
           add(label);
           add(inputField);
       }

       /**
       * Gets the text from the text field
       *
       * @return Returns the text from the text field
       */
       public String getText() {
           return inputField.getText();
       }

       /**
       * Converts the text field value into a number and displays an error
       * message when inputed data contains non digit characters
       *
       * @return the integer represented by the user input
       */
       public double getValue() {
           double value = 0.0;
           try {
               value = Double.parseDouble(inputField.getText());
           } catch (NumberFormatException ex) {
               JOptionPane.showMessageDialog(null,
                       "Invalid characters in number", "Input Error",
                       JOptionPane.ERROR_MESSAGE);
           }
           return value;
       }
   }

   /**
   * This panel represents a panel with a label and a combo box.
   */
   class GetComboPanel extends JPanel {

       JLabel label; // explains the purpose of the combo box
       JComboBox ageCombo; // used for the user input

       /**
       * Constructor sets up a panel with a label and a combo box.
       *
       * @param message
       * the text indicating the purpose of the combo box
       * @param numChoices
       * the range of choices displayed in the combo box
       */
       public GetComboPanel(String message, int numChoices) {
           label = new JLabel(message);
           String[] age = new String[numChoices];

           for (int i = 0; i < age.length; i++) {
               age[i] = i + 1 + "";
           }
           ageCombo = new JComboBox(age);

           add(label);
           add(ageCombo);
       }

       /**
       * Gets the value from the combo box
       *
       * @return value selected from the combo box
       */
       public int getValue() {
           int a;
           a = Integer.parseInt((String) ageCombo.getSelectedItem());
           return a;
       }
   }
}

/*OUTPUT*/


Add a comment
Know the answer?
Add Answer to:
Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given a singly-linked list interface and linked list node class, implement the singly-linked list which has...

    Given a singly-linked list interface and linked list node class, implement the singly-linked list which has the following methods in Java: 1. Implement 3 add() methods. One will add to the front (must be O(1)), one will add to the back (must be O(1)), and one will add anywhere in the list according to given index (must be O(1) for index 0 and O(n) for all other indices). They are: void addAtIndex(int index, T data), void addToFront(T data), void addToBack(T...

  • Implement the following in java. 1. An insertAtBeginning(Node newNode) function, that inserts a node at the...

    Implement the following in java. 1. An insertAtBeginning(Node newNode) function, that inserts a node at the beginning(root) of the linked list. 2. A removeFromBeginning() function, that removes the node from the beginning of the linked list and assigns the next element as the new beginning(root). 3. A traverse function, that iterates the list and prints the elements in the linked list. For the insertAtBeginning(Node newNode) function: 1. Check if the root is null. If it is, just assign the new...

  • In addition to the base files, three additional files are attached: EmptyCollectionException.java, LinearNode.java, and StackADT.java. These...

    In addition to the base files, three additional files are attached: EmptyCollectionException.java, LinearNode.java, and StackADT.java. These files will need to be added to your Java project. They provide data structure functionality that you will build over. It is suggested that you test if these files have been properly added to your project by confirming that Base_A05Q1.java compiles correctly. Complete the implementation of the ArrayStack class. Specifically, complete the implementations of the isEmpty, size, and toString methods. See Base_A05Q1.java for a...

  • There is a data structure called a drop-out stack that behaves like a stack in every...

    There is a data structure called a drop-out stack that behaves like a stack in every respect except that if the stack size is n, then when the n+1element is pushed, the bottom element is lost. Implement a drop-out stack using links, by modifying the LinkedStack code. (size, n, is provided by the constructor. Request: Please create a separate driver class, in a different file, that tests on different types of entries and show result of the tests done on...

  • In this practice program you are going to practice creating graphical user interface controls and placing...

    In this practice program you are going to practice creating graphical user interface controls and placing them on a form. You are given a working NetBeans project shell to start that works with a given Invoice object that keeps track of a product name, quantity of the product to be ordered and the cost of each item. You will then create the necessary controls to extract the user input and display the results of the invoice. If you have any...

  • Java - I need help creating a method that removes a node at the specific index...

    Java - I need help creating a method that removes a node at the specific index position. The * first node is index 0. public boolean delAt(int index) { src code 2 different classes ******************************************** public class Node { private String data; private Node next; public Node(String data, Node next) { this.data = data; this.next = next; } public Node() { } public String getData() { return data; } public void setData(String data) { this.data = data; } public void...

  • In Java Language. Modify the LinkedPostionalList class to support a method swap(p,q) that causes the underlying...

    In Java Language. Modify the LinkedPostionalList class to support a method swap(p,q) that causes the underlying nodes referenced by positions p and q to be exchanged for each other. Relink the existing nodes, do not create any new nodes. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- package lists; import java.util.Iterator; import java.util.NoSuchElementException; public class LinkedPositionalList implements PositionalList { //---------------- nested Node class ---------------- /** * Node of a doubly linked list, which stores a reference to its * element and to both the previous and next...

  • Step 1 Develop the following interface: Interface Name: Queue Interface<T> Access Modifier: public Methods Name: isEmpty...

    Step 1 Develop the following interface: Interface Name: Queue Interface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Name: enqueue Access modifier: public Parameters: element (data type T, parameterized type) Return type: void Step 2 Develop the following class: Class Name: Queue Node<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier:...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • In Java You may add any classes or methods to the following as you see fit in order to complete t...

    In Java You may add any classes or methods to the following as you see fit in order to complete the given tasks. Modify the LinkedList (or DoubleLinkedList) class and add a method append. append should take another LinkedList (DoubleLinkedList) as input and append that list to the end of this list. The append method should work by doing a few "arrow" adjustments on the boxes and it should not loop through the input list to add elements one at...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT