codes about the introduction of java 1

  • Open up a new Java project on Eclipse named Review and create a new class called Review.java.
  • Note that you may need to install Eclipse on your home computer first. See the tutorial here.
  • This activity should be complete individually.
    • If you get stuck, refer to the lesson video and the review notes below covering methods, File I/O and arrays
  • Copy and paste the below starter code into your file:

/**

* @author FILL IN YOUR NAME HERE

* CIS 36B, Activity 1.3
*/

//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

}

  • Next, create a new text file named scores.txt
    • Rick-click the project. Go to New->File.
    • Name your file scores.txt
    • Make sure the text file gets saved inside the overall project folder (Review), not in the src folder
  • Now, copy and paste the following data (exam scores) into your scores.txt file:

90
95
86
41
79
56
90
83
74
98
56
81
64
99
12

  • Your program must declare an array of integers, and populate the array with the contents of the file.
    • You may assume that the length of the array is known to be 15 elements.
  • Next, write a method called addExtraCredit:
    • The addExtraCredit method takes in one parameter – an array of integers
    • It adds 2 to each element in the array (hint: think for loop)
    • It returns nothing
  • Inside of main, call the addExtraCredit method, passing it the array of exam scores.
  • Next, write the contents of the array to a file named extraCredit.txt.
    • Use PrintWriter to write out to the file (see lesson notes above).
  • When you are finished, extraCredit.txt should contain the following:
    • Don’t forget the title!

Scores with Extra Credit:
92
97
88
43
81
58
92
85
76
100
58
83
66
101
14

  • Hint: Your program should include either 3 for loops or 2 for loops and a while loop.
  • If you get stuck, review today’s lesson notes.
  • When extraCredit.txt contains the above data, submit your program to Canvas.

http://deanzacollegecis.jenniferparrish.net/home/c…

And click the link for activity2.1 and 2.2