| | |
i need help understanding how to sort
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2008
Posts: 16
Reputation:
Solved Threads: 0
i'm a realy newbie stil only been taking this course for a few months.
i have a problem with 2 things in the folowing codes and im gona ask ure help with them .
they are semi english since im in europe and these are codes the teachers used as an example and i dont really understand them tht wel .
the end item is some kind of lotto machine tht takes out numbers from the class "GlazenBol" aka glassbowl since tht is were we generate the numbers and shows them and then araanges them from low to hight with the exception of the 7th bal wich would be a joker .
and lastly my test version
what i dont understand is why my teacher uses "mijnBol.schepBal" in the println function to display numbers from the shepBal method in class galzenBol ? is he refering to GlazenBal first and then going to the method shepBal? can u please explain it better if possible?
secondly i tried to order them but i always get the error if i use any sort method and input schepBal or mijnBol.schepBal .
it says its not a variable wich i kind of understand but the method schepbal gives an int as result how would i go about making it a variable then or maybe put it in a list in order to sort them ?
sorry if this is asking to much if u have any sugestions it would be welcome .
i have a problem with 2 things in the folowing codes and im gona ask ure help with them .
they are semi english since im in europe and these are codes the teachers used as an example and i dont really understand them tht wel .
the end item is some kind of lotto machine tht takes out numbers from the class "GlazenBol" aka glassbowl since tht is were we generate the numbers and shows them and then araanges them from low to hight with the exception of the 7th bal wich would be a joker .
Java Syntax (Toggle Plain Text)
public class Bal { private int nummer; public Bal(int _nummer) { nummer = _nummer; } public int getNumber() { return nummer; } }
Java Syntax (Toggle Plain Text)
import java.util.*; public class GlazenBol { public GlazenBol() { ballen = new Vector<Bal>(); vulBol(); } private void vulBol() { for(int i=0; i<45; i++) { ballen.add(new Bal(i+1)); } } public int schepBal() { Collections.shuffle(ballen); int returnvalue = ballen.remove(0).getNumber(); return returnvalue; } }
and lastly my test version
Java Syntax (Toggle Plain Text)
import java.util.*; public class GlazenBolTest { private GlazenBol mijnBol; public GlazenBolTest() { mijnBol = new GlazenBol(); ToonTestResultaten(); } public void ToonTestResultaten() { System.out.println("\f"); for(int i=0;i<7;i++) { Collections.sort(mijnBol.schepBal); //System.out.println("ball nummer" + (i)); System.out.println(mijnBol.schepBal()); } } }
what i dont understand is why my teacher uses "mijnBol.schepBal" in the println function to display numbers from the shepBal method in class galzenBol ? is he refering to GlazenBal first and then going to the method shepBal? can u please explain it better if possible?
secondly i tried to order them but i always get the error if i use any sort method and input schepBal or mijnBol.schepBal .
it says its not a variable wich i kind of understand but the method schepbal gives an int as result how would i go about making it a variable then or maybe put it in a list in order to sort them ?
sorry if this is asking to much if u have any sugestions it would be welcome .
•
•
Join Date: Jan 2008
Posts: 3,827
Reputation:
Solved Threads: 501
•
•
•
•
hmmm .
ok ill keep looking i gues .
its just that the teacher kinda threw this at us lol and suposed to be done by monday .
but thanks ill just keep looking at tutorials online to see if i can find the answer .
http://java.sun.com/javase/6/docs/te...ons/index.html
and a Collections class that has shuffle and sort:
http://java.sun.com/javase/6/docs/ap...llections.html
Both of these functions take a List as a parameter. A Vector is a type of a List.
http://java.sun.com/javase/6/docs/ap...util/List.html
http://java.sun.com/javase/6/docs/ap...il/Vector.html
There is also a Collection interface:
http://java.sun.com/javase/6/docs/ap...ollection.html
•
•
•
•
what i dont understand is why my teacher uses "mijnBol.schepBal" in the println function to display numbers from the shepBal method in class galzenBol ? is he refering to GlazenBal first and then going to the method shepBal? can u please explain it better if possible?
•
•
•
•
private GlazenBol mijnBol;
•
•
•
•
System.out.println(mijnBol.schepBal());
mijnBol.schepBal () says "execute the schepBal function in the GlazenBol class on the mijnBol object."
•
•
•
•
ive come to the conclusion that maybe there is no way to use the return value of a method for creating an int variable
Java Syntax (Toggle Plain Text)
int returnvalue = ballen.remove(0).getNumber();
![]() |
Similar Threads
- Merge Sort (C++)
- Understanding arrays (C++)
- Merge sort not working (C++)
- Why SMS Speak here (Geeks' Lounge)
- Understanding whats best when hosting mp3s and video (Graphics and Multimedia)
- Is My Understanding of C++ OO features correct? (C++)
- help understanding "char" data type (C++)
- Shell Sort w/ fibonacci numbers...HELP!!! Due Friday (C++)
- Array Struct Sort Help!! Urgent! (C)
- Need help understanding what to do (C++)
Other Threads in the Java Forum
- Previous Thread: inorder traverse
- Next Thread: Sorting using merge sort and quicksort
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component database defaultmethod development dice dragging ebook eclipse error event exception formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide image infinite input integer intersect invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie numbers openjavafx parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads time tree windows






