Java Code: "Iterations & I/O" Pulling a file into Eclipse and using it -
with project learning how pull , outside file , use in our eclipse program. in outside file (wordpad) there needs 50 numbers (1-50, new number each line:1 return, 2 return, 3 return, etc.). these numbers have ask user pull in file (with input.txt input, output.txt output). ask user 5 names , average numbers each student. example user enters joe, jack, jill, james, , jake should output:
joe: 5.5 (average of 1-10) jack: 15.5 (average of 11-20) jill: 25.5 (average of 21-30) james: 35.5 (average of 31-40) jake: 45.5 (average of 41-50)
what guys think? advise or help?
import java.io.file; import java.io.filenotfoundexception; import java.io.printwriter; import java.util.scanner; public class lineio { public static void main(string[] args)throws filenotfoundexception{ scanner console = new scanner(system.in); system.out.print("enter input file name: "); string inputfilename = console.next(); system.out.print("output file: "); string outputfilename = console.next(); file inputfile = new file(inputfilename); scanner in = new scanner(inputfile); printwriter out = new printwriter(outputfilename); int linenumber = 1; int linenumber2 = 10; int linenumber3 = 20; int linenumber4 = 30; int linenumber5 = 40; // read input , write output system.out.println("enter name 5 names:"); string person1 = console.next(); string person2 = console.next(); string person3 = console.next(); string person4 = console.next(); string person5 = console.next(); while (in.hasnextline()) { string line = in.nextline(); system.out.println(person1 + " average score " + linenumber); system.out.println(person2 + " average score " + linenumber2); system.out.println(person3 + " average score " + linenumber3); system.out.println(person4 + " average score " + linenumber4); system.out.println(person5 + " average score " + linenumber5); out.println("/* " + linenumber + " */ " + line ); if (linenumber <= 9) linenumber++; else break; if (linenumber2 <= 19) linenumber2++; else break; if (linenumber3 <= 29) linenumber3++; else break; if (linenumber4 <= 39) linenumber4++; else break; if (linenumber5 <= 49) linenumber5++; break; } in.close(); out.close(); } }
can show me how average numbers successfully. can finish there. thank you.
Comments
Post a Comment