SlideShare a Scribd company logo
I'm trying to calculate the total 'wait time' and the average wait time for my 'restaurant
waitlist' application. I can't figure that part out and I've tried to display the total, but it keeps
displaying the total for one. I'm using a linkedlist and want it to keep adding as I add people to
the waitlist. I also do not know how to display the average as the name is a string and if I do the
total/name, it gives me an error. If I parse it to an Int, it gives me an error. Any help would be
appreciated. When I click the following button, it should display the running total.
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
Random rand = new Random();
String name = txtName.getText();
int time = rand.nextInt(30) + 1;
int totaltime = time;
int partySize = Integer.parseInt(txtSize.getText());
txtTotal.setText(String.valueOf(totaltime) + " minutes until your table is ready.");
Highest = partySize;
String result = " Name: " + txtName.getText() + " Party Size: " + partySize + " Wait Time: "
+ time + " minutes.";
stack.enqueue(result);
Wait++;
}
private void btnDisplayActionPerformed(java.awt.event.ActionEvent evt) {
String result;
int s;
int size = stack.size();
lstOutput.removeAll();
for (s = 0; s < size; s++) {
result = (String)stack.dequeue();
lstOutput.add(result);
}
}
stack is my LinkedList.
LinkedListStack stack = new LinkedListStack();
This is the LinkedListStack
public class LinkedListStack implements QueueInterface {
private LinkedList list = new LinkedList<>(); // an empty list
public LinkedListStack() {
} // new queue relies on the initially empty list
public int size() {
return list.getSize();
}
public boolean isEmpty() {
return list.isEmpty();
}
public void enqueue(E element) {
list.addLast(element);
}
public E first() {
return list.first();
}
public E dequeue() {
return list.removeFirst();
}
}
This is my QueueInterface
public interface QueueInterface {
int size();
boolean isEmpty();
// adds an item to the stack
void enqueue(E e);
// return but not remove the top item on the stack
E first();
// remove item at the top of the stack
E dequeue();
}
And this is the LinkedList I'm using.
public class LinkedList {
private int size;
private Node head;
private Node tail;
// default constructor
public LinkedList() {
size = 0;
head = null;
tail = null;
}
// read-only property
public int getSize() {
return size;
}
public boolean isEmpty() {
// replaces an if/else
return (size == 0);
}
// return but not remove head of the list
public E first() {
if ( isEmpty() ) {
return null;
}
else {
return head.getElement();
}
}
public E last() {
if ( isEmpty() ) {
return null;
}
else {
return tail.getElement();
}
}
public void addFirst(E e) {
// create a new node and make it the new head of the list
head = new Node<>(e, head);
if (size == 0) {
tail = head; // special case first item in the list
}
size++;
}
public void addLast(E e) {
// create a new node and add to the tail of the list
Node newest = new Node<>(e, null);
if (size == 0) { // special case for the first item
head = newest; // now head points to the new node
}
else {
tail.setNext(newest);
}
tail = newest;
size++;
}
public E removeFirst() {
if (isEmpty() ) {
return null;
}
else {
E tets = head.getElement();
head = head.getNext();
size--;
if (size == 0) {
tail = null; // list is now empty
}
return tets;
}
}
// nested class
public class Node {
private E element;
private Node next;
// custom constructor
public Node(E e, Node n) {
element = e;
next = n;
}
// get element
public E getElement() {
return element;
}
public Node getNext() {
return next;
}
public void setNext(Node n) {
next = n;
}
} // end nested node class
} // end of LinkedList
Solution
Now, as per the code given, below are my finding and the updated part in the bold and their
explanation in the comments:
private static int totalWaitTime=0;
// There has to be an static total wait counter. You were actually getting the random time and
printing the same //time due to which the time for single was occurring.
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
Random rand = new Random();
String name = txtName.getText();
int time = rand.nextInt(30) + 1;
totalWaitTime+=time; // For every party we generate the time and add the time to get the total
time
int partySize = Integer.parseInt(txtSize.getText());
txtTotal.setText(String.valueOf(totalWaitTime) + " minutes until your table is ready."); //
Updated //the variable name for the totalWaitTime to print the total
Highest = partySize;
int avgWaitTime = totalWaitTime/stack.size(); // avgWaitTime is the variable to hold the
average, //it would be the totalwaittime divide by the stack size. Here the stack size is actually
the total party waiting.
String result = " Name: " + txtName.getText() + " Party Size: " + partySize + " Wait Time: "
+ time + " minutes.";
stack.enqueue(result);
Wait++;
}
private void btnDisplayActionPerformed(java.awt.event.ActionEvent evt) {
String result;
int s;
int size = stack.size();
lstOutput.removeAll();
for (s = 0; s < size; s++) {
result = (String)stack.dequeue();
// Also you would have to reduce the time when an customer is given its table,so I have split the
string and got the //time from it
txtTotal.setText(result.split(" Wait Time: ").split(" ")[0] + " minutes until your table
is ready.");
lstOutput.add(result);
}
}
I have tried to not touch your Stack and LinkedList part, just the handler button event code.

More Related Content

PDF
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
PDF
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
PDF
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
DOCX
Write a program to find the number of comparisons using the binary se.docx
PDF
This is problem is same problem which i submitted on 22017, I just.pdf
PDF
please i need help Im writing a program to test the merge sort alg.pdf
PDF
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
PDF
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
Write a program to find the number of comparisons using the binary se.docx
This is problem is same problem which i submitted on 22017, I just.pdf
please i need help Im writing a program to test the merge sort alg.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf

Similar to Im trying to calculate the total wait time and the average wai.pdf (20)

PDF
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
DOCX
Table.java Huffman code frequency tableimport java.io.;im.docx
PDF
Given below is the completed implementation of MyLinkedList class. O.pdf
PDF
hi i have to write a java program involving link lists. i have a pro.pdf
PDF
I need help creating a parametized JUnit test case for the following.pdf
PDF
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
PDF
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
PDF
In C++Add the function min as an abstract function to the classar.pdf
PDF
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
PDF
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
PDF
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
PDF
How do I fix it in javaLinkedList.java Defines a doubl.pdf
PDF
Describe a data structure to represent sets of elements (each element.pdf
DOCX
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PDF
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
PDF
I have created a class hasdhedDictionary that implements the Diction.pdf
PDF
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
PDF
So I have this code(StackInAllSocks) and I implemented the method but.pdf
PDF
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
DOCX
DS UNIT4_OTHER LIST STRUCTURES.docx
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Table.java Huffman code frequency tableimport java.io.;im.docx
Given below is the completed implementation of MyLinkedList class. O.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
I need help creating a parametized JUnit test case for the following.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
In C++Add the function min as an abstract function to the classar.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
Describe a data structure to represent sets of elements (each element.pdf
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I have created a class hasdhedDictionary that implements the Diction.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
DS UNIT4_OTHER LIST STRUCTURES.docx
Ad

More from ezhilvizhiyan (20)

PDF
Hi please complete the following with detailed working out Find the .pdf
PDF
Explain and discuss 4G wireless communications and their advantages..pdf
PDF
Draw and describe a module of the cross-cultural communication pr.pdf
PDF
Discuss the reasons why visions fail. What steps can be implemented .pdf
PDF
Describe the original purpose of the Clean Air Act Policy of 1963. E.pdf
PDF
Continuity 100 Let f be a continuous function on a metric space X. L.pdf
PDF
Admitting New Partner With Bonus Cody Jenkins and Lacey Tanner formed.pdf
PDF
7. In many respects metal binding is similar to the binding of a prot.pdf
PDF
3. Photosynthetic organisms produce about 300 x 1015 g of oxygen per .pdf
PDF
1. Which is less soluble in water, 1-pentanol or 1-heptanol Explain..pdf
PDF
X Company has the following budgeted cash flows for JanuaryIf the .pdf
PDF
Why did animal phyla appear so suddenly during the Cambrian explosion.pdf
PDF
Which of the following information-management systems uses artificia.pdf
PDF
Which of the following was part of the reason for the European excha.pdf
PDF
Ture or false or uncertain ( explain why) Thank you! e. Output per c.pdf
PDF
This is for a C programDene a Car structure type in your header le.pdf
PDF
This project will implement a simple usernamepassword lookup system.pdf
PDF
The following code is based on the Josephus problem, the code does c.pdf
PDF
Tech transfers should the fed Gov’t keep subsidizing University .pdf
PDF
Remaining Time 31 minutes, 22 seconds QUESTION 1 Question Completion.pdf
Hi please complete the following with detailed working out Find the .pdf
Explain and discuss 4G wireless communications and their advantages..pdf
Draw and describe a module of the cross-cultural communication pr.pdf
Discuss the reasons why visions fail. What steps can be implemented .pdf
Describe the original purpose of the Clean Air Act Policy of 1963. E.pdf
Continuity 100 Let f be a continuous function on a metric space X. L.pdf
Admitting New Partner With Bonus Cody Jenkins and Lacey Tanner formed.pdf
7. In many respects metal binding is similar to the binding of a prot.pdf
3. Photosynthetic organisms produce about 300 x 1015 g of oxygen per .pdf
1. Which is less soluble in water, 1-pentanol or 1-heptanol Explain..pdf
X Company has the following budgeted cash flows for JanuaryIf the .pdf
Why did animal phyla appear so suddenly during the Cambrian explosion.pdf
Which of the following information-management systems uses artificia.pdf
Which of the following was part of the reason for the European excha.pdf
Ture or false or uncertain ( explain why) Thank you! e. Output per c.pdf
This is for a C programDene a Car structure type in your header le.pdf
This project will implement a simple usernamepassword lookup system.pdf
The following code is based on the Josephus problem, the code does c.pdf
Tech transfers should the fed Gov’t keep subsidizing University .pdf
Remaining Time 31 minutes, 22 seconds QUESTION 1 Question Completion.pdf
Ad

Recently uploaded (20)

PDF
Anesthesia in Laparoscopic Surgery in India
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Computing-Curriculum for Schools in Ghana
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
RMMM.pdf make it easy to upload and study
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Complications of Minimal Access Surgery at WLH
PDF
01-Introduction-to-Information-Management.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
Anesthesia in Laparoscopic Surgery in India
O5-L3 Freight Transport Ops (International) V1.pdf
Microbial diseases, their pathogenesis and prophylaxis
Computing-Curriculum for Schools in Ghana
GDM (1) (1).pptx small presentation for students
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Final Presentation General Medicine 03-08-2024.pptx
Orientation - ARALprogram of Deped to the Parents.pptx
O7-L3 Supply Chain Operations - ICLT Program
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Microbial disease of the cardiovascular and lymphatic systems
RMMM.pdf make it easy to upload and study
FourierSeries-QuestionsWithAnswers(Part-A).pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Complications of Minimal Access Surgery at WLH
01-Introduction-to-Information-Management.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025

Im trying to calculate the total wait time and the average wai.pdf

  • 1. I'm trying to calculate the total 'wait time' and the average wait time for my 'restaurant waitlist' application. I can't figure that part out and I've tried to display the total, but it keeps displaying the total for one. I'm using a linkedlist and want it to keep adding as I add people to the waitlist. I also do not know how to display the average as the name is a string and if I do the total/name, it gives me an error. If I parse it to an Int, it gives me an error. Any help would be appreciated. When I click the following button, it should display the running total. private void btnAddActionPerformed(java.awt.event.ActionEvent evt) { Random rand = new Random(); String name = txtName.getText(); int time = rand.nextInt(30) + 1; int totaltime = time; int partySize = Integer.parseInt(txtSize.getText()); txtTotal.setText(String.valueOf(totaltime) + " minutes until your table is ready."); Highest = partySize; String result = " Name: " + txtName.getText() + " Party Size: " + partySize + " Wait Time: " + time + " minutes."; stack.enqueue(result); Wait++; } private void btnDisplayActionPerformed(java.awt.event.ActionEvent evt) { String result;
  • 2. int s; int size = stack.size(); lstOutput.removeAll(); for (s = 0; s < size; s++) { result = (String)stack.dequeue(); lstOutput.add(result); } } stack is my LinkedList. LinkedListStack stack = new LinkedListStack(); This is the LinkedListStack public class LinkedListStack implements QueueInterface { private LinkedList list = new LinkedList<>(); // an empty list public LinkedListStack() { } // new queue relies on the initially empty list public int size() { return list.getSize(); } public boolean isEmpty() { return list.isEmpty(); } public void enqueue(E element) { list.addLast(element); } public E first() { return list.first(); }
  • 3. public E dequeue() { return list.removeFirst(); } } This is my QueueInterface public interface QueueInterface { int size(); boolean isEmpty(); // adds an item to the stack void enqueue(E e); // return but not remove the top item on the stack E first(); // remove item at the top of the stack E dequeue(); } And this is the LinkedList I'm using. public class LinkedList { private int size; private Node head; private Node tail; // default constructor public LinkedList() { size = 0; head = null; tail = null; } // read-only property public int getSize() { return size;
  • 4. } public boolean isEmpty() { // replaces an if/else return (size == 0); } // return but not remove head of the list public E first() { if ( isEmpty() ) { return null; } else { return head.getElement(); } } public E last() { if ( isEmpty() ) { return null; } else { return tail.getElement(); } } public void addFirst(E e) { // create a new node and make it the new head of the list head = new Node<>(e, head); if (size == 0) { tail = head; // special case first item in the list } size++; }
  • 5. public void addLast(E e) { // create a new node and add to the tail of the list Node newest = new Node<>(e, null); if (size == 0) { // special case for the first item head = newest; // now head points to the new node } else { tail.setNext(newest); } tail = newest; size++; } public E removeFirst() { if (isEmpty() ) { return null; } else { E tets = head.getElement(); head = head.getNext(); size--; if (size == 0) { tail = null; // list is now empty } return tets; } } // nested class public class Node { private E element; private Node next;
  • 6. // custom constructor public Node(E e, Node n) { element = e; next = n; } // get element public E getElement() { return element; } public Node getNext() { return next; } public void setNext(Node n) { next = n; } } // end nested node class } // end of LinkedList Solution Now, as per the code given, below are my finding and the updated part in the bold and their explanation in the comments: private static int totalWaitTime=0; // There has to be an static total wait counter. You were actually getting the random time and printing the same //time due to which the time for single was occurring. private void btnAddActionPerformed(java.awt.event.ActionEvent evt) { Random rand = new Random(); String name = txtName.getText(); int time = rand.nextInt(30) + 1;
  • 7. totalWaitTime+=time; // For every party we generate the time and add the time to get the total time int partySize = Integer.parseInt(txtSize.getText()); txtTotal.setText(String.valueOf(totalWaitTime) + " minutes until your table is ready."); // Updated //the variable name for the totalWaitTime to print the total Highest = partySize; int avgWaitTime = totalWaitTime/stack.size(); // avgWaitTime is the variable to hold the average, //it would be the totalwaittime divide by the stack size. Here the stack size is actually the total party waiting. String result = " Name: " + txtName.getText() + " Party Size: " + partySize + " Wait Time: " + time + " minutes."; stack.enqueue(result); Wait++; } private void btnDisplayActionPerformed(java.awt.event.ActionEvent evt) { String result; int s; int size = stack.size(); lstOutput.removeAll(); for (s = 0; s < size; s++) { result = (String)stack.dequeue(); // Also you would have to reduce the time when an customer is given its table,so I have split the string and got the //time from it txtTotal.setText(result.split(" Wait Time: ").split(" ")[0] + " minutes until your table is ready."); lstOutput.add(result);
  • 8. } } I have tried to not touch your Stack and LinkedList part, just the handler button event code.