Welcome to my Personal Management Program Enter the student's info: Choose one of the options: Name of Student: Matt Jones 1- Add a new Faculty member ID: ma0258 2- Add a new Student 3- Print tuition invoice for a student 4- Print information of a faculty 5- Exit Program Gpa: 2.78 Credit hours: 0 Thanks! Enter your selection: 2 1- Add a new Faculty member 2- Add a new Student 3- Print tuition invoice for a student 4- Print information of a faculty 5- Exit Program Enter the student's info: Name of Student: Julia Alvarez ID: jul254 Enter your selection: a Gpa: 3.26 Invalid entry- please try again Credit hours: 7 1- Add a new Faculty member 2- Add a new Student 3- Print tuition invoice for a student 4- Print information of a faculty 5- Exit Program Thanks! Choose one of the options: 1. Add a new Faculty member 2. Add a new Student 3. Print tuition invoice for a student 4. Print information of a faculty 5. Exit Program Enter your selection: 1 Enter the faculty's info: Name of the faculty: John Miller Enter your selection: 2 ID: jo7894 Rank: Instructor Sorry entered rank (Instructor) is invalid Rank: Professor 5- Exit Program Department: Engineering Enter your selection: 3 Thanks! Enter the student's id: eri856 1- Add a new Faculty member 2- Add a new Student 3- Print tuition invoice for a student 4- Print information of a faculty 5- Exit Program Sorry-student not found! 1- Add a new Faculty member 2- Add a 3- Print tuition invoice for a student 4- Print information of a faculty 5- Exit Program new Student Enter your selection: 3 Enter the student's id: jul254 Here is the tuition invoice for Julia Alvarez : Enter your selection: 4 Enter the faculty's id: jo8578 Sorry jo8578 doesn't exist Julia Alvarez jul254 1- Add a new Faculty member 2- Add a new Student 3- Print tuition invoice for a student 4- Print information of a faculty 5- Exit Program Credit Hours:7 ($236.45/credit hour) Fees: $52 Total payment: $1,707.15 ($0 discount applied) Enter your selection: 4 Enter the faculty's id: JO7894 Faculty found: 1- Add a new Faculty member 2- Add a new Student 3- Print tuition invoice for a student 4- Print information of a faculty John Miller
Results are not the same at the end and I do not get the right result after choosing number 3. The images below is how it should look like going from entering first student to printing information of a faculty. Here's part of my code :
class UniversityPersonnelManagement {
public static void main(String[] args) {
//create list to store Student objects
ArrayList<Student> studentList = new ArrayList<Student>();
//create list to store Faculty objects
ArrayList<Faculty> facultyList = new ArrayList<Faculty>();
System.out.println("Welcome to my Personal Management Program");
for (;;) {
int input = 0;
System.out.println(" Choose one of the options:");
System.out.println("1- Add a new Faculty member");
System.out.println("2- Add a new Student");
System.out.println("3- Print tuition invoice for a student");
System.out.println("4- Print information of a faculty");
System.out.println("5- Exit Program");
System.out.print("\n Enter your selection: ");
Scanner s = new Scanner(System.in);
try {
input = s.nextInt();
s.nextLine();
} catch (Exception e) {
System.out.println("Invalid entry- please try again");
}
if (input == 1) {
Faculty f = new Faculty();
System.out.println("\tEnter the faculty’s info:");
System.out.print("\tName of the faculty:");
f.fullName = s.next();
System.out.print("\tID:");
f.ID = s.nextLine();
// s.nextLine();
for (;;) {
String rank;
System.out.print("\tRank:");
rank = s.next();
if (rank.equalsIgnoreCase("professor") || rank.equalsIgnoreCase("adjunct")) {
f.Rank = rank;
break;
} else {
System.out.print("\tSorry entered rank (" + rank + ") is invalid");
}
}
for (;;) {
String department;
System.out.print("Department:");
//read the complete line
department = s.nextLine();
if (department.equalsIgnoreCase("mathematics") || department.equalsIgnoreCase("engineering")
|| department.equalsIgnoreCase("arts") || department.equalsIgnoreCase("science")) {
f.Department = department;
break;
} else {
System.out.print("Sorry entered department (" + department + ") is invalid");
}
}
System.out.println("Thanks!");
facultyList.add(f);
}
if (input == 2) {
Student st = new Student();
System.out.println("\tEnter the student’s info:");
System.out.print("\tName of Student:");
st.fullName = s.nextLine();
System.out.print("\tID:");
st.ID = s.nextLine();
System.out.print("\tGpa:");
st.Gpa = s.nextDouble();
System.out.print("\tCredit hours:");
st.numberOfCreditHoursCurrentlyTaken = s.nextInt();
System.out.println("\tThanks!");
studentList.add(st);
}
//display the tution invoice of student
if (input == 3) {
System.out.print("\tEnter the student’s id:");
String id = s.next();
//move the cursor to next line
s.nextLine();
Student stnt = new Student();
//iterate the student list till end of list
Iterator<Student> si = studentList.iterator();
//flag to keep track of if student found
boolean studentFound = false;
while (si.hasNext()) {
stnt = si.next();
//if id already there
//for comparing string if both are equal or not
//use equals method
if (stnt.ID .equals(id)) {
//display the details of student
stnt.generateTuituonInvoice(stnt);
//student exist set flag to true
studentFound = true;
break;
}
}
//if student with given id not found
if (!studentFound) {
System.out.print("Sorry-student not found!\n");
}
}
if (input == 4) {
System.out.print("Enter the faculty’s id: ");
String id = s.next();
//read the left \n character
s.nextLine();
Faculty ft = new Faculty();
Iterator<Faculty> si = facultyList.iterator();
while (si.hasNext()) {
ft = si.next();
if (ft.ID == id) {
break;
}
}
if (ft.fullName == null) {
System.out.print("Sorry-Faculty not found!");
} else {
System.out.println("Faculty found:");
System.out.println("--------------------------------------------------");
System.out.println(ft.fullName);
System.out.println(ft.Department + " Department, " + ft.Rank);
System.out.println("--------------------------------------------------");
}
}
if (input == 5) {
break;
}
}
}
}
class Faculty extends Person{
public String Department;
public String Rank;
public void add() {
// TODO Auto-generated method stub
}
public String getDepartment() {
return Department;
}
public void setDepartment(String department) {
Department = department;
}
public String getRank() {
return Rank;
}
public void setRank(String rank) {
Rank = rank;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images