Please help me solve this, it's computer science Java language I solved the first one only answer number 7&8 Write the c
Posted: Sat May 14, 2022 6:39 pm
Please help me solve this, it's computer science Java
language
I solved the first one only answer number
7&8
Write the complete Person, Student and Faculty classes (only
include what is asked)
using super.
class Person {
private String
name;
public Person(String n)
{
name =
n;
}
public String getName()
{
return
name;
}
public String toString()
{
return "Name:
'" + name ;
}
}
class Student extends Person{
private double gpa;
public Student(String n, double g)
{
super(n);
gpa =
g;
}
public double getGpa() {
return
gpa;
}
public String toString()
{
return
super.toString()+" GPA:" + gpa ;
}
}
class Faculty extends Person{
private double salary;
public Faculty(String n, double s)
{
super(name);
salary =
s;
}
public double getSalary()
{
return
salary;
}
Q7: data.txt is a text file contains info about whether a person is a student or faculty, their name and either their salary if they are faculty or their gpa if they are students e.g. student salem 3.4 student mariam 2.9 faculty ali 1450.5 student jassem 3.7 faculty ahmed 2150 etc... Write code to do the following => First make an ArrayList of Person called auk Next, read the text file, create the objects (either Faculty or Student) and add them to auk Q8: Using the auk ArrayList from Q7, work out the average gpa of students.
language
I solved the first one only answer number
7&8
Write the complete Person, Student and Faculty classes (only
include what is asked)
using super.
class Person {
private String
name;
public Person(String n)
{
name =
n;
}
public String getName()
{
return
name;
}
public String toString()
{
return "Name:
'" + name ;
}
}
class Student extends Person{
private double gpa;
public Student(String n, double g)
{
super(n);
gpa =
g;
}
public double getGpa() {
return
gpa;
}
public String toString()
{
return
super.toString()+" GPA:" + gpa ;
}
}
class Faculty extends Person{
private double salary;
public Faculty(String n, double s)
{
super(name);
salary =
s;
}
public double getSalary()
{
return
salary;
}
Q7: data.txt is a text file contains info about whether a person is a student or faculty, their name and either their salary if they are faculty or their gpa if they are students e.g. student salem 3.4 student mariam 2.9 faculty ali 1450.5 student jassem 3.7 faculty ahmed 2150 etc... Write code to do the following => First make an ArrayList of Person called auk Next, read the text file, create the objects (either Faculty or Student) and add them to auk Q8: Using the auk ArrayList from Q7, work out the average gpa of students.