Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program #3: Work programming exercise 17.8, page 702, Update count, to develop a

ID: 3914959 • Letter: P

Question

Program #3: Work programming exercise 17.8, page 702, Update count, to develop a program to keep count how many times the program is executed. The count is stored in a file. Follow the problem statement specifications and develop a test program as specified. 17.8 (Update count) Suppose you wish to track how many times a program has been executed. You can store an int to count the file. Increase the count by 1 each time this program is executed. Let the program be Exercise17 08 and store the count in Exercise17 08.dat Please write this Java program as simple as possible and with comments throughout explaining what is happening. Thank you!

Explanation / Answer

Exercise17_08.java

import java.io.*;
import java.util.*;
public class Exercise17_08{

public static void main(String []args) throws IOException{
File file= new File("Exercise17_08.dat");
int count = 0;
if(file.exists()) {
Scanner scan = new Scanner(file);
count = scan.nextInt();
scan.close();
}
count++;
PrintWriter pw = new PrintWriter(file);
pw.write(count);
pw.flush();
pw.close();
System.out.println("File has been generated with the count "+count);   
}
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote