Quantcast
Channel: VBForums - Java
Viewing all articles
Browse latest Browse all 54

Java problem.

$
0
0
this is my project for my java..

so i want to display the 1st second and 3rd placers for the best time..
my problem is i only showed the 1st place which is john and 2nd which is kate and third that should be "Thomas".. could you revise my program..
this is a simple prog for you


this is the class utility

package Nov25;

public class Util {
private int index;
private int indexa;
private int indexaaa;
private int[] times;

public void setTimes(int[] times){
this.times = times;
}

public int getTimes(){
findBest();
return index;

}

public int getTimesa(){
findBest();
return indexa;

}

public int getTimesaa(){
findBest();
return indexaaa;

}

private void findBest(){
int low = times[0];

for(int counter=0;counter<times.length;counter++)
{
if(times[counter]<low)
{
low = times[counter];
index = counter;
{
int second = times[counter];

for(int x=index;x<times.length;x++)
{
if(times[x]<times[counter])
{
second = times[x];
indexa = x;
{
int third = times[x];
for(int y=x;y<times.length;y++)
{
if(times[y]<x)
{
third = times[y];
indexaaa = y;
}
}

}
}
}
}
}
}
}
}
-----------------------------------------------------

and this is the class runner:

package Nov25;

public class Runner {
public static void main(String[] args){

String[] names = {"Elena", "Thomas", "Hamilton", "Suzie", "Phil", "Matt", "Alex", "Emma",
"John", "James", "Jane", "Emily", "Daniel", "Neda", "Aaron", "Kate"};

int[] times = {341, 273, 278, 329, 445, 402, 338, 275, 243, 334, 412, 393, 299, 343, 317,
265};

Util util = new Util();
util.setTimes(times);

int index = util.getTimes();
int indexa = util.getTimesa();
int indexaaa = util.getTimesaa();


System.out.println("1st place : " + names[index]);
System.out.println("time: " + times[index]);

System.out.println("2nd place : " + names[indexa]);
System.out.println("time: " + times[indexa]);

System.out.println("3rd place : " + names[indexaaa]);
System.out.println("time: " + times[indexaaa]);


}
}

Viewing all articles
Browse latest Browse all 54

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>