I am working on a series java programs regarding the following classes - Person,
ID: 3687489 • Letter: I
Question
I am working on a series java programs regarding the following classes - Person, Student, UnderGradStudent, GradStudent, and NonDegreeStudent using inherit properties. I am using examples from my professor and I still am unable to compile without errors. This is the first phase of the problem presented:
I have to create a Person class with four instance variables: one each for the name, area, title, and yearsOfEmployment with appropriate constructors and accessor and mutator methods. The Student class will inherit parts from the Person class.
Additionally I need to have a method to check if two persons are the same. This method is to accept another person object as a parameter and check if the calling object and the parameter object both have the same name, area, title and yearsOfEmployment. If so, the method should return true, else it returns false.
I need to create a base class Student with the following attributes: Student ID (int), Student’s name (String), Student’s address (String), and letterGrade (char).
Additionally I need to create classes UnderGradStudent, GradStudent and NonDegreeStudent that inherit from Student. The GradStudent class definition needs to include a Person type as an instance variable. The child classes have the following additional properties listed below.
UnderGradStudent - major (String), year (freshman, sophomore, etc), exam1Score (double), exam2Score (double), and exam3Score (double).
GradStudent - department (String), advisor (Person), thesisGrade (char) and examScore (double)
NonDegreeStudent - creditHours (int), assignScore (double) and examScore (double).
Now I need to create constructor, accessor, mutator methods for all the above classes while creating all methods required to complete the student application as described below
Letter Grade for each student type is to be computed as follows:
UnderGradStudent: gpa is computed based on the following information
Graded activity
Maximum Score
Weight
Exam1Score
50
30%
Exam2Score
100
25%
Exam3Score
250
45%
TotalScore
LetterGrade
>=85
A
>=70
B
>=60
C
< 60
F
GradStudent:
ThesisGrade
ExamScore
LetterGrade
A
Does not matter
A
B
>= 90
A
B
>= 80
B
B
< 80
C
C
>=80
C
Graded activity
Maximum Score
Weight
Exam1Score
50
30%
Exam2Score
100
25%
Exam3Score
250
45%
Explanation / Answer
//Person.java
/* create a Person class with four instance variables: one each for the name, area, title, and yearsOfEmployment */
public class Person {
String name;
String area;
String title;
int yearsOfEmployment;
/*constructors and accessor and mutator methods.*/
public Person(String n, String a, String t, int y)
{
name=n;
area=a;
title=t;
yearsOfEmployment=y;
}
public String getName()
{
return name;
}
public String getTitle()
{
return title;
}
public String getArea()
{
return area;
}
public int getYearsOfEmployment()
{
return yearsOfEmployment;
}
/*
method to check if two persons are the same
*/
/* This method is to accept another person object as a parameter and check if the calling object
and the parameter object both have the same name, area, title and yearsOfEmployment. If so,
the method should return true, else it returns false. */
public boolean equals(Person P)
{
boolean ans=false;
if(name.equalsIgnoreCase(P.getName()) &&
area.equalsIgnoreCase(P.getArea()) &&
title.equalsIgnoreCase(P.getTitle())&&
yearsOfEmployment==P.getYearsOfEmployment())
{
ans=true;
}
return ans;
}
}
//Student.java
public class Student{
int studentID;
String studentName;
String address;
char letterGrade;
public Student(int ID,String name, String a, char grade)
{
studentID=ID;
studentName=name;
address=a;
letterGrade=grade;
}
public void BaseInfo()
{
System.out.println("Student ID: "+studentID);
System.out.println("Student name: "+studentName);
System.out.println("Student address: "+address);
}
}
//GradStudent.java
public class GradStudent extends Student{
String department;
Person advisor;
char thesisGrade;
double examScore;
public GradStudent(String d, Person p,char tgrade,double score,int ID, String name, String a, char g) {
super(ID, name, a, g);
department=d;
advisor=p;
thesisGrade=tgrade;
examScore=score;
}
public char getLetterGrade()
{
char g=' ';
if(thesisGrade=='A')
g='A';
else if(thesisGrade=='B' && examScore>=90)
g='A';
else if(thesisGrade=='B' && examScore>=80)
g='B';
else if(thesisGrade=='B' && examScore<80)
g='C';
else if(thesisGrade=='C' && examScore>=80)
g='C';
return g;
}
public void info()
{
this.BaseInfo();
System.out.println("Department: "+department);
System.out.println("Advisor: "+advisor);
System.out.println("thesis grade: "+thesisGrade);
System.out.println("Exam score: "+ examScore);
System.out.println("letter grade: "+getLetterGrade());
}
}
//UnderGradStudent.java
public class UnderGradStudent extends Student{
String major;
String year;
double exam1Score;
double exam2Score;
double exam3Score;
public UnderGradStudent(String m, String y, double s1, double s2, double s3,int ID, String name, String a, char grade) {
super(ID, name, a, grade);
major=m;
year=y;
exam1Score=s1;
exam2Score=s2;
exam3Score=s3;
}
public double getGPA()
{
double gpa=exam1Score*30/100+ exam2Score*25/100 +exam3Score*45/100;
return gpa;
}
public void info()
{
this.BaseInfo();
System.out.println("Major: "+major);
System.out.println("year: "+year);
System.out.println("GPA: "+getGPA());
}
}
//NonDegreeStudent.java
public class NonDegreeStudent extends Student {
int creditHours;
double assignScore;
double examScore;
public NonDegreeStudent(int hours, double assign, double s,int ID, String name, String a, char grade) {
super(ID, name, a, grade);
creditHours=hours;
assignScore=assign;
examScore=s;
}
public char getLetterGrade()
{
double totalScore=assignScore+examScore;
char g=' ';
if(totalScore>=85)
g='A';
else if(totalScore>=70)
g='B';
else if(totalScore>=60)
g='C';
else if(totalScore<60)
g='F';
return g;
}
public void info()
{
this.BaseInfo();
System.out.println("Credit Hours: "+creditHours);
System.out.println("Assignment score: "+assignScore);
System.out.println("Exam Score: "+examScore);
System.out.println("Letter Grade: "+getLetterGrade());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.