I am making a program that the user puts in their Class ID then enter the amount of Boxes sold. I am trying to get the computer in the end to tell me which of the ten classes had the most boxes. But I can't seem to figure out how to get the program to tell me which one of the ten had the most boxes. I think I need to find the biggest number in the array if that is even possible?
import java.util.*;
public class Boxs {
int ID, boxs;
public static void main(String[] args) {
int p = 0;
Scanner scan = new Scanner(System.in);
Boxs[] bx = new Boxs[10];
for (int i = 0; i <= 9; i++) {
bx[i] = new Boxs();
System.out.print("Enter Class ID: ");
bx[i].ID = scan.nextInt();
System.out.print("Enter boxs sold: ");
bx[i].boxs = scan.nextInt();
}
int temp = 0;
int temp2 = 0;
for (int j = 0; j < 9; j++) {
for (int h = 0; h < 9; h++) {
if (bx[h].boxs > bx[h+1].boxs) {
temp2 = bx[p].boxs;
bx[h].boxs = bx[p+1].boxs;
bx[p+1].boxs = temp;
temp = bx[h].ID;
bx[h].ID = bx[p+1].ID;
bx[h+1].ID = temp2;
System.out.println(bx[h].boxs);
System.out.println(bx[h+1].boxs);
}
}
}
System.out.println("The Class ID with the most boxes is: " + bx[0].ID + " and sold " + bx[0].boxs + " boxs.");
}
}