Based on the code below, please make a Javadocs(not generated by eclipse) that w
ID: 3822641 • Letter: B
Question
Based on the code below, please make a Javadocs(not generated by eclipse) that will describe each field and method of a class, its diffrent from pseudo code, it should be a list that's written into a word document and numbered. each method, attribute, etc should have a discription underneath it and labled by number, not comments in the code.
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
class WriteToFile{
/*Static method to write data to file from Array */
static void writeArray(String filename,int[] array) {
FileWriter fw = null;
BufferedWriter bw = null;
try {
fw = new FileWriter(filename);
bw = new BufferedWriter(fw);
bw.write(Arrays.toString(array));
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bw != null)
bw.close();
if (fw != null)
fw.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
/*Static method to read data from file.
if want to add data to array, import JSON library and uncomment the commented code . */
static void readArray(String filename,int[] array) {
try {
BufferedReader br = new BufferedReader(new FileReader(filename));
String Line;
while ((Line = br.readLine()) != null) {
System.out.println(Line);
}
/* JSONArray jsonArray = (JSONArray) new JSONObject(new JSONTokener("{data:"+Line+"}")).get("data");
for(int i=0; i<jsonArray.length(); i++) {
array[i] = jsonArray.getInt(i);
}
System.out.println(Arrays.toString(array));
*/
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String file = new String("try.txt");
int[] array = new int[] {11,22,33,44,55};
int[] array2 = new int[6];
writeArray(file,array);
readArray(file,array2);
}
}
Explanation / Answer
Documentation:-
WriteToFile class :
1) static void writeArray(String filename,int[] array)
- This method is a static method of return type void. It does not return any value to the calling function.
- It has two parameters:
· filename – This parameter is of type string.
· array – This is an array of integer type.
- this method is used to write data to file from Array
2) static void readArray(String filename,int[] array)
- This method is a static method of return type void. It does not return any value to the calling function.
- It has two parameters:
· filename – This parameter is of type string.
· array – This is an array of integer type.
- This method is employed to read data from file
- String Line : This variable is used to store the file data line by line.
3) public static void main(String[] args)
- Main method of the class. The program execution starts here.
- This method calls the following methods and passes arguments to perform the necessary operations.
writeArray(file,array)
readArray(file,array2)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.