Exercise 1
The first step is to read the file. Then I store the text from the file in a String called input. Then I loop the characters in input and output them line by line.
Exercise 2
The first step is to read the file. Then a declare an integer variable called line and initiate it with the value of zero. Then I loop the text in the file. As long as the text still has next line, the value of line will keep adding one. Until there is no line left, the system will output the value of the variable line.
Exercise 3
The first step is to read the file. Then I loop the text to figure out the number of lines in this file. Then I create an array called gradeArray to store the grade(int type) on each line by looping the whole text. Then the sum can be calculated by adding all the grades in gradeArray. The average is the sum divided by the numbers of grades which equal to the numbers of lines.
Exercise 4
I create a double loop here. The process will be comparing the first line in inputStream1 to all the lines in inputStream2, comparing the second line in inputStream2 to all the lines in inputStream2, and continue looping the following lines in inputStream1. If all characters in a line from inputStream1 are exactly the same as those of a line from inputStream2, the integer called same will add 1, otherwise, diff will add one.
Exercise5
As long as a line contains “=”, the “=” notation will be replaced by the “:” notation. As long as a line contains “&”, the “&” notation will be replaced by the a space.
Exercise 6
Conclusion
We should really benefit from the OOP function, internal call, external call that Java has. Just like exercise 6, it makes the program more efficient and well-organized.