
Patrick B. answered 07/08/21
Math and computer tutor/teacher
class StudentRec
{
protected String name;
protected int roll;
protected int admissionCategory;
protected String email;
protected int bloodType;
protected int technology;
protected int domicile;
protected float gpa;
public StudentRec( String nameStr, String emailStr)
{
name = new String(nameStr);
email = new String(emailStr);
roll=1;
admissionCategory=0;
bloodType=0;
technology=1;
domicile = 0;
gpa=0.00f;
}
public String GetName() { return(name); }
public int GetRoll() { return(roll); }
public int GetAdmissionCategory() { return(admissionCategory); }
public String GetEmail() { return(email); }
public int GetBloodType() { return(bloodType); }
public int GetTechnology() { return(technology); }
public int GetDomicile() { return(domicile); }
public float GetGPA() { return(gpa); }
public void SetRoll(int roll) { this.roll=roll; }
public void SetAdmissionCategory(int admissionCategory) { this.admissionCategory = admissionCategory; }
public void SetBloodType(int bloodType) { this.bloodType = bloodType; }
public void SetDomicile(int domicile) { this.domicile = domicile; }
public void SetGPA( float gpa) { this.gpa = gpa; }
public StudentRec( StudentRec studentRec)
{
name = new String(studentRec.name);
email = new String(studentRec.email);
roll=studentRec.roll;
admissionCategory=studentRec.admissionCategory;
bloodType=studentRec.bloodType;
technology=studentRec.technology;
domicile = studentRec.domicile;
gpa = studentRec.gpa;
}
public StudentRec( String studentRecBuffCSV)
{
String tokens[] = studentRecBuffCSV.split(",");
email = tokens[0];
name = tokens[1];
roll = Integer.parseInt(tokens[2]);
admissionCategory = Integer.parseInt(tokens[3]);
bloodType = Integer.parseInt(tokens[4]);
technology = Integer.parseInt(tokens[5]);
domicile = Integer.parseInt(tokens[6]);
gpa = Float.parseFloat(tokens[7]);
}
public String SerializeToCSV()
{
return (
new String(
email + "," +
name + "," +
roll + "," +
admissionCategory + "," +
bloodType + "," +
technology + "," +
domicile + "," +
gpa
)
);
}
}
class StudentRecDB
{
public static final int MAX_STUDENT_RECS =5000;
protected StudentRec studentRecs[];
protected int count;
public StudentRecDB()
{
studentRecs = new StudentRec[MAX_STUDENT_RECS];
count=0;
}
public int GetCount() { return(count); }
public int Push(StudentRec newStudentRec)
{
int iReturn=0;
if (count < MAX_STUDENT_RECS)
{
studentRecs[count++]=new StudentRec(newStudentRec);
}
else
{
iReturn = -1;
}
return iReturn;
}
public StudentRec IndexerGetAtIndex(int iIndexPos)
{
StudentRec studentRecReturn=null;
if (iIndexPos>=0 && iIndexPos < count)
{
studentRecReturn = new StudentRec(studentRecs[iIndexPos]);
}
return(studentRecReturn);
}
}
import java.io.*;
import java.util.Scanner;
class StudentInput
{
private BufferedReader bufferedReader;
private Scanner scanner;
public StudentInput()
{
scanner = new Scanner(System.in);
bufferedReader = null;
}
public StudentRec Input()
{
StudentRec studentRec;
String email;
String name;
float gpa;
System.out.print(" Please input student email :>");
email = scanner.nextLine();
System.out.print(" Please input student name in the format last;first \n"+
" EX. Smith;John \n"+
" ----:> ");
name = scanner.nextLine();
System.out.println("Please input student GPA");
gpa = scanner.nextFloat();
studentRec = new StudentRec(name,email);
studentRec.SetGPA(gpa);
//please continue here with the input of the remaining data field columns: roll,bloodtype,etc.
return(studentRec);
}
public int Read(StudentRecDB studentRecDB, String filename)
{
int iReturn=0;
String inbuff;
try
{
FileReader fileReader = new FileReader(filename);
bufferedReader = new BufferedReader(fileReader);
inbuff = bufferedReader.readLine();
int N = Integer.parseInt(inbuff);
for (int iLoop=0; iLoop<N; iLoop++)
{
inbuff = bufferedReader.readLine(); System.out.println(inbuff);
StudentRec curStudentRec = new StudentRec(inbuff);
studentRecDB.Push(curStudentRec);
}
if (N == studentRecDB.GetCount())
{
System.out.println( N + " records read from file ");
}
bufferedReader.close();
}
catch (Exception ex)
{
System.out.println(" IO Exception occurs ");
iReturn=-1;
}
return(iReturn);
}
}
import java.io.*;
class StudentOutput
{
public int Write(StudentRecDB studentRecDB, String filename)
{
int iReturn=0;
try
{
FileWriter fileWriter = new FileWriter(filename);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
int N = studentRecDB.GetCount();
String outbuff = " " + N + "\n";
bufferedWriter.write(outbuff);
for (int iLoop=0; iLoop<N; iLoop++)
{
StudentRec curStudentRec = studentRecDB.IndexerGetAtIndex(iLoop);
outbuff = curStudentRec.SerizlizeToCSV()+ "\n";
bufferedWriter.write(outbuff);
}
bufferedWriter.close();
}
catch (Exception ex)
{
System.out.println(" Exception occurs writing file");
iReturn=-1;
}
return(iReturn);
}
}