Project 2 statement
Please write this in JAVA.
Please read this entire statement carefully before you start doing
anything…
This project involves implementing a simple university personnel
management program. The program contains two different kinds of
objects: students and faculty. For each object, the program stores
relevant information such as university ID, name, etc. Different
information is stored depending on the type of the object. For
example, a student has a GPA, while a faculty has a title and
department (professor, mathematics).
For each of any class data member, your program must include the
getters and the setters, and each
class must include at least two constructors. The
goal of this Project is to demonstrate the use of inheritance,
abstract classes, abstract methods and method overriding.
Student class has:
Faculty class has:
Students in this college pay $236.45 per credit hour in addition to a $52 administrative fee. Your code should generate a tuition invoice ( a method within the class Student). Note that students get a 25% off total payment if their gpa is greater or equal to 3.85.
Both classes Faculty and Student inherit from the abstract class Person. The abstract class Person has what’s common to both Faculty and Student, and it is left to you (the programmer) to come out with an abstract method that you implement in your classes Faculty and Student.
Test your code with one array of size 100 of type Person (Or you may use an ArrayList object). The sample run below should give you a clear idea about how your code should run. The user’s entry is marked in bold so you can tell what your code should display to the screen and what the user enters.
Please note well that:
Welcome to my Personal Management Program
Choose one of the options:
Enter your selection: 2
Enter the student’s info:
Name of Student: Julia Alvarez
ID: ju1254
Gpa: 3.26
Credit hours: 7
Thanks!
Choose one of the options:
Enter your selection: 2
Enter the student’s info:
Name of Student: Matt Jones
ID: ma0258
Gpa: 2.78
Credit hours: 0
Thanks!
Enter your selection: a
Invalid entry- please try again
Enter your selection: 1
Enter the faculty’s info:
Name of the faculty: John Miller
ID: jo7894
Rank: Instructor
Sorry entered rank (Instructor) is invalid
Rank: Professor
Department: Engineering
Thanks!
Enter your selection: 3
Enter the student’s id: ju1254
Here is the tuition invoice for Julia Alvarez :
---------------------------------------------------------------------------
Julia Alvarez ju1254
Credit Hours:7 ($236.45/credit hour)
Fees: $52
Total payment: $1,707.15 ($0 discount applied)
---------------------------------------------------------------------------
Enter your selection: 3
Enter the student’s id: eri856
Sorry-student not found!
Enter your selection: 4
Enter the faculty’s id: jo8578
Sorry jo8578 doesn’t exist
Enter your selection: 4
Enter the faculty’s id: JO7894
Faculty found:
---------------------------------------------------------------------------
John Miller
Engineering Department, Professor
---------------------------------------------------------------------------
Enter your selection: 5
Goodbye!
// Person.java
public abstract class Person
{
private String ID;
private String name;
// default constructor
public Person()
{
ID = "";
name = "";
}
// parameterized constructor
public Person(String ID, String name)
{
this.ID = ID;
this.name= name;
}
// abstract method to display the details
public abstract void display();
// getters
public String getID()
{
return ID;
}
public String getName()
{
return name;
}
// setters
public void setID(String ID)
{
this.ID = ID;
}
public void setName(String name)
{
this.name = name;
}
}
//end of Person.java
// Faculty.java
public class Faculty extends Person
{
private String department;
private String rank;
// default constructor
public Faculty()
{
super();
department = "";
rank = "";
}
// parameterized constructor
public Faculty(String ID, String name, String
department, String rank)
{
super(ID,name);
this.department = department;
this.rank = rank;
}
// setters
public void setDepartment(String department)
{
this.department = department;
}
public void setRank(String rank)
{
this.rank = rank;
}
// getters
public String getDepartment()
{
return department;
}
public String getRank()
{
return rank;
}
// display the details of Faculty
public void display()
{
System.out.println("---------------------------------------------------------------------------");
System.out.println(getName());
System.out.println(department.substring(0,1).toUpperCase()+department.substring(1).toLowerCase()+
" Department, "
+rank.substring(0,1).toUpperCase()+rank.substring(1).toLowerCase());
System.out.println("---------------------------------------------------------------------------");
}
}
//end of Faculty.java
// Student.java
public class Student extends Person
{
private double gpa;
private int credit_hours;
// default constructor
public Student()
{
super();
gpa = 0;
credit_hours = 0;
}
// parameterized constructor
public Student(String ID, String name, double gpa, int
credit_hours)
{
super(ID, name);
this.gpa = gpa;
this.credit_hours =
credit_hours;
}
// setters
public void setGPA(double gpa)
{
this.gpa = gpa;
}
public void setCreditHours(int credit_hours)
{
this.credit_hours =
credit_hours;
}
// getters
public double getGPA()
{
return gpa;
}
public int getCreditHours()
{
return credit_hours;
}
// display the details of Student
public void display()
{
System.out.println("---------------------------------------------------------------------------");
System.out.println(getName()+"
"+getID());
System.out.println("Credit Hours:
"+credit_hours +" ($236.45/credit hour)");
System.out.println("Fees:
$52");
double discount =
getDiscount();
if(discount == 0)
System.out.printf("Total payment: $%,.2f ($0 discount
applied)\n",getTotalInvoice());
else
System.out.printf("Total payment: $%,.2f ($%,.2f discount
applied)\n",getTotalInvoice()-discount,discount);
System.out.println("---------------------------------------------------------------------------");
}
// helper method to calculate and return total
invoice
private double getTotalInvoice()
{
return((credit_hours*236.45)+52);
}
// helper method to return discount if any
private double getDiscount()
{
if(gpa >= 3.85)
return
0.25*getTotalInvoice();
else
return 0;
}
}
//end of Student.java
// PersonTester.java
import java.util.ArrayList;
import java.util.Scanner;
public class PersonTester {
public static void main(String[] args) {
// create an array list to store
Person objects
ArrayList<Person> personList
= new ArrayList<Person>();
System.out.println("Welcome to my
Personal Management Program");
Scanner keyboard = new
Scanner(System.in);
String ID, name, dept, rank;
int hours;
double gpa;
String choice;
System.out.println("Choose one of
the options: ");
// loop that continues until the
user exits
do
{
System.out.println("Add a new Faculty member");
System.out.println("Add a new Student");
System.out.println("Print tuition invoice for a student");
System.out.println("Print information of a faculty");
System.out.println("Exit Program");
// input of
choice
System.out.print("Enter your selection: ");
choice =
keyboard.nextLine();
if(choice.equals("1")) // insert faculty
{
System.out.println("Enter the faculty’s
info:");
System.out.print("Name of the faculty: ");
name = keyboard.nextLine();
System.out.print("ID: ");
ID = keyboard.nextLine();
System.out.print("Rank: ");
rank = keyboard.nextLine();
while(!(rank.equalsIgnoreCase("Professor") ||
rank.equalsIgnoreCase("Adjunct")))
{
System.out.println("Sorry
entered rank ("+rank+") is invalid");
System.out.print("Rank:
");
rank =
keyboard.nextLine();
}
System.out.print("Department: ");
dept = keyboard.nextLine();
while(!(dept.equalsIgnoreCase("Mathematics") ||
dept.equalsIgnoreCase("Physics") ||
dept.equalsIgnoreCase("Engineering")))
{
System.out.println("Sorry
entered department ("+dept+") is invalid");
System.out.print("Department:
");
dept =
keyboard.nextLine();
}
personList.add(new
Faculty(ID,name,dept,rank));
System.out.println("Thanks!");
}
else
if(choice.equals("2")) // insert student
{
System.out.println("Enter the student’s
info:");
System.out.print("Name of Student: ");
name = keyboard.nextLine();
System.out.print("ID: ");
ID = keyboard.nextLine();
System.out.print("Gpa: ");
gpa = keyboard.nextDouble();
while(gpa < 0)
{
System.out.println("Sorry
entered GPA ("+gpa+") is invalid");
System.out.print("Gpa:
");
gpa =
keyboard.nextDouble();
}
System.out.print("Credit hours: ");
hours = keyboard.nextInt();
while(hours < 0)
{
System.out.println("Sorry
entered Credit hours ("+hours+") is invalid");
System.out.print("Credit
hours: ");
hours =
keyboard.nextInt();
}
keyboard.nextLine();
personList.add(new
Student(ID,name,gpa,hours));
System.out.println("Thanks!");
}
else
if(choice.equals("3")) // display student info
{
System.out.print("Enter the student's id:
");
ID = keyboard.nextLine();
boolean flag = false;
for(Person person: personList)
{
if((person instanceof
Student) && (person.getID().equalsIgnoreCase(ID)))
{
flag =
true;
System.out.println("Here is the tuition invoice for
"+person.getName()+": ");
person.display();
break;
}
}
if(!flag)
System.out.println("Sorry-student not found!");
}
else
if(choice.equalsIgnoreCase("4")) // display faculty info
{
System.out.print("Enter the faculty's id:
");
ID = keyboard.nextLine();
boolean flag = false;
for(Person person: personList)
{
if((person instanceof
Faculty) && (person.getID().equalsIgnoreCase(ID)))
{
flag =
true;
System.out.println("Faculty found");
person.display();
break;
}
}
if(!flag)
System.out.println("Sorry
"+ID+" doesn't exist");
}
else
if(!choice.equalsIgnoreCase("5")) // invalid choice
{
System.out.println("Invalid entry- please try
again");
}
}while(!choice.equalsIgnoreCase("5"));
System.out.println("Goodbye!");
}
}
//end of PersonTester.java
Output:
Get Answers For Free
Most questions answered within 1 hours.