Question
please answer 1-5
Section 4. Write the following programs. (34 points) 1. (7 points) Define a class called MyLinkedQueue containing two data fi


Section 4. Write the following programs. (34 points) 1. (7 points) Define a class called MyLinkedQueue containing two data fi
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) MyLinkedQueue --- I have created the MyLInkedQueue class in eclipse please refer below

public class MyLinkedQueue {

private int head;
private int tail;

public MyLinkedQueue(int head, int tail) {
   super();
   this.head = head;
   this.tail = tail;
}

public int getHead() {
   return head;
}

public void setHead(int head) {
   this.head = head;
}

public int getTail() {
   return tail;
}

public void setTail(int tail) {
   this.tail = tail;
}
}

==================================================================

2)  

public class MyLinkedQueue {

private QueueNode head;
private QueueNode tail;

private class QueueNode { // inner class started
       private int data;
       private QueueNode next;
       private QueueNode previous;

       public QueueNode (int data) {
           this.data = data;
       }
   } // Inner class ended

public MyLinkedQueue(int head, int tail) {
   super();
   this.head = head;
   this.tail = tail;
}

public int getHead() {
   return head;
}

public void setHead(int head) {
   this.head = head;
}

public int getTail() {
   return tail;
}

public void setTail(int tail) {
   this.tail = tail;
}
}

==================================================

3)

public class MyLinkedQueue{

    public static void main(String args[])

    {

        MyLinkedQueue<String> queue = new MyLinkedQueue<String>();   // Creating an empty MyLinkedQueue

        queue.offer("The");   // Inserting using offer()

        queue.offer("Priority");

        queue.offer("Class");

System.out.println("MyLinkedQueue after Insertion: " + queue); // Displaying the final Queue

MyLinkedQueue<Integer> Q = new LinkedList<Integer>(); // create object of Queue

Q.add(423);   // Add numbers to end of Queue

        Q.add(3432);

System.out.println("Queue: " + Q);   // print queue

System.out.println("Queue's head: " + Q.poll());   // print head and deletes the head

System.out.println("Queue's head: " + Q.poll());    // print head and deleted the head

    }

}

Add a comment
Know the answer?
Add Answer to:
please answer 1-5 Section 4. Write the following programs. (34 points) 1. (7 points) Define 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
  • Need help with a few questions! Using the JAVA language please. 1) exercises - branching Write...

    Need help with a few questions! Using the JAVA language please. 1) exercises - branching Write a method whatToWear(int temp) that takes a temperature and then outputs a string for what to wear in different weather conditions. There must be at least 3 categories. For example, whatToWear(90) might return “shorts” and whatToWear(30) might return “down coat” 2) Enum exercise • Define an enum Seasons, and rewrite the whatToWear method to use enums and switch statement 8) 2D array exercise 1....

  • You must write C# classes which are used to manage product review data for Books and...

    You must write C# classes which are used to manage product review data for Books and Cars. You will write an abstract class called Review which abstracts common properties (review rating and comments). You will then create an Interface responsible for the functionality to display the Reviewcontent. Then, you will create 2 concrete classes which inherit from Review and implement the Interface. Finally, you will create console applicationwhich will create 2 CarReview instances and 2 BookReview instances and display them...

  • How to solve and code the following requirements (below) using the JAVA program? 1. Modify the...

    How to solve and code the following requirements (below) using the JAVA program? 1. Modify the FoodProduct Class to implement Edible, add the @Overrride before any methods that were there (get/set methods) that are also in the Edible interface. 2. Modify the CleaningProduct Class to implement Chemical, add the @Overrride before any methods that were there (get/set methods) that are also in the Chemical interface. 3. Create main class to read products from a file, instantiate them, load them into...

  • USE JAVA PLEASE And answer all questions Question 5.1 1. Write a program that reads in...

    USE JAVA PLEASE And answer all questions Question 5.1 1. Write a program that reads in a number n and then reads n strings. it then reads a string s from the user and gives you the word that was typed in after s. Example input: 4 Joe Steve John Mike Steve Example output: John Example input: 7 Up Down Left Right North South East Right Example output: North 2. Remember to call your class Program Question 5.2 1. Write...

  • Chapter 5 Assignment Read directions: In JAVA design and implement a class called Dog that contains...

    Chapter 5 Assignment Read directions: In JAVA design and implement a class called Dog that contains instance data that represents the dog's name and dog's age. Define the Dog constructor to accept and initialize instance data. Include getter and setter methods for the name and age. Include a method to compute and return the age of the dog in "person years" (seven times age of dog. Include a toString method that returns a one-time description of the dog (example below)....

  • 1. (TCO 7) Which of the following statements are true? (Points : 5)        Interfaces contain...

    1. (TCO 7) Which of the following statements are true? (Points : 5)        Interfaces contain one and only one implemented method, a constructor.        Interfaces are defined inside an abstract class.        All methods defined in an interface must be implemented when used by another class.        A true object-oriented design must contain as least one interface. Question 2. 2. (TCO 7) In an object-oriented program, methods with no implementation might be found in an _____ and/or a(n) ______....

  • Answer in eclispe please!!! Do the following: 1. Create a package named, “prob3” and a class...

    Answer in eclispe please!!! Do the following: 1. Create a package named, “prob3” and a class named, “Games2”. 2. Create a Player class and add this code: public class Player { private String name; private int points; public Player(String name, int points) { this.name = name; this.points = points; } public String getName() { return name; } public int getPoints() { return points; } @Override public String toString() { return "name=" + name + ", points=" + points; } }...

  • 60 points, Complete javadocs documentation required Be sure to submit all files (.java and dictio...

    60 points, Complete javadocs documentation required Be sure to submit all files (.java and dictionary.txt) required to run your program Background Boggle is a word game using a plastic grid of lettered dice, in which players attempt to find words in sequences of adjacent letters. The dice are randomly arranged in the grid, and players have 90 seconds to form as many words as possible from adjacent top-facing letters For example, the word SUPER is spelled in the gameboard to...

  • Write the code for the Song class. 1. Instance variables: title:String, lyrics:String, numAwards:int 2. For the...

    Write the code for the Song class. 1. Instance variables: title:String, lyrics:String, numAwards:int 2. For the 2-arg constructor (parameters are title and lyrics), use the following default value: - numAwards: 3 3. Create the 3-argument constructor. 4. No additionalconstructors. 5. Generate all getters and setters for instance variables 6. toString: Return a nicely formatted string describing this object 7. toSummary: This instance method will return a String that contains up to the first 10 characters of the lyrics. Be sure...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...

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