Please enable JavaScript.
Coggle requires JavaScript to display documents.
2090 (890 Parental, 860 Abuse, 660 Malnutrition, 100 P +A, 100 P + M),…
-
try { // FileWriter fw = new FileWriter("input.in"); - creates a file named "input.in" in write mode
FileWriter fw = new FileWriter("input.in"); // PrintWriter pw = new PrintWriter(fw); - opens a PrintWriter object to write to the file
Random r = new Random(); // int sum = 0; - initialize variable to hold sum of numbers written to file
while (sum <= 10000000) { // int num = r.nextInt(10220); - generate random number between 0 and 10,220
-
-
} // once the total is 10,000,000, stops writing numbers
-
} catch (IOException e) { // System.out.println("Error writing to file"); - print error message if IOException occurs
-
-
try { // FileReader fr = new FileReader("input.in"); - create a FileReader object to read from "input.in" file
FileReader fr = new FileReader("input.in"); // Scanner sc = new Scanner(fr); - create a Scanner object to read from the file
Scanner sc = new Scanner(fr); // FileWriter fw = new FileWriter("results.out"); - create a FileWriter object in write mode to write results to "results.out" file
FileWriter fw = new FileWriter("results.out"); // PrintWriter pw = new PrintWriter(fw); - create a PrintWriter object to write to the file
PrintWriter pw = new PrintWriter(fw); // int sum = 0; - initialize variable to hold sum of numbers written to file
-
int count = 0; // int minimum = Integer.MAX_VALUE; - initialize variable to hold minimum number read from file
int minimum = Integer.MAX_VALUE; // int maximum = Integer.MIN_VALUE; - initialize variable to hold maximum number read from file
int maximum = Integer.MIN_VALUE; // while (sc.hasNextInt()) { - loop while there are still numbers in the file
while (sc.hasNextInt()) { // int num = sc.nextInt(); - read the next number from the file and store it in num variable
-
-
} // pw.printf("There were %,d contributions\n", count); - print the number of contributions to results file
pw.printf("There were %,d contributions\n", count); // pw.printf("The minimum contribution was $%d\n", minimum); - print the minimum contribution to results file
pw.printf("The minimum contribution was $%d\n", minimum); // pw.printf("The maximum contribution was $%,d\n", maximum); - print the maximum contribution to results file
pw.printf("The maximum contribution was $%,d\n", maximum); // pw.printf("The average contribution was $%,.2f\n", (double) sum / count); - print the average contribution to results file
pw.printf("The average contribution was $%,.2f\n", (double) sum / count); // pw.printf("The total of all contributions was $%,d", sum); - print the total of all contributions to results file
pw.printf("The total of all contributions was $%,d", sum); // pw.close(); - close the PrintWriter and FileWriter objects
-
try { // FileWriter fw = new FileWriter("input.in"); - creates a file named "input.in" in write mode
FileWriter fw = new FileWriter("input.in"); // PrintWriter pw = new PrintWriter(fw); - opens a PrintWriter object to write to the file
Random r = new Random(); // int sum = 0; - initialize variable to hold sum of numbers written to file
while (sum <= 10000000) { // int num = r.nextInt(10220); - generate random number between 0 and 10,220
-
-
} // once the total is 10,000,000, stops writing numbers
-
} catch (IOException e) { // System.out.println("Error writing to file"); - print error message if IOException occurs
-
-
try { // FileReader fr = new FileReader("input.in"); - create a FileReader object to read from "input.in" file
FileReader fr = new FileReader("input.in"); // Scanner sc = new Scanner(fr); - create a Scanner object to read from the file
Scanner sc = new Scanner(fr); // FileWriter fw = new FileWriter("results.out"); - create a FileWriter object in write mode to write results to "results.out" file
FileWriter fw = new FileWriter("results.out"); // PrintWriter pw = new PrintWriter(fw); - create a PrintWriter object to write to the file
PrintWriter pw = new PrintWriter(fw); // int sum = 0; - initialize variable to hold sum of numbers written to file
-
int count = 0; // int minimum = Integer.MAX_VALUE; - initialize variable to hold minimum number read from file
int minimum = Integer.MAX_VALUE; // int maximum = Integer.MIN_VALUE; - initialize variable to hold maximum number read from file
int maximum = Integer.MIN_VALUE; // while (sc.hasNextInt()) { - loop while there are still numbers in the file
while (sc.hasNextInt()) { // int num = sc.nextInt(); - read the next number from the file and store it in num variable
-
-
} // pw.printf("There were %,d contributions\n", count); - print the number of contributions to results file
pw.printf("There were %,d contributions\n", count); // pw.printf("The minimum contribution was $%d\n", minimum); - print the minimum contribution to results file
pw.printf("The minimum contribution was $%d\n", minimum); // pw.printf("The maximum contribution was $%,d\n", maximum); - print the maximum contribution to results file
pw.printf("The maximum contribution was $%,d\n", maximum); // pw.printf("The average contribution was $%,.2f\n", (double) sum / count); - print the average contribution to results file
pw.printf("The average contribution was $%,.2f\n", (double) sum / count); // pw.printf("The total of all contributions was $%,d", sum); - print the total of all contributions to results file
pw.printf("The total of all contributions was $%,d", sum); // pw.close(); - close the PrintWriter and FileWriter objects
-