Stephenfrazier10's Profile
Reputation: 2
Apprentice
- Group:
- Active Members
- Active Posts:
- 56 (0.22 per day)
- Joined:
- 12-September 12
- Profile Views:
- 266
- Last Active:
Apr 23 2013 07:51 PM- Currently:
- Offline
Previous Fields
- Country:
- US
- OS Preference:
- Windows
- Favorite Browser:
- FireFox
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- XBox
- Your Car:
- Ford
- Dream Kudos:
- 0
Latest Visitors
-
macosxnerd101 
21 Mar 2013 - 16:45 -
Atli 
12 Dec 2012 - 02:27
Posts I've Made
-
In Topic: How to Implement a Priority Queue without actually using one?
Posted 23 Apr 2013
That compiles, but when I go to run it, I just get an error now.
java.lang.ArrayIndexOutOfBoundsException: -1 at ERQueue.enqueue(ERQueue.java:94) at Tester.main(Tester.java:26)
-
In Topic: How to Implement a Priority Queue without actually using one?
Posted 23 Apr 2013
I did not take out the "this" in there but I did change what you said.
/** * Adds a new Patient to the Queue, based on their level of emeregency * @param newPat The new Patient that is being added to the Queue */ public void enqueue (Patient newPat) { if(isEmpty()) // For the very first Patient being added { this.Patients[0] = newPat; } else { int place = 0; for(int i = 0; i < this.size(); i++) { if(this.Patients[place] != null) // If there is something there { if(newPat.getEmeregencyLevel() >= this.Patients[place].getEmeregencyLevel()) { place++; } } } for(int j = place; j < this.numPatients; j++) // Move everything over 1, so new Patient can be added { this.Patients[j + 1] = this.Patients[j]; } this.Patients[place] = newPat; } this.numPatients++; this.rear = (this.rear + 1) % CAPACITY; } -
In Topic: How to Implement a Priority Queue without actually using one?
Posted 23 Apr 2013
That makes sense. But now when I test it, it does print out ten Patients like it is supposed to but it prints out the two level ones at the top, which is good. But then it prints out the first level 2 eight times after that. I wrote the testing program to read in 10 random Patients, 2 of each level, and create Patients. I do not know if the problem is in the testing method, which I don't see as possible, or still somewhere within the enqueue method.
This is my testing method.
public class Tester { public static void main() { Scanner infile = null; try { infile = new Scanner(new File("patients.txt")); } catch (FileNotFoundException e){} ERQueue myList = new ERQueue(); while (infile.hasNext()) { String patName = infile.next(); int severetyNum = infile.nextInt(); String sickness = infile.next(); Patient newPat = new Patient(patName, severetyNum, sickness); System.out.println(newPat); myList.enqueue(newPat); } System.out.println("________________________________________________________________________________"); System.out.println("CORRECTLY ORDERED"); System.out.println("________________________________________________________________________________ \n"); for(int i = 0; i < 10; i++) // All 10 Patients { System.out.println(myList.dequeue()); } } } -
In Topic: How to Implement a Priority Queue without actually using one?
Posted 23 Apr 2013
Do you know why this method is not working? I have traced it by hand and it seems to work everytime, but when I test it with 10 Patients, it prints out 5 of them in order.
public void enqueue (Patient newPat) { if(isEmpty()) // For the ery first Patient being added { this.Patients[0] = newPat; } else { int place = 0; for(int i = 0; i < this.size(); i++) { if(this.Patients[place] != null) // If there is something there { if(newPat.getEmeregencyLevel() >= this.Patients[place].getEmeregencyLevel()) { place++; } } } for(int j = place; j < this.numPatients; j++) // Move everything over 1, so new Patient can be added { this.Patients[j] = this.Patients[j + 1]; } this.Patients[place] = newPat; } this.numPatients++; this.rear = (this.rear + 1) % CAPACITY; } -
In Topic: How to Implement a Priority Queue without actually using one?
Posted 23 Apr 2013
My Information
- Member Title:
- D.I.C Head
- Age:
- 19 years old
- Birthday:
- January 21, 1994
- Gender:
-
- Location:
- VA
- Interests:
- MMA, Politics, Computer Science, gaming
- Full Name:
- Stephen Frazier
- Years Programming:
- 2
- Programming Languages:
- Python, Java, HTML, C++
Contact Information
- E-mail:
- Click here to e-mail me
- MSN:
-
stephenfrazier@go.rmc.edu
- Yahoo:
-
stephenfrazier10@yahoo.com
Friends
Stephenfrazier10 hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
Stephenfrazier10 has no profile comments yet. Why not say hello?