Use this sample code: public class Bargraph { //start method public static void main…
- User
Use this sample code: public class Bargraph { //start method public static void main (String args[])throws IOException { //defining all my variables I will use int spaceNeed = 0; int spaceHave = 0; String newLine = ""; String line = ""; int firstIndex = 0; int done = 0; double barHeight = 0; int canvasHeight = 400; int maxPossible = 19000000; int currentStatePop = 0; int left = 0; //rand method define Random rand = new Random(); //Reads in the file and creates the scanner
File theData = new File("stateInfo (1).txt"); Scanner dataReader = new Scanner(theData); //gets user input and makes sure its "men" or "women" String userInput = SimpleIO.getString("Which do you prefer? women or men"); //loop till men or women is answered while (!(userInput.equals("men") || userInput.equals("women"))){ userInput = SimpleIO.getString("Which do you prefer? women or men"); userInput = userInput.toLowerCase(); } //goes to 3rd collumn if men if (userInput.equals("men")){ spaceNeed = 3; } //if women goes to 4th collumn else{ spaceNeed = 4; } //define canvas MyroCanvas canvas = new MyroCanvas("canvas", 800, 400); //skip first row dataReader.nextLine(); //reads each line while(dataReader.hasNext()){ line = (dataReader.nextLine()); //itterates through collumns for (int i = 0; i < line.length(); i++){ if (line.substring(i,i+1).equals(" ")){ spaceHave += 1; } if (spaceHave == spaceNeed){ if (done == 0){ firstIndex = i; done = 1; } } if (spaceHave == (spaceNeed + 1)){ if (done == 1){ //gets the targeted collumn newLine = line.substring(firstIndex + 1,i); done = 2; } } //skips if the targeted collumn and row string has no number in it if (newLine.equals("")){ continue; } } //converts string to integer currentStatePop = Integer.parseInt(newLine); //defines bar height barHeight = canvasHeight * ((double) currentStatePop / maxPossible); //makes bar MyroRectangle rectangle = new MyroRectangle(canvas, left, 400 - (int)barHeight, 16, (int) barHeight); rectangle.visible(); left += 16; Color rColor = new Color(rand.nextInt(255), rand.nextInt(255), rand.nextInt(255)); rectangle.setFillColor(rColor); rectangle.makeFilled(); spaceHave = 0; done = 0; } }} to graph 4 year and 2 year program applicants to admissions with respect to ACT and SAT scores with this csv file: Nonprofit,For-profit, 4-year,2-year,4-year,2-year
Number of applications (in thousands),4,444,16,76,18
90 percent or more accepted,2.3,9.0,10.1,29.1 75.0 to 89.9 percent accepted,14.2,10.3,8.3,31.1 50.0 to 74.9 percent accepted,37.6,26.0,68.7,27.1 25.0 to 49.9 percent accepted,25.6,54.8,12.8,12.6 10.0 to 24.9 percent accepted,12.9,0.0,,0.0 Less than 10 percent accepted,7.4,0.0,0.0,0.0
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.