My Java Programming HELP ME thread!

Aug 15, 2004
158
0
0
DISCLAIMER: First and formost, thank you guys for visiting my programming help thread! I'm a student at UCSB in Computer Engineering needing a little help from fellow noobies to veteren JAVA programmers.

I ask lots of questions on the forum regarding programming. Therefore I wanted to stop junking the forum and just make a long thread. I just want to make it clear that I'm not starting this thread in order to get you guys to do my homework. Instead, you will see more questions regarding which methods do what or if there is a method that already exists for my usage, and (hopefully) little debugging questions.

And, in comparison to my TA, ATers answer my questions so much faster than my TA. Plus I usually get multiple suggestions and methods.

So there's my little "disclaimer". Thanks all. If you feel so inclined to help me out keep reading...
*************************************************************************
*************************************************************************

02/15/05

I'm just having a problem understanding and using heaps.

Simulating a doctor's office, I have an ArrayList of Patients with each Patient holding their own set of values, one of which is an integer representing a given priority. I want to create a priority queue so that the patient with the highest priority level can be accessed and modified.

I do not understand how to initialize heaps or manage them in this situation. Any help would be great. Thanks!
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
I'm assuming the ArrayList has Strings? You can try the Integer parseInt() function.

int temp;
for (int j=0; j < list.size(); j++){
...try{
......temp = Integer.parseInt((String)list.get(j));
...}
...catch (NumberFormatException e){
......// item was not an integer
...}
}
 

ttown

Platinum Member
Oct 27, 2003
2,412
0
0
I think you might want isInteger(), which I believe is part of java.lang.String

edit: ...or what mrchad says...
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
Not directly answering your question, but one of the nicer new features in Java 5 is the inclusion of generics. Instead of a list of Objects, the list is like a C++ template - you decide the type. For example, you declare the list of ints, and at compile time all getters/setters/etc are typed to int. With autoboxing, the resulting code can be much cleaner, sans dangerous casting.

Also, when accessing Collections, try to use Iterators. Again, it's probably outside the scope of your current assignment.
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
Originally posted by: MrChad
I'm assuming the ArrayList has Strings? You can try the Integer parseInt() function.

int temp;
for (int j=0; j < list.size(); j++){
...try{
......temp = Integer.parseInt((String)list.get(j));
...}
...catch (NumberFormatException e){
......// item was not an integer
...}
}

The man with the answer speaks!

 
Aug 15, 2004
158
0
0
MrChad: I think it worked...must compile after finding all the other bugs. Thanks!

diegoalcatraz: We've implemented Java 5 into the class. But my professor said we wont be moving out of the scope of 1.3x i think. Sounds very interesting though.

Thanks for the quick replys guys! I wasn't sure if I would get any responses to my post.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: diegoalcatraz
Not directly answering your question, but one of the nicer new features in Java 5 is the inclusion of generics. Instead of a list of Objects, the list is like a C++ template - you decide the type. For example, you declare the list of ints, and at compile time all getters/setters/etc are typed to int. With autoboxing, the resulting code can be much cleaner, sans dangerous casting.

Also, when accessing Collections, try to use Iterators. Again, it's probably outside the scope of your current assignment.

Hmmm, I think autoboxing is what he really is looking for in the above example (not that generics aren't a great idea too), but what does autoboxing have to do with casts?

Iterators, yes, but you don't have to use them per se :
for (Object candidate : list) {
...if (candidate instanceof Integer) {
......doStuff((Integer) candidate);
...}
}
Where doStuff() can take an int argument
Or, using the generics (I'm just demoing for heylook, not lecturing you, diego):
List<Integer> list = getListSomehow();
for (Integer value : list) {
...doStuff(value);
}

I think java's becoming too syntactically complex for beginners. There's too much nuance to alot of what you can do with generics and autoboxing, although the implicit Iterator helps.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
bump and a placeholder. I'll get back to this sometime tomorrow...
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
I forgot about the implicit iterator =) I remember first learning about templates in C++, the syntax threw me for a loop, but it was easier to pick up the C# and Java concepts of generics after that. As for autoboxing, I just think it's a good idea (TM) - but I guess they'd apply more to creating the said list than to the checks the OP was conducting.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |