Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In JAVA PLEASE SHOW CLASS SET UP Use inheritance to display a college student’s

ID: 3575022 • Letter: I

Question

In JAVA

PLEASE SHOW CLASS SET UP

Use inheritance to display a college student’s record.

The user enters the student name.

The user enters the major.

The user enters the GPA.

The application creates a college student object and displays it on the screen.

Create a class that defines a student. This class should contain at least two instance variables for name and GPA. It should also contain a constructor that accepts two values for the instance variables. In addition to set and get methods, the class should override the toString method from the Object class.

Create a class that defines a college student. To do this, the class should inherit the student class. In addition to the inherited instance variables, this class should contain at least one more instance variable that defines the college student’s major. This class a constructor that accepts three values for the instance variables. The first statement in this constructor should call a constructor in the superclass. This class should also override the toString method.

Explanation / Answer

Program:
package org.dailytasks;
import java.util.Scanner;
class Student {
  
   String name;
   double GPA;
  
   public Student(String name,double GPA){
       this.name = name;
       this.GPA = GPA;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public double getGPA() {
       return GPA;
   }
   public void setGPA(double gPA) {
       GPA = gPA;
   }
  
   @Override
   public String toString(){
       return name+" "+GPA;
      
   }
}
class CollegeStudent extends Student{
  
   String major;
   public CollegeStudent(String name, double GPA,String major){
       super(name,GPA);
       this.major = major;
   }
   @Override
   public String toString(){
       return name+" "+GPA+" "+major;
   }
  
}
public class DefineApplication{
   public static void main(String args[]){
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter name,GPA and major of student:");
       String name = sc.next();
       double GPA = sc.nextDouble();
       String major = sc.next();
       CollegeStudent stu = new CollegeStudent(name, GPA, major);
       System.out.println("college student details:"+stu.toString());//displays student details
   }
}
Output:
Enter name,GPA and major of student:
lakshman 85.87 major
college student details:lakshman 85.87 major

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote