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 .

public class Bal
{
    private int nummer;

   
    public Bal(int _nummer)
    {
        
        nummer = _nummer;
    }

    public int getNumber()
    {

        return nummer;
    }
}
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

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 .

Recommended Answers

All 4 Replies

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 .

there is no way to use the return value of a method for creating an int variable

That is not true.

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 .

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/technotes/guides/collections/index.html

and a Collections class that has shuffle and sort:
http://java.sun.com/javase/6/docs/api/java/util/Collections.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/api/java/util/List.html
http://java.sun.com/javase/6/docs/api/java/util/Vector.html

There is also a Collection interface:
http://java.sun.com/javase/6/docs/api/java/util/Collection.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:

int returnvalue = ballen.remove(0).getNumber();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.