In: Computer Science
/**
* @author
* @author
* CIS 36B
*/
//write your two import statements here
public class Review {
public static void main(String[] args) { //don't
forget IOException
File infile = new
File("scores.txt");
//declare scores array
//Use a for or while loop to
read in data from scores.txt to the array
//call method
//Use a for loop to write
data from array into extraCredit.txt
}
/**
* Write complete Javadoc comment
here
*/
//write your addExtraCredit method here
}
90
95
86
41
79
56
90
83
74
98
56
81
64
99
12
Scores with Extra Credit:
92
97
88
43
81
58
92
85
76
100
58
83
66
101
14
If you have any doubts, please give me comment...
/**
* @author
* @author CIS 36B
*/
// write your two import statements here
import java.io.*;
import java.util.*;
public class Review {
public static void main(String[] args) throws IOException{ // don't forget IOException
File infile = new File("scores.txt");
Scanner fileScnr =new Scanner(infile);
// declare scores array
int scores[] = new int[15];
// Use a for or while loop to read in data from scores.txt to the array
int n=0;
while(fileScnr.hasNextInt()){
scores[n] = fileScnr.nextInt();
n++;
}
fileScnr.close();
// call method
addExtraCredit(scores);
// Use a for loop to write data from array into extraCredit.txt
PrintWriter pw = new PrintWriter(new File("extraCredit.txt"));
for(int i=0; i<n; i++){
pw.println(scores[i]);
}
pw.close();
}
/**
* Write complete Javadoc comment here
*/
// write your addExtraCredit method here
public static void addExtraCredit(int scores[]){
for(int i=0; i<scores.length; i++){
scores[i] += 2;
}
}
}