Sean 80 sean@csi.edu James 100 james@yahoo.com Issac 99 issac@mail.csi.edu Thoma
ID: 3609194 • Letter: S
Question
Sean 80 sean@csi.eduJames 100 james@yahoo.com
Issac 99 issac@mail.csi.edu
Thomas 88 tom@cix.csi.edu
Alice 78 alice@myclass.com
Jone 75 jone@hotmail.com
Zach 89 zach@yahoo.com
Mark 86 mark@gmail.com
Nick 79 nick@bmail.com
Amy 95 amy@hotmail.com
Claire 89 claire@yahoo.com
Eve 97 eve@nytimes.com From the above text file iam supposed to write a function toprint out the lowest record on screen but iam having trouble withhow to locate the lowest record? please help Sean 80 sean@csi.edu
James 100 james@yahoo.com
Issac 99 issac@mail.csi.edu
Thomas 88 tom@cix.csi.edu
Alice 78 alice@myclass.com
Jone 75 jone@hotmail.com
Zach 89 zach@yahoo.com
Mark 86 mark@gmail.com
Nick 79 nick@bmail.com
Amy 95 amy@hotmail.com
Claire 89 claire@yahoo.com
Eve 97 eve@nytimes.com From the above text file iam supposed to write a function toprint out the lowest record on screen but iam having trouble withhow to locate the lowest record? please help From the above text file iam supposed to write a function toprint out the lowest record on screen but iam having trouble withhow to locate the lowest record? please help
Explanation / Answer
//method assumes datais passed to the method in an array of Strings public void lowestRecord(String[] strings) { int min=Integer.MAX_VALUE; //min tocompare to int lowestIndex=-1; for(int a=0; a<strings.length; a++) { String[] temp = (strings[a]).split("\s); //splits a string where there is white space try //in case the data was enteredwrong... { int iTemp=Integer.parseInt(temp[1]); //parse the index where the integer should be if(min>iTemp) { min=iTemp; //compares if the just parsedinteger is smaller. If it is, then it is the new min lowestIndex=a; //stores the index of thestring with the lowest integer } } catch(ClassCastException e) {System.out.println("Data entered wrong: at " +a+ ": "+strings[a]);} //there isn't an integer inthe right spot catch(IndexOutOfBoundsException e) {System.out.println("Index out of Bounds: at "+a+ ": "+strings[a]);} //index out ofbounds } System.out.println(strings[lowestIndex]); // print out the string } //method assumes datais passed to the method in an array of Strings public void lowestRecord(String[] strings) { int min=Integer.MAX_VALUE; //min tocompare to int lowestIndex=-1; for(int a=0; a<strings.length; a++) { String[] temp = (strings[a]).split("\s); //splits a string where there is white space try //in case the data was enteredwrong... { int iTemp=Integer.parseInt(temp[1]); //parse the index where the integer should be if(min>iTemp) { min=iTemp; //compares if the just parsedinteger is smaller. If it is, then it is the new min lowestIndex=a; //stores the index of thestring with the lowest integer } } catch(ClassCastException e) {System.out.println("Data entered wrong: at " +a+ ": "+strings[a]);} //there isn't an integer inthe right spot catch(IndexOutOfBoundsException e) {System.out.println("Index out of Bounds: at "+a+ ": "+strings[a]);} //index out ofbounds } System.out.println(strings[lowestIndex]); // print out the string }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.