samedi 15 octobre 2016

My retrun Statments doesn't return

Here are my codes

CLASS

package work;

public class Run {

private int sec;
private int sec2;
private int sec3;
private double min;
private double min2;
private double min3;
private String n1;
private String n2;
private String n3;


public Run(int s, int ss, int sss, String n, String nn, String nnn){
    sec = s;
    sec2 = ss;
    sec3 = sss;
    n1 = n;
    n2 = nn;
    n3 = nnn;
    calcMin();
}


public void calcMin(){
    min = (double) sec/60;
    min2 = (double) sec2/60;
    min3 = (double) sec3/60;
}



public String getres(){
    String res = "";
    if(min>min2 && min>min3 && min2>min3){
        res = n1+n2+n3;
    }
    else if (min>min2 && min>min3 && min2<min3){
        res = n1+n3+n2;
    }
    else if (min2>min && min2>min3 && min>min3){

        res = n2+n1+n3;
    }
    return res;
}

}

MAIN

Scanner x = new Scanner(System.in);
System.out.println("n1");
String ni = x.next(); 
System.out.println("His time in s");
int s1 = x.nextInt();
System.out.println("n2");
String nii = x.next();
System.out.println("His time in s");
int s2 = x.nextInt();
System.out.println("n3");
String niii = x.next();
System.out.println("His time in s");
int s3 = x.nextInt();

Run gogo = new Run(s1, s2, s3, ni, nii, niii);

System.out.println(gogo.getres());

In the end, it doesn't show anything, it's blank. The problem asks the results in minutes of a race. Like in competition, the one with the lowest time has to be first and etc.. Then, it has to show the name of the first, the second and third according to their time. The problem is that after the main asks the question, it doesn't show anything. I know that advanced people would use array list, but I am not allowed to. I didn't put all the if-else-if statements, because it still doesn't work. Plz help me.

Aucun commentaire:

Enregistrer un commentaire