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

Group Assignment #2 We\'ve just covered inputs and Outputs. I want you, as a gro

ID: 3755162 • Letter: G

Question

Group Assignment #2 We've just covered inputs and Outputs. I want you, as a group, to demonstrate how these concepts work The Details You're teaching a class and you need a way to keep track of students. Wite a Java program to add students and take roll call. Student information includes their ID number, name and rank (freshman, senior, etc.). Your program should ask the user to input the student's information, and then write that information to a file If the teacher wants to take roll call, you should print out the information from the file onto one line per student Create three students in your class and take roll call. Your program must have: . A method for adding a student . A method for taking roll caw · Inputs from the user Outputs to a file and the user Error-free syntax When your group is finished, show me that it works. Tun in: This paper with ALL team member names A copy of your source code

Explanation / Answer

Program

import java.util.Scanner;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class FileStudentInfo {

   
    public static void main(String[] args) {
       
   Scanner input = new Scanner(System.in);
System.out.print("Enter number of students: ");

int n = input.nextInt();
String[] name = new String[n];
String[] rank = new String[n];
int[] id=new int[n];
for(int i = 0; i < n; i++)
{
System.out.print("Enter id of student: ");
id[i] = input.nextInt();
System.out.print("Enter name of student: ");
name[i] = input.next();
System.out.print("Enter rank of student (senior,freshmen etc):");
rank[i] = input.next();
System.out.println("");
}
System.out.println("      Student Details");
System.out.println("=====================");
System.out.println("ID Name Rank");
System.out.println("=====================");
for(int i = 0; i < n; i++)
{
System.out.println(id[i]+" "+name[i]+" "+rank[i]);  
}

DataOutputStream output=null;
    try {
        output = new DataOutputStream(new FileOutputStream("studentinfo.txt"));
       
       
        for (int i = 0; i <= n; i++) {
            output.writeInt(id[i]);
            output.writeBytes(name[i]);
            output.writeBytes(rank[i]);
        }
        output.flush();
        output.close();
    } catch (Exception e) {
        System.out.println(e.getMessage());
    } finally{
        try{
            output.close();
        }catch(Exception e){
            System.out.println(e.getMessage());
        }
    }
    }
   
    }