SlideShare a Scribd company logo
1 of 8
Download to read offline
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

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

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

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

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

More from ezhilvizhiyan

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

More from ezhilvizhiyan (20)

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

Recently uploaded

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 

Recently uploaded (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

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.