Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Explain why the array implementation of a stack does not require elements to be shifted but the (non-circular) array implementation of a queue does.
Assume you have a queue called Q with the following contents, and trace the following operations:

(front) (back)

4 8 2 3 1


System.out.println(Q.first()); //a) What is printed?

Integer Y = Q.dequeue();

System.out.println(Q.first()); //b) What is printed?

Q.enqueue(new Integer (5));

System.out.println(Q.dequeue()); //c) What is printed?

System.out.println(Q.first()); //d) What is printed?

//e) What are final the contents of the queue? (Indicate front and back.)
Trace a Queue (called Q) through the following operations:

Queue Q = new Queue();

Q.enqueue(new Integer(4));

Q.enqueue(new Integer(3));

//a) What is the content of the queue at this point?

Integer Y = Q.dequeue();

Q.enqueue(new Integer(7));

Q.enqueue(new Integer(2));

Q.enqueue(new Integer(5));

Q.enqueue(new Integer(9));

//b) What is the content of the queue at this point?

Integer Y = Q.dequeue();

Q.enqueue(new Integer(3));

Q.enqueue(new Integer(9));

//c) What is the content of the queue at this point?
Consider the following scenario: In a social media news feed, users are required to subscribe to the news feed before receiving any news or updates. Users can only subscribe to each news feed only up to five (5) different feeds.


Given your knowledge of linked structures and arrays, determine which of the two complex types you would use to implement the solution (1) for tracking the number of subscribers within a media company and (2) for tracking the number of news feed a subscriber can subscribe to. Justify your answers. (e.g., identify the advantages and disadvantage for inserting, deleting, and searching through different complex types.)
Consider the following code for creating and inserting a element into a list. Assume that front is a variable that represents a reference to the first node of a list.

public void insert_number(T element) {

LinearNode<T> temp = new LinearNode<T>(element);

//insert

temp = front;

front.setNext(temp);

}

Answer the following questions:

a) Does this function correctly insert the node into the linked list? Explain. Hint: Try drawing a picture of the list.


b) Give the correct code for adding node at the head of the linked list.
1-public double getTotalCost();
A method that returns the total cost of items without tax.The number has to be rounded to the nearest two decimal points.... @return The total cost without tax
2-public double getTotalTax();
A method that returns the total tax. The number has to be rounded to the nearest two decimal points..@return The total taxes of items
3-public void addItem(Fruit fruit);
Add a fruit to the cashier for checkout...@param fruit The fruit object to add
4-public void clear();
Clear all fruits from this cashier
5-public int getNumberOfItems();
Get the number of items in the current cashier box .. @return the total number of items in this cashier box
You will also need to create a Cashier.java file in package qa.edu.qu.cmps251.hw3 (not in the .model subpackage) that implements this interface. The cashier must have an ArrayList of fruits, a method called getTotalCost() will return the cost of all the fruit objects in the list, and getTotalTax() will return only the total taxes of the fruits in the list. You must use the constant TAX_RATE in the Consts.java file to get that rate and calculate the taxes properly. The constructor of this class must take the shop name. This shop name will be printed in the receipt eventually.
Pay attention that you must round your prices to the nearest 2 digit decimal points in both of these methods.
You must also override toString() method and return a user-friendly receipt of all the items in the basket in this cashier.
Person persons[] = new Person[5];

public static int femaleNum(Person[] persons){

int count = 0;

for(Person p : persons){
if (p.getGender() == 'F'){

count++;
}
}

Can you please explain what the meaning of "Person p : persons" inside the for loop is?
What is p and where does it come from? What is the meaning of ":"? Thanks.
Class Month has the followin instance variables:

a variable ‘name’ to store name of the month
an int array days can hold 28 30 or 31 values. Days used to store max daily temps
Constructor to specify size array & month name
setDays to specify size of array
setMonth stores name of month in name variable
getMonth to return name of the month
setTemps to allow all temps for that month to be entered into the days array
getTemp returns temp on a specified day

App program:

Creates an array of Month objects called Year & assigns appropriate names & num of days to each month
Create loop in the program to allow the temps for Jan & Feb to be entered
Display temp on 3rd Jan & 15th Feb
Write a method to display the highest temp in the 2 months & date on which it occurred
Find avg temp in a specified month
Find range of temps in a specified month (highest – lowest temp)
Find number of days in a specified month that the temp was higher than a specified value
The cashier class must have an ArrayList of fruits, a method called getTotalCost() will return the cost of all the fruit objects in the list, and getTotalTax() will return only the total taxes of the fruits in the list. You must use the constant TAX_RATE in the Consts.java file to get that rate and calculate the taxes properly. The constructor of this class must take the shop name. This shop name will be printed in the receipt eventually.Round Prices to nearest 2 digit decimal points in both of these methods. A getTotalTax() that results in 3.432 will not be accepted. Here, the number should be 3.43.You must also override toString() method and return a user-friendly receipt of all the items in the basket in this cashier.
LATEST TUTORIALS
APPROVED BY CLIENTS