In: Computer Science
public class studentUpdate {
public static void main(String[] args) {
// instantiate Student object
Student s = ?;
// instantiate StudentOther object
StudentOther sO = ?;
// set the fields
s.setStudentName ?;
s.setId ?;
s.setCredits ?;
s.setGpa ?;
s.setScholarship ?;
s.setCommuter ?;
// check input
System.out.println(s.getStudentData());
// change this as needed
// run rating method 1
s.rating( s.getCredits(), s.getGpa() );
// run rating method 2
s.rating( s.getCredits(), s.getGpa(), s.getScholarship() );
// run rating method 3
s.rating( s.getScholarship(), s.getGpa() );
// run rating 4
sO.rating( s.getCredits(), s.getGpa() );
}
}public class StudentOther ? Student {
// @Override
// new student rating method - use c and g
public void rating( ? ) {
System.out.println("This is student rating 4 - Override");
}
}public class Student {
// variables
public String studentName;
public int id;
public int credits;
public double gpa;
public double scholarship;
public boolean commuter;
// getters and setters
// select all- access Public
// returns all the data in one string
public String getStudentData()
{
return(studentName + " has a gpa of " + gpa + " and has completed " + credits + " credits");
}
// student rating method
// this is the primary method
public void rating(int c, double g) {
System.out.println("Student rating 1 is: " + (c * g));
}
// @Overload
// overload by count - add double s
public void rating( ? ) {
System.out.println("Student rating 2 is: " + ((c + s) * g) + " Overload by count" );
}
// @Overload
// overload by type
public void rating( ? ) {
System.out.println("Student rating 3 is: " + (s * g) + " Overload by type");
}
}
Below are the completed classes as per comments:
Student.java
public class Student {
// variables
public String studentName;
public int id;
public int credits;
public double gpa;
public double scholarship;
public boolean commuter;
// getters and setters
// select all- access Public
// returns all the data in one string
public String getStudentData() {
return (studentName + " has a gpa of " + gpa + " and has completed "
+ credits + " credits");
}
// student rating method
// this is the primary method
public void rating(int c, double g) {
System.out.println("Student rating 1 is: " + (c * g));
}
// @Overload
// overload by count - add double s
public void rating(int c, double g, double s) {
System.out.println("Student rating 2 is: " + ((c + s) * g)
+ " Overload by count");
}
// @Overload
// overload by type
public void rating(double s, double g) {
System.out.println("Student rating 3 is: " + (s * g)
+ " Overload by type");
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getCredits() {
return credits;
}
public void setCredits(int credits) {
this.credits = credits;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
public double getScholarship() {
return scholarship;
}
public void setScholarship(double scholarship) {
this.scholarship = scholarship;
}
public boolean isCommuter() {
return commuter;
}
public void setCommuter(boolean commuter) {
this.commuter = commuter;
}
}
StudentOther.java
public class StudentOther extends Student {
// @Override
// new student rating method - use c and g
public void rating(int c, double g) {
System.out.println("This is student rating 4 - Override and the rating is: " + (c * g));
}
}
StudentUpdate.java
public class StudentUpdate {
public static void main(String[] args) {
// instantiate Student object
Student s = new Student();
// instantiate StudentOther object
StudentOther sO = new StudentOther();
// set the fields
s.setStudentName("Nitya");
s.setId(1);
s.setCredits(32);
s.setGpa(3.5);
s.setScholarship(250.50);
s.setCommuter(true);
// check input
System.out.println(s.getStudentData());
// change this as needed
// run rating method 1
s.rating(s.getCredits(), s.getGpa());
// run rating method 2
s.rating(s.getCredits(), s.getGpa(), s.getScholarship());
// run rating method 3
s.rating(s.getScholarship(), s.getGpa());
// run rating 4
sO.rating(s.getCredits(), s.getGpa());
}
}
Output
Nitya has a gpa of 3.5 and has completed 32 credits
Student rating 1 is: 112.0
Student rating 2 is: 988.75 Overload by count
Student rating 3 is: 876.75 Overload by type
This is student rating 4 - Override and the rating is:
112.0