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

Questions 1 - 3 use the Student class The Student class contains the following c

ID: 3857805 • Letter: Q

Question

Questions 1 - 3 use the Student class
The Student class contains the following constructor:

public Student( String name, double gpa, String email )
It also contains a getter called getGPA( ) that returns the student’s gpa
and a getter called getEmail( ) that returns a String - the student’s email.

1. Make an object called s1 of type Student for the Student: "Adam", gpa 3.8 and email ah@yahoo.com.

11. The array interns is an array of Student. Write code to create an ArrayList of Student called honors and add Ahmed and only the interns whose gpa is > 3.5 to honors.

12. Write code to ask the user how many honor students he wishes to add. Then read in from the user using the Scanner class the name, gpa and email of those students and add them to the ArrayList

Explanation / Answer

1. To create student object we need to call the constructor.

Student student = new Student("Adam",3.8,"ah@yahoo.com");

11. Assuming already array exist as Student arrayInterns[].

ArrayList<Student> honours = new ArrayList<>();

for(int i=0; i<arrayInterns.length;i++)
{
   if(Double.compare(arrayInterns[i].getGPA(),3.5) > 0 || arrayInterns[i].getName.equals("Ahmed"))
   {
       honours.add(arrayInterns[i])
   }
}

12.

Scanner sc = new Scanner(System.in);

System.out.println("How many honour students you need to add");

ArrayList<Student> honours = new ArrayList<>(sc.nextInt());

for(int i=0; i<honours.Size();i++)
{
   String name, email;
   double gpa;
   System.out.println("Enter student name");
   name = sc.next();
   System.out.println("Enter GPA of student");
   gpa = sc.nextDouble();
   System.out.println("Enter email address");
   email = sc.next();
   honours.add(new Student(name,gpa,email));
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote