In: Computer Science
Using pseudocode, write the code that will perform the necessary file operations as described in the short scenario below:
“During registration at a college, student’s details will be captured by a staff member and written to a file called “studentDetails.dat”. The following student details will be captured: name, surname, studentNumber, registeredCourse. The staff member will be prompted for the student details. After every record added to the file, the staff member will be asked whether they would like to add another record. If they choose not to add another record, the program should end.”
Here i am providing the answer. Hope it helps. please give me a like. it helps me a lot.
Pseudocode
Main
read filename.
do
{
print prompt ”Enter student details.”
Read student details from user
Write student details to file
print prompt “whether to add another record(yes/no)”to know user choice
read user choice
}while(user choice is yes)
Endmain
Java code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileWriter;
public class Main
{
public static void main(String[] args) throws IOException {
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
String student_details;//all student details stored in single variable
String ch;
FileWriter fw=new FileWriter("studentDetails.dat");
do
{
System.out.println("Enter student name,surname,studentNumber,registeredCourse");
student_details = reader.readLine(); // Reading data using readLine
fw.write(student_details+"\n"); //write string details to file and move to next line
System.out.println("would like to add another record(yes/no)");
ch= reader.readLine(); //choice (yes/no) reading
}while(ch.equals("yes"));//loop continue until enter no
fw.close();
}
}
Thank you, please upvote.