
1. Implement the “missing” front and rear operations in JAVA using constructor and
Also write output:
class Queue
{
private int maxSize; private long[] queArray; private int front;
private int rear; private int nItems;
public Queue(int s) // constructor
{
maxSize = s;
queArray = new long[maxSize]; front = 0;
rear = -1;
nItems = 0;
}
//
public void insert(long j)
{
// put item at rear of queue
//
public long remove()
{
// take item from front of queue
//And then return
}
//
public long peekFront()
{
// peek at front of queue
//Return queue array front
}
//
public boolean isEmpty(){
// true if queue is empty
//return nItems zero
}
//
public boolean isFull()
{
// true if queue is full return
}
//
public int size() // number of items in queue
{
//return nItems;
}
//
} // end class Queue
//////////////////////////////////////////////////////////////// class QueueApp
{
public static void main(String[] args)
{
Queue theQueue = new Queue(5); // queue holds 5 items theQueue.insert(10); // insert 4 items theQueue.insert(20);
theQueue.insert(30); theQueue.insert(40); theQueue.remove(); // remove 3 items theQueue.remove(); // (10, 20, 30) theQueue.remove();
theQueue.insert(50); // insert 4 more items theQueue.insert(60); // (wraps around) theQueue.insert(70);
theQueue.insert(80);
while( !theQueue.isEmpty() ) // remove and display
{ // all items
long n = theQueue.remove(); // (40, 50, 60, 70, 80) System.out.print(n);
System.out.print(“ “);
}
System.out.println(“”);
} // end main()
} // end class QueueApp

Step by stepSolved in 2 steps with 1 images

- Image attachedarrow_forwardCode 16-1 /** This class has a recursive method. */ public class EndlessRecursion { public static void message() { System.out.println("This is a recursive method."); message(); } } Code 16.2 /** This class has a recursive method message, which displays a message n times. */ public class Recursive { public static void messge (int n) { if (n>0) { System.out.println (" This is a recursive method."); message(n-1); } } } Task #1 Tracing Recursive Methods 1. Copy the file Recursion.java (see Code Listing 16.1) from the Student Files or as directed by your instructor. 2. Run the program to confirm that the generated answer is correct. Modify the factorial method in the following ways: a. Add these lines above the first if statement: int temp; System.out.println("Method call -- " + "calculating " + "Factorial of: " + n); Copyright © 2019 Pearson Education, Inc., Hoboken NJ b. Remove this line in the recursive section at the end of the method: return…arrow_forwarddo part 4 import java.util.*; // Car classclass Car{ private String name; // Variable to hold car name private String model; // Variable to hold car model // Default constructor Car(){ this.name = null; this.model = null; } // Parametrised constructor Car(String name, String model){ this.name = name; this.model = model; } // Function to get car name public String getName(){ return this.name; }} // Dealer classclass Dealer{ private Car[] arr; // Array holding car objects for a dealer private int count; // Variable to hold number of cars under a dealer // Default constructor Dealer(){ arr = new Car[50]; count=0; } // Function to add a car under a dealer public void addCar(Car obj){ this.arr[this.count] = obj; this.count++; } // Function to check if a car exists under a dealer or not public boolean contains(String name){…arrow_forward
- Assume class LinkedQueue has been deńned using the implementation in your textbook that myQueue has been initialized so it is empty. Type the EXACT output of the following code segment. You may assume that the code compiles and executes without errors. LinkedQueue myQueue; int i - 1; int j = 2; int k = 3; int n = 4; myQueue.enqueue (n); myQueue.enqueue (); i = myQueue.peekFront (); myQueue.dequeue (); myQueue.enqueue (k); n = myQueue.peekFront (); myQueue.dequeue (); myQueue.enqueue (); myQueue.enqueue (n); while (ImyQueue.isEmpty ()) { i = myQueue.peekFront (); myQueue.dequeue (); cout << i<< " ": cout << endl;arrow_forwardUML DIAGRAM FOR THE FOLLOWING public class BookStore { /** * @param args the command line arguments */ Customer customerList[]; Product productList[]; public static void main(String[] args) { // TODO code application logic here } public Customer registerPremiumMember(){ Customer newCustomer = new Customer(); return newCustomer; } public void completePurchase(Customer coCustomer){ } public Customer addToBasket(Customer currentCustomer, Product cuProduct){ currentCustomer.addToBasket(cuProduct); return currentCustomer; }}arrow_forwardComputer science helparrow_forward
- 6. Given: class Pet { public: virtual void eat() { cout eat(); } What is the result of compiling and running the above program? m. The program compiles and crashes when it runs. i. The program compiles and runs, printing "Pet::eat" j. The program compiles and runs, printing "Cat::eat" The program compiles and runs to completion without printing anything. n. o. None of the above. k. The program fails to compile because the method eat is not marked virtual in Cat. I. The program fails to compile for some other reason.arrow_forwardInstructions-Java Assignment is to define a class named Address. The Address class will have three private instance variables: an int named street_number a String named street_name and a String named state. Write three constructors for the Address class: an empty constructor (no input parameters) that initializes the three instance variables with default values of your choice, a constructor that takes the street values as input but defaults the state to "Arizona", and a constructor that takes all three pieces of information as input Next create a driver class named Main.java. Put public static void main here and test out your class by creating three instances of Address, one using each of the constructors. You can choose the particular address values that are used. I recommend you make them up and do not use actual addresses. Run your code to make sure it works. Next add the following public methods to the Address class and test them from main as you go: Write getters and…arrow_forwardDraw a UML class diagram for the following code: class Node: def __init__(self, value): self.value = value self.next = None class Stack: def __init__(self): self.top = None def isEmpty(self): return self.top is None def push(self, item): new_node = Node(item) new_node.next = self.top self.top = new_node def pop(self): if self.isEmpty(): raise Exception("Stack is empty") popped_item = self.top.value self.top = self.top.next return popped_item def popAll(self): items = [] while not self.isEmpty(): items.append(self.pop()) return items[::-1] def peek(self): if self.isEmpty(): raise Exception("Stack is empty") return self.top.value # Verificationstack = Stack()print("Is stack empty?", stack.isEmpty()) stack.push(10)stack.push(20)stack.push(30)print("Top item:", stack.peek()) print("Popped item:", stack.pop())print("Popped…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





