i need help understanding how to sort

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 16
Reputation: Sereal_Killer is an unknown quantity at this point 
Solved Threads: 0
Sereal_Killer Sereal_Killer is offline Offline
Newbie Poster

i need help understanding how to sort

 
0
  #1
Nov 29th, 2008
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 .

  1. public class Bal
  2. {
  3. private int nummer;
  4.  
  5.  
  6. public Bal(int _nummer)
  7. {
  8.  
  9. nummer = _nummer;
  10. }
  11.  
  12. public int getNumber()
  13. {
  14.  
  15. return nummer;
  16. }
  17. }

  1. import java.util.*;
  2.  
  3. public class GlazenBol
  4. {
  5.  
  6. public GlazenBol()
  7. {
  8.  
  9. ballen = new Vector<Bal>();
  10. vulBol();
  11. }
  12.  
  13. private void vulBol()
  14. {
  15. for(int i=0; i<45; i++)
  16. {
  17. ballen.add(new Bal(i+1));
  18. }
  19. }
  20.  
  21. public int schepBal()
  22. {
  23. Collections.shuffle(ballen);
  24. int returnvalue = ballen.remove(0).getNumber();
  25. return returnvalue;
  26. }
  27. }

and lastly my test version

  1. import java.util.*;
  2.  
  3. public class GlazenBolTest
  4. {
  5. private GlazenBol mijnBol;
  6.  
  7. public GlazenBolTest()
  8. {
  9.  
  10. mijnBol = new GlazenBol();
  11.  
  12. ToonTestResultaten();
  13. }
  14.  
  15. public void ToonTestResultaten()
  16. {
  17.  
  18.  
  19. System.out.println("\f");
  20. for(int i=0;i<7;i++)
  21. {
  22.  
  23.  
  24. Collections.sort(mijnBol.schepBal);
  25.  
  26. //System.out.println("ball nummer" + (i));
  27. System.out.println(mijnBol.schepBal());
  28.  
  29.  
  30.  
  31. }
  32.  
  33. }
  34.  
  35. }

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 .
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 16
Reputation: Sereal_Killer is an unknown quantity at this point 
Solved Threads: 0
Sereal_Killer Sereal_Killer is offline Offline
Newbie Poster

Re: i need help understanding how to sort

 
0
  #2
Nov 29th, 2008
Ok ive come to the conclusion that maybe there is no way to use the return value of a method for creating an int variable cause i wnated to use the return value from schepbal and sort it directly .
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,598
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: i need help understanding how to sort

 
0
  #3
Nov 29th, 2008
Originally Posted by Sereal_Killer View Post
there is no way to use the return value of a method for creating an int variable
That is not true.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 16
Reputation: Sereal_Killer is an unknown quantity at this point 
Solved Threads: 0
Sereal_Killer Sereal_Killer is offline Offline
Newbie Poster

Re: i need help understanding how to sort

 
0
  #4
Nov 30th, 2008
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 .
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,821
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: i need help understanding how to sort

 
0
  #5
Nov 30th, 2008
Originally Posted by Sereal_Killer View Post
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 .
Here are the documentation pages for some of what you are using. There is a Collections framework:
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 is an object of type GlazenBol. schepBal is a function/method in the GlazenBol class.

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
You are doing that here:
  1. int returnvalue = ballen.remove(0).getNumber();
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC