Question

In: Computer Science

complete all methods in java! /* Note:   Do not add any additional methods, attributes.         Do...

complete all methods in java!
/*
Note:   Do not add any additional methods, attributes.
        Do not modify the given part of the program.
        Run your program against the provided Homework2Driver.java for requirements.
*/

/*
Hint:   This Queue implementation will always dequeue from the first element of
        the array i.e, elements[0]. Therefore, remember to shift all elements
        toward front of the queue after each dequeue.
*/

public class QueueArray<T> {
    public static int CAPACITY = 100;
    private final T[] elements;
    private int rearIndex = -1;
   
    public QueueArray() {
    }

    public QueueArray(int size) {
    }
   
    public T dequeue() {

    }
   
    public void enqueue(T info) {

    }
   
    public boolean isEmpty() {
       
    }
   
    public boolean isFull() {
       
    }
   
    public int size() {
       
    }
}

Solutions

Expert Solution

If you have any doubts, please give me comment...

/*

Note:   Do not add any additional methods, attributes.

        Do not modify the given part of the program.

        Run your program against the provided Homework2Driver.java for requirements.

*/

/*

Hint:   This Queue implementation will always dequeue from the first element of

        the array i.e, elements[0]. Therefore, remember to shift all elements

        toward front of the queue after each dequeue.

*/

public class QueueArray<T> {

    public static int CAPACITY = 100;

    private final T[] elements;

    private int rearIndex = -1;

    @SuppressWarnings("unchecked")

    public QueueArray() {

        elements = (T[]) new Object[CAPACITY];

    }

    @SuppressWarnings("unchecked")

    public QueueArray(int size) {

        CAPACITY = size;

        elements = (T[]) new Object[size];

    }

    public T dequeue() {

        if(!isEmpty()){

            T temp = elements[0];

            for (int i = 0; i < rearIndex; i++) {

                elements[i] = elements[i + 1];

            }

            rearIndex--;

            return temp;

        }

        return null;

    }

    public void enqueue(T info) {

        if(!isFull()){

            rearIndex++;

            elements[rearIndex] = info;

        }

    }

    public boolean isEmpty() {

        return rearIndex == -1;

    }

    public boolean isFull() {

        return rearIndex+1 == CAPACITY;

    }

    public int size() {

        return rearIndex+1;

    }

}


Related Solutions

Complete the java program. /* Note: Do not add any additional methods, attributes. Do not modify...
Complete the java program. /* Note: Do not add any additional methods, attributes. Do not modify the given part of the program. Run your program against the provided Homework2Driver.java for requirements. */ /* Hint: This Queue implementation will always dequeue from the first element of the array i.e, elements[0]. Therefore, remember to shift all elements toward front of the queue after each dequeue. */ public class QueueArray<T> { public static int CAPACITY = 100; private final T[] elements; private int...
Complete all parts of this java program. Use Homework2Driver.java below for testing. /* Note: Do not...
Complete all parts of this java program. Use Homework2Driver.java below for testing. /* Note: Do not add any additional methods, attributes. Do not modify the given part of the program. Run your program against the provided Homework2Driver.java for requirements. */ public class Node<T> { private T info; private Node nextLink; public Node(T info) { } public void setInfo(T info) { } public void setNextLink(Node nextNode) { } public T getInfo() { } public Node getNextLink() { } } /* Note:...
Complete the attached program by adding the following: a) add the Java codes to complete the...
Complete the attached program by adding the following: a) add the Java codes to complete the constructors for Student class b) add the Java code to complete the findClassification() method c) create an object of Student and print out its info in main() method of StudentInfo class. * * @author * @CS206 HM#2 * @Description: * */ public class StudentInfo { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application...
IN JAVA: Repeat Exercise 28, but add the methods to the LinkedStack class. Add the following...
IN JAVA: Repeat Exercise 28, but add the methods to the LinkedStack class. Add the following methods to the LinkedStacked class, and create a test driver for each to show that they work correctly. In order to practice your array related coding skills, code each of these methods by accessing the internal variables of the LinkedStacked, not by calling the previously defined public methods of the class. - String toString()—creates and returns a string that correctly represents the current stack....
How to write a Java program that has a base class with methods and attributes, subclasses...
How to write a Java program that has a base class with methods and attributes, subclasses with methods and attributes. Please use any example you'd like.
Modify the attached files to do the following in java: 1) Add all necessary Getters and...
Modify the attached files to do the following in java: 1) Add all necessary Getters and Setters to the Class file. 2) Add code to compare two instances of the class to see which one comes before the other one based on the zipcode. //Address1.java public class Address {    // attributes    private String street, aptNum, city, state;    private int zip;    // constructors    public Address(String street, String aptNum, String city, String state, int zip)    {...
JAVA Add static methods largest and smallest to the Measurable interface. The methods should return the...
JAVA Add static methods largest and smallest to the Measurable interface. The methods should return the object with the largest or smallest measure from an array of Measurable objects.
Code in Java Given the LinkedList class that is shown below Add the following methods: add(String...
Code in Java Given the LinkedList class that is shown below Add the following methods: add(String new_word): Adds a linkedlist item at the end of the linkedlist print(): Prints all the words inside of the linkedlist length(): Returns an int with the length of items in the linkedlist remove(int index): removes item at specified index itemAt(int index): returns LinkedList item at the index in the linkedlist public class MyLinkedList { private String name; private MyLinkedList next; public MyLinkedList(String n) {...
In Java: Complete the following methods in the template by adhering to the comments: // TO...
In Java: Complete the following methods in the template by adhering to the comments: // TO DO: add your implementation and JavaDoc public class BetterArray<T> { private static final int DEFAULT_CAPACITY = 2; //default initial capacity / minimum capacity private T[] data; //underlying array, you MUST use this for full credit // ADD MORE PRIVATE MEMBERS HERE IF NEEDED! @SuppressWarnings("unchecked") public BetterArray() { //constructor //initial capacity of the array should be DEFAULT_CAPACITY } @SuppressWarnings("unchecked") public BetterArray(int initialCapacity) { // constructor...
Complete the following methods in java: Consult the rest of the methods of BigInteger from its...
Complete the following methods in java: Consult the rest of the methods of BigInteger from its API documentation as needed to solve the following problems. public static List<BigInteger> fibonacciSum(BigInteger n) The unique breakdown into Fibonacci numbers can be constructed with a greedy algorithm that simply finds the largest Fibonacci number f that is less than or equal to n. Add this f to the result list, and break down the rest of the number given by the expression n-f the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT