Quick Java Question

Man of Honour
Joined
15 Mar 2004
Posts
28,140
Location
Liverpool
How do I find the smallest float number (out of 4)?

I want to put this line:

Winning Time = public static float findMin(float TimeG, TimeW, TimeCP, TimeS);

Where:

Winning Time = the quickest race time
Time'X' = a character's individual race time.

I keep getting really weird errors though, and I can't figure out if it's anything to do with the the fact that I've either defined it wrong (it's not 'findMin' or I haven't defined it correctly above where this line sits? :confused:

Thanks for any help offered. :)
 
It's essentially to find the winner of the race - I have defined the distance each thing needs to cover, and it's speed (in other classes). I now call these to work out a time (just by using speed=distance/time => time=distance/speed). Then I'm trying to find the shortest one of these times.

Code:
import java.util.Scanner;
import java.util.*;

public class Creature {
    static Grasshopper z = new Grasshopper();
    static Worm z = new Worm();//etc etc
    static CP z = new CP();
    static Slug z = new Slug();
    
    //static Driver a = new Driver();//New instance of Driver.java class to be read from Creature.java (here)
    
    public double GD = z.fetchGD();
    public double WD = z.fetchWD(); //- will need these distances from creature to leaf and the two below
    public double CPD = z.fetchCPD();
    public double SD = z.fetchSD();
    
    public static int speedG = z.fetchspeedG();//creature's individual speeds and three below
    public static int speedW = z.fetchspeedW();
    public static int speedCP = z.fetchspeedCP();
    public static int speedS = z.fetchspeedS();
    
    public float TimeG;
    public float TimeW;
    public float TimeCP;
    public float TimeS;
    
    public float WinningTime ();
   
    public Creature() {
    }
    {float TimeG = (GD / speedG);
    }
    {float TimeW = (GW / speedW);
    }
    {float TimeCP = (GCP / speedCP);
    }
    {float TimeS = (GS / speedS);
    }
}    
    {float WinningTime = findMin( TimeG,  TimeW,  TimeCP, TimeS)
}
 
Back
Top Bottom