I need this written in Java WITHOUT GUI. 1. Collect student information and stor
ID: 3602871 • Letter: I
Question
I need this written in Java WITHOUT GUI.
1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow the user to edit student ID.
2. Collect Course information and store it in a separate data file. Each course is identified by an unique ID. The user should be able to view/edit an existing course information. User is not allowed to edit the key field such as Course ID.
3. Collect Enrollment information. Here you allow the user to enroll students to courses. You make sure that the user types valid student id and course ID. You display the student and course information in the window. You will have to store enrollment information in a separate binary file. This file may contain the course, student ID, Year and semester information.
4. Grade Management, such as Add grades, View Grades. You will allow the user to enter student ID, year, Semester, course ID, and the grade. The user should be above to view/edit the grades.
Explanation / Answer
public class Student {
private String fName;
private String mName;
private String lName;
private String UFID;
private String DOB;
private String month, day, year;
public Student() {
fName = "Anonymous";
mName = "";
lName = "Anonymous";
UFID = "xxxx-xxxx";
DOB = "MM/DD/YYYY";
}
public void setNames(String name) {
String[] nameSplit = name.split(" ");
fName = nameSplit[0];
lName = nameSplit[nameSplit.length - 1];
if (nameSplit[1] != lName) {
mName = nameSplit[1];
}
}
public void setUFID(String id) {
//Check that characters are integers (8 total)
int numbers = 0;
for(int i=0; i<4; i++) {
if (Character.isDigit(id.charAt(i)))
numbers++;
}
for(int i=5; i<9; i++) {
if (Character.isDigit(id.charAt(i)))
numbers++;
}
//Check that 9 char long, - in middle, and contains all numbers
char hyphen = id.charAt(4);
if (id.length() == 9 && hyphen == '-' && numbers == 8) {
UFID = id;
System.out.println("Valid");
}
else {
System.out.println("UFID is not valid. ");
}
}
//Set DOB
public void setDOB(String dob) {
//Check for valid date format
char[] dobChars = dob.toCharArray();
if (((dobChars[1] == '/') && (dobChars[3] == '/' || dobChars[4] == '/')) ||
((dobChars[2] == '/') && (dobChars[4] == '/' || dobChars[5] == '/'))) {
//Check for valid date
String[] dobSplit = dob.split("/");
month = dobSplit[0];
day = dobSplit[1];
year = dobSplit[2];
if (validate(month, day, year)) {
System.out.println("Valid date of birth.");
DOB = dob;
}
else {
System.out.println("Invalid date of birth.");
}
}
else {
System.out.println("Invalid date format.");
}
}
//Check if date is valid
public static boolean validate(String month, String day, String year) {
//convert year to #
int year_ = Integer.parseInt(year);
//valid day of month
if (day.equals("31") &&
(month.equals("4") || month.equals("6") || month.equals("9") ||
month.equals("11") || month.equals("04") || month.equals("06") ||
month.equals("09"))) {
return false; // only 1,3,5,7,8,10,12 has 31 days
}
//leap year
else if (month.equals("2")("02")) {
if((year_ % 4==0 && year_ % 100!=0) || (year_ % 400==0)){
if(day.equals("30") || day.equals("31")){
return false;
}
else{
return true;
}
}
else {
if(day.equals("29")||day.equals("30")||day.equals("31")){
return false;
}
else{
return true;
}
}
}
else{
return true;
}
}
public String getFullName() {
String fullName;
if (mName.matches("")) {
fullName = fName + " " + lName;
}
else {
fullName = fName + " " + mName + " " + lName;
}
return fullName;
}
public String getDOB() {
return DOB;
}
public String getUFID() {
return UFID;
}
public String toString() {
return "Name: " + lName + ", " + fName + " UFID: " + UFID + " D.O.B.: " + DOB;
}
}
import java.util.Scanner;
public class ReadStudentData {
public static void main(String[] args) throws Exception {
java.io.File file = new java.io.File("students.txt");
Scanner input = new Scanner(file);
Student[] students = new Student[2];
for(int i=0; i<2; i++) {
String name = input.nextLine();
students[i].setNames(name);
String ufid = input.next();
students[i].setUFID(ufid);
String dob = input.next();
students[i].setDOB(dob);
System.out.println(students[i].toString());
}
input.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.