• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

PriorityQueue and simpleQueue

 
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I have a program that is going to run with priority queue once, and then simple queue. The program is based on a hospital determining what is the time someone can live without being on a er table, wait times, emptying tables, etc. We are going to assume that if that make it to the er table they will live. So I have completed most of it, but I just need some help in the final pieces. its honestly not that difficult, or not suppose to be but I am scratching my head at the end here. SO there are todo comments, and under those I have what I think is the correct code.

1) I want to make sure I did this correct. The todo says to do this only if the conditions are right, so I call getnewpatients to get the list of new patients, then it says to go through the triage queue which is created in the method. I cant call that out of a method, and since it returns a queue of patients I assume that I can just loop through the method.




2) I am not really sure what this is asking. if im just returning the count of waiting room or what?




3) So for this I ant to check and see if the patient time has expired, and if so then add to the expiry count. I am just not sure of the if statement or what goes in there. I am mainly working out of 2 classes EmergencyRoom and Patient. Here are a description of the patient variables. Between these and whats in the emergencyRoom I am sot sure what to use.

• TimeToLive - minutes until it is too late for the patient to survive if not on an ER table
• TimeForProcedure - minutes to perform the procedure for this patient
• LastPossibleMoment - time (relative to hospital time) when this patient MUST be on an ER table
• IntakeTime - time entering waiting room; setting this value also adjusts the LastPossibleMoment based on the current time
• TimeEnteringER - time when patient is placed on an ER table


3a) if the patient time is not up then we add him to the er table, and set the time he made it to the er table. But I get errors on patient.timeenteringer, and my add patient method. timeenteringer says I need a object reference, and add patient does not like the patient I give it.



 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my classes

EmergencyRoom


Patient
 
Marshal
Posts: 80244
426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope I never have to go into your hospital

I presume the Queue classes do something similar to the Java® classes of the same name. So your priority queue will need some sort of sorting to do with the urgency of the situation, so you will need some way to compare time to live. But with the ordinary queues, what is going to happen? You are going to get people out of it in the same order they went in: remember a queue is usually FIFO. What are you going to do? Go through the whole queue and find the people with the shortest time to live?
Your methods are far too long. One of them is over 120 lines. That suggests either you should rethink the whole logic for that method, or it needs to be divided into lots of smaller methods, (or both).
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not the best hospital. Everything has to be done in this method according to my instructions. Here is where I am at. If the patient didnt make it then I need to get another patient, well what if the next 3 patients all didnt make it? How could I handle that? I dont want to put a dead guy on the er table.

 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry here is the real code

 
Campbell Ritchie
Marshal
Posts: 80244
426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cody Biggs wrote:. . . Everything has to be done in this method according to my instructions. . . . If the patient didnt make it then I need to get another patient, well what if the next 3 patients all didnt make it? . . .

Did they all die waiting for that method to complete?

I suppose you are stuck with that instruction about that method, then. Once it has been given out, it is just about impossible to change the specification of an assignment. A half‑second loop at that for‑each loop suggests it will work all right. What happened to the if() in line 10? Did it actually compile?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The if was something I was thinking through. Thinking if some way how to handle multiple “expired” patients in a row. Just not sure.
 
Campbell Ritchie
Marshal
Posts: 80244
426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are ways to remove all patients who died in your Queue, but I wouldn't think of an if (...) as my first choice.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yea, thats why I trashed that idea. The only other thing I can think of would be a loop, and I was thinking of a for each that goes through the waiting room and just checks the above if statement again. So originally something like. Which wont work because the Iqueue class does not contain a definition for getEnumerator



So I thought of just a normal loop, but thats not going to go through my queue, just loop how many patients
 
Campbell Ritchie
Marshal
Posts: 80244
426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nor would I have used either of those sorts of loop.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I have no idea.
 
Campbell Ritchie
Marshal
Posts: 80244
426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What other sorts of loop are there?
 
Campbell Ritchie
Marshal
Posts: 80244
426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have to go away now, so don't expect a response from me for several hours at least.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The ones we have really used this semester are foreach. The ones I have only used are while, for, foreach
 
Campbell Ritchie
Marshal
Posts: 80244
426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There aren't many other sorts of loop: do‑while is the only sort you haven't mentioned, I think. You have already tried for loops and for‑each, and they didn't work, so there aren't that many left.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This what I have now


full class now. When I run it, it does not print the lines at the bottom. I still need to figure out the rest of those times below, but for people expired, total time, and total patients I think I got. It just does not print. The only thing that prints is the first console.writeline where is prints usePriority, after that nothing shows up

 
Campbell Ritchie
Marshal
Posts: 80244
426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That method is too long and complicated to understand. You will have to put some print instructions into it to watch the flow of execution.

Also, just as in Java®, never write == true or == false, which are both poor style and error‑prone if you write = by mistake.
Never while (b == true) ...
Always while (b) ...
Never while (b == false) ...
Always while (!b) ...
And != true is even worse style.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I have added some simple writelines, and have figured out that nothing after the while in the code below gets printed. not sure why

 
Campbell Ritchie
Marshal
Posts: 80244
426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is going to happen to the queue if the patient makes it onto the operating table?

Apart from your having to write bad code (one method too large), this looks as though you were writing code without first thinking through what you are going to do. If you had a piece of paper with this sort of thing written on:-. . . you would find it easy to write the code, and get it right. Some people might start nitpicking and say I have given you misleading instructions. That isn't true. They aren't misleading; they are positively wrong
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I think I have found the problem, but no idea how to solve it. So the code never breaks out of the while loop. instructor has currenttime set to 0, so in the condition time is never going to be greater than the last possible moment. And since the patient never died it does not get a new patient meaning the other condition is never met. Now the only this is how to solve that......even setting current time to something else, the last possible moment is still higher
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
got the stupid thing to print but now ignores all my total expired++ and my max patients

 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scratch all that above. got an email from the instructor.

Still where I was before the two previous post
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still can not figure out why it wont print!!! I was told that the problem was my while condition

then in one of the emails I get this message
" You want to stay in the loop as long as there is  someone in the waiting room AND you haven't found a living patient." But now i obviously can not get out of the loop for anything to print. So I changed it to like what he said


Still no luck. I dont freaking KNOW!!!
 
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you asked yourself the question if there is a difference, ,and if so what, between this exercise and a previous one, with customers being served by some tellers?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally got it working. I’m not sure what is was really. Using && was not working when I first ran it, and looked like it was stuck in the loop. So I just erased the whole line, and wrote it again. Not sure why, but that time it got everything working. Ended up getting a 94 in the assignment. Most frustrating assignment I’ve had.
 
A tiny monkey bit me and I got tiny ads:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic