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

Construct a Java class named CscStudent which inherits from (i.e. extends) the S

ID: 3589991 • Letter: C

Question

Construct a Java class named CscStudent which inherits from (i.e. extends) the Student class presented below. Your new class should add the additional private data members of a String named advisor and a double named average. Write a constructor for your class which takes 3 strings and a double. The first two strings should be passed to the super class constructor to be assigned properly. The third String should be assigned into the advisor field and the final double value should be assigned into the average field.

You should write a class and file named Problem1.java that will contain a main method. You should create an instance of the CscStudent object for testing purposes.

public class Student {

protected String name;

protected String ssnum;

public Student(String name, String ssnum) {

this.name = name;

this.ssnum = ssnum; }

}

Explanation / Answer

Student.java

public class Student {

//Declaring instance variables

protected String name;

protected String ssnum;

//Parameterized constructor

public Student(String name, String ssnum) {

this.name = name;

this.ssnum = ssnum; }

public String getName() {

return name;

}

//getters and setters

public void setName(String name) {

this.name = name;

}

public String getSsnum() {

return ssnum;

}

public void setSsnum(String ssnum) {

this.ssnum = ssnum;

}

//toString method is used to display the contents of an object inside it

@Override

public String toString() {

return "Name=" + name + ", Ssnum=" + ssnum;

}

  

}

_______________

CscStudent.java

public class CscStudent extends Student {

//Declaring instance variables

private String adviser;

private double average;

//Parameterized constructor

public CscStudent(String name, String ssnum, String advissr, double average) {

super(name, ssnum);

this.adviser = advissr;

this.average = average;

}

//getters and setters

public String getAdviser() {

return adviser;

}

public void setAdviser(String adviser) {

this.adviser = adviser;

}

public double getAverage() {

return average;

}

public void setAverage(double average) {

this.average = average;

}

//toString method is used to display the contents of an object inside it

@Override

public String toString() {

return super.toString()+" Adviser=" + adviser + ", Average=" + average;

}

}

________________

Problem1.java

import java.util.Scanner;

public class Problem1 {

public static void main(String[] args) {

  

//Declaring variables

String name,ssnum,adviser;

double average;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Getting the input entered by the user

System.out.print("Enter Name :");

name=sc.nextLine();

  

System.out.print("Enter Social Security Number :");

ssnum=sc.nextLine();

  

System.out.print("Enter Adviser :");

adviser=sc.nextLine();

System.out.print("Enter Grade :");

average=sc.nextDouble();

//Creating an CSEStudent object by passisng the user entered inpts as arguments

CscStudent stud=new CscStudent(name, ssnum, adviser, average);

  

//Displaying the output

System.out.println(stud.toString());

}

}

__________________

Output:

Enter Name :Kane Williams
Enter Social Security Number :F-123H
Enter Adviser :Johnson
Enter Grade :87
Name=Kane Williams, Ssnum=F-123 HSdvisor=Johnson, Average=87.0


_____________Could you rate me well.Plz .Thank You