//JAVA PROGRAMMING project// Create a program that helps manage student informat
ID: 3708325 • Letter: #
Question
//JAVA PROGRAMMING project//
Create a program that helps manage student information. The program will keep track of 2 different students. It will use several concepts you have learned so far. It will read input files and output a different file that contains a combination of the two input files.
Program specs:
Use JOptionPane for user input.
Have a separate Student class that should contain information about the student.
Ask user for the filename to input. There are 2 files attached to the assignment. It will need to ask 1 time for each file.
The data in student1.txt should be read into the first student instance.
The data in student2.txt should be read into the second student instance.
The file in the data looks like this:
[Student Number]
[Student Name]
[Major]
[GPA]
Ask user for output filename. The output file should be in this format:
[Student Number],[Student Name],[Major],[GPA]
There should be 1 output line in the file for each student.
When finished, the program needs to inform the user that the process is complete.
--------------------------------------------
Below are the images of the contents of the files for the student information. Files are named "student1.txt" and "student2.txt"
-------------------------------------------
12345 Alvin Arnold Computer Information Systems 3.50 studentl.txtExplanation / Answer
/*************************************************Student.java*****************************************************/
/**
* The Class Student.
*/
public class Student {
/** The student number. */
private String studentNumber;
/** The student name. */
private String studentName;
/** The major. */
private String major;
/** The gpa. */
private double gpa;
/**
* Gets the student number.
*
* @return the student number
*/
public String getStudentNumber() {
return studentNumber;
}
/**
* Sets the student number.
*
* @param studentNumber the new student number
*/
public void setStudentNumber(String studentNumber) {
this.studentNumber = studentNumber;
}
/**
* Gets the student name.
*
* @return the student name
*/
public String getStudentName() {
return studentName;
}
/**
* Sets the student name.
*
* @param studentName the new student name
*/
public void setStudentName(String studentName) {
this.studentName = studentName;
}
/**
* Gets the major.
*
* @return the major
*/
public String getMajor() {
return major;
}
/**
* Sets the major.
*
* @param major the new major
*/
public void setMajor(String major) {
this.major = major;
}
/**
* Gets the gpa.
*
* @return the gpa
*/
public double getGpa() {
return gpa;
}
/**
* Sets the gpa.
*
* @param gpa the new gpa
*/
public void setGpa(double gpa) {
this.gpa = gpa;
}
}
/*******************************************StudentDriver.java*********************************************/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
* The Class StudentDriver.
*/
public class StudentDriver {
/** The students. */
private static List<Student> students = new ArrayList<>();
/**
* Read.
*
* @param fileName the file name
*/
public static void read(String fileName) {
FileReader fileReader = null;
BufferedReader bufferedReader = null;
try {
// FileReader reads text files in the default encoding.
fileReader = new FileReader(fileName);
// Always wrap FileReader in BufferedReader.
bufferedReader = new BufferedReader(fileReader);
String line;
StringBuilder sb = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
sb.append(line + ",");
}
line = sb.toString();
String[] datas = line.split(",");
// Student instance creation
Student st = new Student();
st.setStudentNumber(datas[0]);
st.setStudentName(datas[1]);
st.setMajor(datas[2]);
st.setGpa(Double.valueOf(datas[3]));
// save Student object into list
students.add(st);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fileReader != null) {
try {
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* Write.
*
* @param fileName the file name
* @param content the content
*/
public static void write(String fileName, String content) {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(fileName, true));
writer.append(content);
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
JFrame f = new JFrame();
int noOfStudnet = 2;
// Reading file content from file
while (noOfStudnet > 0) {
String fileName = JOptionPane.showInputDialog(f, "Please enter the file name. ");
read(fileName);
noOfStudnet--;
}
String outputFile = JOptionPane.showInputDialog(f, "Please enter the output file name. ");
// Writing into Output file
StringBuilder sb = new StringBuilder();
for (int i = 0; i < students.size(); i++) {
Student student = students.get(i);
sb.append(student.getStudentNumber() + ",");
sb.append(student.getStudentName() + ",");
sb.append(student.getMajor() + ",");
sb.append(student.getGpa() + " ");
}
write(outputFile, sb.toString());
System.exit(0);
}
}
/******************************************output*********************************************/
student1.txt
12345
Alvin Arnold
Computer Information Systems
3.50
student2.txt
54321
Robert Robertson
Computer Science
3.75
output.txt
12345,Alvin Arnold,Computer Information Systems,3.5
54321,Robert Robertson,Computer Science,3.75
Thanks a lot. Please let me know if you have any query. HIT LIKE
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.