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

JAVA PROGRAM. Develop a main program from the belowe java programs Develop a mai

ID: 3756048 • Letter: J

Question

JAVA PROGRAM. Develop a main program from the belowe java programs

Develop a main program that:

• allows the user to enter the information for a number of students

• creates objects of type Student and stores in an array (of type Students[])

• allows the user to display the information of the student with the highest gpa

/////////////////////////////////////////////////student.java/////////////////////////////////////

public class Student extends Person {
private int earned_credits;
private double gpa;
private String major;
public Student(String name, int age, int height_weight, int earned_credits, double gpa, String major) {
super(name, age, height_weight);
this.earned_credits = earned_credits;
this.gpa = gpa;
this.major = major;
}
public int getEarned_credits() {
return earned_credits;
}
public double getGpa() {
return gpa;
}
public String getMajor() {
return major;
}
@Override
public String toString() {
return "earned credits=" + earned_credits + ", gpa=" + gpa + ", major=" + major;
}
public String getStatus() {
if (earned_credits >= 0 && earned_credits <= 30) {
return "freshman";
} else if (earned_credits <= 60) {
return "sophomore";
} else if (earned_credits <= 90) {
return "junior";
} else {
return "senior";
}
}
public boolean onDeansList() {
return gpa >= 3.4;
}
}

///////////////////////////////////////////person.java/////////////////////////////////////////////////

public class Person {
private String name;
private int age;
private int HeightAndWeight;
public Person(String n, int a, int hw) {
name = n;
age = a;
HeightAndWeight = hw;
}
// getName
public String getName() {
return name;
}
// getAge
public int getAge() {
return age;
}
// getHeightAndWeight
public int getHeightAndWeight() {
return HeightAndWeight;
}
// toString statement
public String toString() {
return "Name=" + name + " " + "Age=" + age + " " + "HeightAndWeight=" + HeightAndWeight;
}
}

///////////////////////// tester.java///////////////////////////////

public class TestStudentClass
{
public static void main(String[] args)
{
Student s1 = new Student("Bikram", 24, 45, 80, 4.5, "computer science");
// printing the status of the student
System.out.println("Status : " + s1.getStatus());
System.out.println(s1);
}
}

Explanation / Answer

/******************************************************************************

Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
/******************************************************************************

Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;

class Student extends Person {
private int earned_credits;
private double gpa;
private String major;

public Student() {}
public Student(String name, int age, int height_weight, int earned_credits, double gpa, String major) {
super(name, age, height_weight);
this.earned_credits = earned_credits;
this.gpa = gpa;
this.major = major;
}
public int getEarned_credits() {
return earned_credits;
}
public double getGpa() {
return gpa;
}
public String getMajor() {
return major;
}
@Override
public String toString() {
return " "+super.toString()+" earned credits=" + earned_credits + ", gpa=" + gpa + ", major=" + major;
}
public String getStatus() {
if (earned_credits >= 0 && earned_credits <= 30) {
return "freshman";
} else if (earned_credits <= 60) {
return "sophomore";
} else if (earned_credits <= 90) {
return "junior";
} else {
return "senior";
}
}
public boolean onDeansList() {
return gpa >= 3.4;
}
}

class Person {
private String name;
private int age;
private int HeightAndWeight;

public Person() {}
public Person(String n, int a, int hw) {
name = n;
age = a;
HeightAndWeight = hw;
}
// getName
public String getName() {
return name;
}
// getAge
public int getAge() {
return age;
}
// getHeightAndWeight
public int getHeightAndWeight() {
return HeightAndWeight;
}
// toString statement
public String toString() {
return "Name=" + name + " " + "Age=" + age + " " + "HeightAndWeight=" + HeightAndWeight;
}
}


public class Main
{
public static void main(String[] args)
{
/*
Student s1 = new Student("Bikram", 24, 45, 80, 4.5, "computer science");
// printing the status of the student
System.out.println("Status : " + s1.getStatus());
System.out.println(s1); */
Scanner scan = new Scanner(System.in);

//asking user to input number of student
System.out.print("Enter number of students:");
int numOfStudents= scan.nextInt();

//creating objects of type Student and stores in an array
Student [] students = new Student[numOfStudents];

for(int i=0;i<numOfStudents;i++)
{
//askiner each number of students details
  
System.out.print(" Enter "+(i+1)+" student name:");
String name = scan.next();

System.out.print("Enter "+(i+1)+" student age:");
int age = scan.nextInt();

System.out.print("Enter "+(i+1)+" student height_weight:");
int height_weight = scan.nextInt();

System.out.print("Enter "+(i+1)+" student earned_credits:");
int earned_credits = scan.nextInt();

System.out.print("Enter "+(i+1)+" student gpa:");
double gpa = scan.nextDouble();

System.out.print("Enter "+(i+1)+" student major:");
String major = scan.next();

//creating student object with entered details
Student student = new Student(name,age,height_weight, earned_credits, gpa,major);

//assigning student object to students array
students[i]=student;
}

//creating student object with array index 0
Student st = students[0]; ;

//lets assume student at 0 index has highestGpa
double highestGpa= students[0].getGpa();

//for loop to find student with highestGpa
for(int i=0;i<students.length;i++)
{
if(students[i].getGpa() > highestGpa )
{
st = students[i];
}
}

//displaying info
System.out.print("Highest GPA Student Info: "+st.toString());
}
}

Output:

Enter number of students:2                                                                                            

                                                                                                                      

Enter 1 student name:John                                                                                             

Enter 1 student age:28                                                                                                

Enter 1 student height_weight:49                                                                                      

Enter 1 student earned_credits:74                                                                                     

Enter 1 student gpa:4.7                                                                                               

Enter 1 student major:computerscience                                                                                 

                                                                                                                      

Enter 2 student name:Neil                                                                                             

Enter 2 student age:25                                                                                                

Enter 2 student height_weight:44                                                                                      

Enter 2 student earned_credits:80                                                                                     

Enter 2 student gpa:4.9                                                                                               

Enter 2 student major:cse                                                                                             

Highest GPA Student Info:                                                                                             

Name=Neil Age=25 HeightAndWeight=44 earned credits=80, gpa=4.9, major=cse