30 31 for(int j = 0; j<lines. size() - i -1; j++) 32 33 int templ = Integer. parseInt (lines . get (j ) ) ; 34 int temp2 = Integer. parseInt (...
This question has been answered
Question

Java Programming.

I want to solve the error and complete the assignment, following the instructions.


Instructions:

Screen Shot 2020-12-06 at 17.11.36.png

Primes1.txt ↓↓↓

( https://drive.google.com/file/d/1XZMTo2r25k29zLHFKzKiH3PAaix5PKU6/view?usp=sharing )


My codes, bubble.java ↓↓↓

( https://drive.google.com/file/d/1UW3tTpGYY30Ntmi2gFNVmkXcUtl3qX-d/view?usp=sharing )

Screen Shot 2020-12-06 at 17.10.11.png

Screen Shot 2020-12-06 at 17.08.41.png

Screen Shot 2020-12-06 at 17.08.50.png

Image transcriptions

Demo program to the instructor or upload the java file to Ecampus: Using file input, read in Primes 1.txt into an array. Sort it using a bubble sort. Print out the first 10 and last 10 numbers from the sorted array. Print out the time it took to perform the sort.

import java. io. BufferedReader; import java. io. File; 3 import java. io. FileNotFoundException; 4 import java. io. FileReader; 5 import java. io. IOException; 6 import java. util. List; 7 import java. util. ArrayList; 8 public class bubble 9 { Run | Debug 10 public static void main (String args) 11 12 List<String> lines = new ArrayList<String>() ; 13 try 14 15 File file = new File("C:myname\\Desktop\\COSC_1437\\Homeworks\\6\\primes1. txt"); 16 FileReader filereader = new FileReader(file); 17 BufferedReader bufReader = new BufferedReader (filereader); 18 String line = ""; 19 while((line = bufReader. readLine() ) !=null) 20 21 Lines . add ( line) ; 22 23 bufReader . close ( ) ; 24 25 catch (FileNotFoundException e) {} 26 catch ( 10Exception e) {} 27 int convert = 1000*1000; 28 long startT = System. nanoTime ( ) ; 29 for(int i =0; i <lines. size(); i++)

30 31 for(int j = 0; j<lines. size() - i -1; j++) 32 33 int templ = Integer. parseInt (lines . get (j ) ) ; 34 int temp2 = Integer. parseInt ( lines . get (j+1) ); 35 if ( temp1>temp2) 36 37 String temp3 = lines. get(j); 38 Lines. set (j, lines . get(j+1) ); 39 lines. set (j+1, temp3); 40 41 42 43 long endTime = System. nanoTime ( ) ; 44 Long timespend = endTime - startT; 45 System. out. print In( lines. get (0) ); 46 for (int z =0; z <10; z++) 47 48 System. out . print In( lines. get (z) ) ; 49 50 for(int h = lines. size()-10; h < lines. size(); h++) 51 52 System. out. print In( lines . get (h) ) ; 53 54 System. out. printf ("Time spend for buble sort: $.If nson", (double) timespend/convert); 55 56

Exception in thread "main" java. lang. IndexOutOfBoundsException: Index @ out of bounds for length 0 at java. base/jdk. internal. util. Preconditions. outOfBounds (Preconditions. java: 64) at java. base/jdk. internal. util. Preconditions. outOfBoundsCheckIndex (Preconditions. java:70) at java. base/jdk. internal. util. Preconditions. checkIndex (Preconditions. java: 248) at java. base/java. util. Objects. checkIndex(Objects. java:373) at java. base/java. util. ArrayList. get (ArrayList. java: 426) at bubble. main (bubble. java: 45)

Answered by Expert Tutors

nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ul

itur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio.

Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, d

sus ante, dapibus a molestie consequat, ultrices ac mag

ec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lect

Step-by-step explanation

ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facili

consectetur adipiscing elit. Nam lacinia pulvinar to


ec aliquet. Lorem ipsum dolor sitScreen Shot 2020-12-06 at 4.54.21 PM.png

trices ac magna. Fusce dui lectus, co
1 Attachment
Screen Shot 2020-12-06 at 4.54.21 PM.png
png
The student who asked this found it Helpful
Overall rating 100%
Get unstuck

442,185 students got unstuck by Course
Hero in the last week

step by step solutions

Our Expert Tutors provide step by step solutions to help you excel in your courses