I cant figure this out and its bothering me. I have a assignment where i have to sort a bar but i am struggling with placing the bars in order. I can place it but it is either out of order or half of the bar is out of the world. I really need help with this. i need help with much more but this is the main thing bothering me. here is the code
import greenfoot.*; import java.awt.FileDialog; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author Marcus Jones * @version 12/4/22 */ public class MyWorld extends World { public static void swap(int inArray[], int index1, int index2) { int temp = inArray[index1]; inArray[index1] = inArray[index2]; inArray[index2] = temp; } public static int findMinIndex(int arr[], int fromIndex) { int minIndex = fromIndex; for(int searchIndex=fromIndex+1; searchIndex<arr.length; searchIndex++) { if (arr[searchIndex] < arr[minIndex]) minIndex=searchIndex; } return(minIndex); } public static void sort(int arr[]) { for (int targetIndex=0; targetIndex<arr.length; targetIndex++) { int minPos = findMinIndex(arr, targetIndex); swap(arr, minPos, targetIndex); } } /** * Constructor for objects of class MyWorld. * */ public MyWorld() { super(800, 600, 1); } public void act() { int delayCount = 0; if(Greenfoot.isKeyDown("l")) { prepare(); } if (Greenfoot.isKeyDown("N")) { } Boolean autoSort; if (Greenfoot.isKeyDown("s")) { autoSort = true;// Remember to automatically sort. //delayCount = 250/barArray.length; // Delay value should be as calculated. //sort(values); } } public void prepare() { /** * Took the fileDialog from Lab6 */ FileDialog fd = null; fd = new FileDialog(fd, "Title for the GUI", FileDialog.LOAD); fd.setVisible(true); String filename = fd.getFile(); //what String path = fd.getDirectory(); //where String fullName = path + filename; File myFile = new File(fullName); Scanner reader; // declare try // attempt the following code { reader = new Scanner(myFile); // attempt to assign } catch(FileNotFoundException e) // I know there might be a problem, I'm gonna catch it { System.out.println("User error on read file!"); System.out.println(e); return; } int size = (int) reader.nextInt(); int[] values = new int[size]; int x3 = 800; int x1 = 800/size; int y1 = 600; for(int index = 0; index < size; index++) { int value = reader.nextInt(); values[index] = value; int x2 = x1; x3 -= x2; int y = 600/size; int x = (int) values[index]; //SortingBar bar = new SortingBar(x, y); addObject(new SortingBar(x,y),x3,y1); } fd.dispose(); reader.close(); } }