Using Java import data from a text file named fata.txt then create two Student o
ID: 673179 • Letter: U
Question
Using Java import data from a text file named fata.txt then create two Student objects with the following name(String), id(String), and gpa(double values:
S1: John, 1111, 3.5
S2: Jean,2222, 3.9
The Student class must be a subclass of a Person class. The Person class must have a name field and an id field and the Student class must have a gpa field. THe Student class must also implement an interface called CurveGPA. The interface forces the Student class to implement a curveGPA() method that would add to each exisiting GPA.
Display these two objects with the curved GPA values on the console using toString() method.
Using JavaFX Gui allow the user to enter values for the two Student objects. You need three labels, three textfields and one button. Display the two new object information using the toString() method on either the console or the GUI
Explanation / Answer
public class Person
{
private String fname,lname;
protected int id;
public Person() {
}
public Person(String fname, String lname, int id) {
this.fname=fname;
this.lname=lname;
this.id=id;
}
public void setData(String fname, String lname,int id) {
this.fname=fname;
this.lname=lname;
this.id=id;
}
public void getData() {
System.out.println("id :- "+id);
System.out.println("First Name :- "+fname);
System.out.println("Last Name :- "+lname);
}
public void dispaly(){
getData();
}
class Student extends Person {
private double gpa;
public Student() {
}
public Student(double gpa) {
this.gpa=gpa;
}
public void setData(double gpa) {
this.gpa=gpa;
}
public void getData() {
System.out.println("GPA :-"+gpa);
}
public void display(){
super.getData();
getData();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.