Nothing prints after while loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • codybiggs1
    New Member
    • Apr 2018
    • 2

    Nothing prints after while loop

    So I am working on an assignment, and I thought it was close as far as the requirements go. I am stuck however because my final output does not print, in fact nothing prints after my while loop that is suppose to ad patient to the table. I added some simple writeline to figure out where it ends. I dont see why it cant get past the while loop?

    Some info on the assignment. It is a hospital, where we are simply keeping track of how many patients come in, how many didnt make it in time to the er, what was the longest wait of a patient. I dont have all that yet, I want to make sure I can print first. The main code is in on single method...yes that is terrible, but according to the instructor it must be in one method. SO the method is huge with over 100 lines, so its hard to kind of keep track of whats going on

    Here is the code
    Code:
    using System;
    using System.Collections.Generic;
    using PriorityQueue;
    using System.Collections;
    
    namespace Hospital
    {
        // DO NOT MODIFY
        public class Hospital
        {
            static public int CurrentTime { get; set; }
            static void Main(string[] args)
            {
                EmergencyRoom er = new EmergencyRoom();
                er.processPatients();
                Console.ReadLine();
            }
        }
    
        // DO NOT MODIFY
        class ERTable
        {
            // estimated time of completion
            public int ETC { get; set; }
            Patient patient;
            public bool IsFree { get { return (patient == null);}}
    
            public void AddPatient(Patient p)
            {
                patient = p;
                ETC = p.TimeForProcedure + Hospital.CurrentTime;
            }
    
            public void Clear()
            {
                patient = null;
                ETC = 0;
            }
        }
    
        // DO NOT MODIFY
        class TriageUnit
        {
            private readonly int seed = 97;
            private readonly Random rand;
    
            const int MIN_EXPIRY = 20;     // minimum time until patient will die if not seen
            const int MAX_EXPIRY = 120;    // maximum time until patient will die if not seen
            const int MIN_PATIENTS = 2;    // at least this many new patients every 10 minutes
            const int MAX_PATIENTS = 5;    // no more than this many new patients every 10 minutes
            const int MIN_TABLE_TIME = 10; // shortest time in the ER
            const int MAX_TABLE_TIME = 50; // longest time in the ER
    
            public TriageUnit()
            {
                rand = new Random(seed);
            }
    
            public Queue<Patient> getNewPatients()
            {
    
                Queue<Patient> newPatients = new Queue<Patient>();
                int numPatients = rand.Next(MIN_PATIENTS,MAX_PATIENTS + 1);
                for (int i = 0; i < numPatients; i++)
                {
                    int expiryTime = rand.Next(MIN_EXPIRY, MAX_EXPIRY + 1);
                    int operationTime = rand.Next(MIN_TABLE_TIME, MAX_TABLE_TIME + 1);
    
                    newPatients.Enqueue(new Patient(expiryTime, operationTime));
                }
                return newPatients;
            }
        }
    
        // TODO -- your code goes here
        class EmergencyRoom
        {
            const int NUM_TABLES = 12;
            const int SIMULATION_DURATION = 60 * 12; // one shift
    
            public void processPatients()
            {
                IQueue<Patient> waitingRoom = null;
                bool usePriority = false;
    
                // create an array or list of ERTables
                List<ERTable> tables = new List<ERTable>();
    
                for(int i = 0; i < NUM_TABLES; i++)
                {
                    tables.Add(new ERTable());
                }
    
                // this for loop will run twice, once with a SimpleQueue and once with the PriorityQueue
                for (int i = 0; i < 2; i++)
                {
                    Console.WriteLine("\nUsing Priority Queue: {0}", usePriority);
    
                    int totalExpired = 0;
                    int totalPatients = 0;
                    int maxPatients = 0;
                    int maxWait = 0;
                    int totalWait = 0;
                    int totalStay = 0;
                    int maxWaitingInLine = 0;
                    bool stillWorking = false;
    
    
                    // TODO -- create triage unit
                    TriageUnit triage = new TriageUnit();
    
                    // TODO set the waitingQueue to one or the other type Queue, depending on the value of usePriority
                    // you will need to instantiate the appropriate Queue in the if/else statement.
                    if (usePriority == false)
                    {
                        SimpleQueue<Patient> simple = new SimpleQueue<Patient>();
                        waitingRoom = simple;
                    }
                    else
                    {
                        PriorityQueue<Patient> priority = new PriorityQueue<Patient>();
                        waitingRoom = priority;
                    }
    
                    // Reset Hospital clock
                    Hospital.CurrentTime = 0;
    
                    while (Hospital.CurrentTime < SIMULATION_DURATION || waitingRoom.Count > 0 || stillWorking)
                    {
                        // TODO empty tables that are free
                        // look for table where ETC <= currentTime
                        // do not look for expired patients; if they made it to an ER table, they lived
                        foreach (var table in tables)
                        {
                            if (table.ETC <= Hospital.CurrentTime)
                            {
                                table.Clear();
                            }
                        }
    
                        // NOTE: do the following *ONLY* if currentTime < simulation duration, otherwise you'll never finish
                        // TODO: get list of new patients from triage unit
    
                        if (Hospital.CurrentTime < SIMULATION_DURATION)
                        {
                            triage.getNewPatients();
                            // for each patient in the triage queue
                            // set IntakeTime for each patient to 'currentTime'
                            // place new patients into waiting room
                            // when placing in waiting room, priority is the patient's last possible moment
                            foreach (var pat in triage.getNewPatients())
                            {
                                pat.IntakeTime = Hospital.CurrentTime;
                                waitingRoom.Add(pat.LastPossibleMoment, pat);
                                totalPatients++;
                            }
                        }
                        // TODO: check for maximum number in waiting room
                        if (totalPatients > waitingRoom.Count)
                        {
                            maxPatients = totalPatients;
                        }
                        else
                        {
                            maxPatients = waitingRoom.Count;
                        }
    
                        // TODO: for every EMPTY tables, be careful here
                        // remove next patient from waiting room
                        // check for expired patients (count them)
                        // (if the patient has expired, you'll need to get another one)
                        // placing living patients on empty ER table
                        // update any accumulators, maximums, etc.
    
                        foreach (var table in tables)
                        {
                            if (table.IsFree)
                            {
                                bool isFound = false;
                                Patient patient = waitingRoom.Remove();
                                while (waitingRoom.Count > 0 || isFound != true)
                                {
                                    if (Hospital.CurrentTime > patient.LastPossibleMoment)//patient didnt make it
                                    {
                                        totalExpired++;//count the total of people who did not make it
                                        patient = waitingRoom.Remove();//get another patient
                                    }
    
                                    else//they made it to the er table
                                    {
                                        isFound = true;
                                        patient.TimeEnteringER = Hospital.CurrentTime;
                                        table.AddPatient(patient);
                                        
                                    }
                                   
                                }//nothing prints after this
                               
                            }
                           
    
                        }
                       
    
    
                        stillWorking = false;
                        // TODO: Make certain ALL of the tables are free
                        // if any table is not free, set stillWorking to true
                        foreach (var table in tables)
                        {
                            if (!table.IsFree)// if a table is not free
                            {
                                stillWorking = true;
                            }
                        }
    
                        // set add 10 minutes to hospital time
                        Hospital.CurrentTime += 10;
                    }
    
                    // print parameters (num tables, duration, using priority queue)
                    // print time, total patients, max waiting, average waiting, expired patients
                    Console.WriteLine("Total Elapsed Time: {0,7}", Hospital.CurrentTime);
                    Console.WriteLine("Total patients:     {0,7}", maxPatients);
                    Console.WriteLine("Total Expired:      {0,7}", totalExpired);
                    Console.WriteLine("Longest Wait:       {0,7}", maxWait);
                    Console.WriteLine("Average Wait:       {0,7:N2}", (double)totalWait / maxPatients);
                    Console.WriteLine("Average Stay:       {0,7:N2}", (double)totalStay / maxPatients);
                    Console.WriteLine("Maximum waiting:    {0,7:N2}", maxWaitingInLine);
    
                    usePriority = true;
                
                } // end for
            } // end processPatients
        }
    }
  • codybiggs1
    New Member
    • Apr 2018
    • 2

    #2
    Got the stupid thing to print. but it ignores everything. Ran it in the debugger...and it just shoots for the console.writes. ..ignoring everything else

    Comment

    Working...