import java.io.*;
import java.util.*;
/**
*
*
*/
public class CourInfo {
private
String tcm; // times that the course meets ea. week
private String dcn; //Department and course number
private String dcm; // The days class his held ea. week.
private int nc = 0; // number of courses
/** Creates a new instance of CourInfo */
public CourInfo() {
}
public CourInfo(String dn, String dm, String tm){
dcn = dn;
dcm = dm;
tcm = tm;
}
public void setDcn(String dn){
dcn = dn;
}
public void setDcm(String dm){
dcm = dm;
}
public void setTcm(String tm){
tcm = tm;
}
public String getDcn(){
return dcn;
}
public String getDcm(){
return dcm;
}
public String getTcm(){
return tcm;
}
public static void main(String[] args) {
BufferedReader is; // is = input stream
PrintWriter op; // op = output stream
String first;
String last;
String email;
String maj; // Students Major
String dows; // days of the week student is available
String dm; // The days class his held ea. week.
String dn; //Department and course number
String tm;
int ns; // # of students records to be used in increment
int nc; // # of course records to be used in increment
double gpa; // grade point average
int cc; // count for course increment
int sc; // count for student increment
int i;
int j;
int yog; // year of graduation
/*asks for user to enter the location for the file which
*the user wants to be read from.
*/
System.out.println("Enter location of the file:");
Scanner keyboard = new Scanner(System.in);
String ipFileName = keyboard.next();
try {
is = new
BufferedReader(new
FileReader((ipFileName)));
ns = Integer.parseInt(is.readLine()); StudentInfo [] students = new StudentInfo[ns]; for (i = 0; i < ns; i++){
last = is.readLine();
first = is.readLine();
email = is.readLine();
yog = Integer.parseInt(is.readLine());
maj = is.readLine();
gpa = Double.parseDouble(is.readLine());
nc = Integer.parseInt(is.readLine()); CourInfo[] courses = new CourInfo[nc];
for (j = 0; j < nc; j++){
dn = is.readLine(); //Department and course number
dm = is.readLine(); // The days class his held ea. week.
tm = is.readLine(); // times that the course meets ea. week
courses[j] = new CourInfo(dn, dm, tm); }
dows = is.readLine();
students[i] = new StudentInfo(first, last, email, yog, maj, gpa, nc, courses, dows);
}
is.close();
bubbSort(students);
System.out.println("Enter location of file you wish to output to:");
String opFileName = keyboard.next();
op = new
PrintWriter(new
FileOutputStream(opFileName));
for (i = 0; i < ns; i++){
for (j = 0; j < students[i].getNumCourses(); j++) op.println(students[i].getFirst());
op.println(students[i].getLast());
op.println(students[i].getEmail());
op.println(students[i].getYearOfGraduation());
op.println(students[i].getMajor());
op.println(students[i].getGradePointAverage());
op.println(students[i].getNumCourses()); op.println(students[i].getCourses(j).getDcn()); op.println(students[i].getCourses(j).getDcm()); op.println(students[i].getCourses(j).getTcm()); op.println(students[i].getDaysWeekAvail());
}
op.close();
}
catch (
FileNotFoundException e) {
System.out.println("File not found");
System.exit(0);
}
catch(
IOException e) {
System.out.println("Error reading from or writing to the file");
}
}
public static void bubbSort(StudentInfo[] s){
int index, indexOfSmallest, pass, i;
StudentInfo temp;
for (pass = 0; pass < s.length - 1; pass++)
{
for (index = 0; index < s.length - 1 - pass; index++)
if (s[index + 1].getGradePointAverage() > s[index].getGradePointAverage())
{
temp = s[index];
s[index] = s[index + 1];
s[index + 1] = temp;
}
}
}
}