Question: Looking for help with Java assignment. Supposed to make a Array for 3 students using while loop print results. Had that working, after much refactoring,

Looking for help with Java assignment. Supposed to make a Array for 3 students using while loop print results. Had that working, after much refactoring, and second part of assigment (Add FindStudentByName method. I see "no errors" but nothing is working. Tried breaking out the two into separate methods. ....one issue with the "find" is that it prints the object 1 less then it =.. Not sure... Well here is the code..

import java.util.Scanner;

public class Student {

private double gpa;

private String name;

private String gender;

public Student(String name, String gender, double gpa) {

this.name = name;

this.gpa = gpa;

this.gender = gender;

}

public double getGpa() {

return gpa;

}

public String getName() {

return name;

}

public String getGender() {

return gender;

}

public void setName(String name) {

this.name = name;

}

public void setGpa(double gpa) {

this.gpa = gpa;

}

public void setGender(String gender) {

this.gender = gender;

}

public String toString() {

return "Student [Name=" + name + ", Gender=" + gender + ", Gpa=" + gpa + "]";

}

public Student[] student;

public static void main(String[] args) {

Student[] student = new Student[3];

student[0] = new Student("James", "Male", 3.70);

student[1] = new Student("Mary", "Female", 4.00);

student[2] = new Student("Benjamin", "Male", 3.92);

}

private void ViewStudents()

{

int i= 0;

while (i < student.length)

{

System.out.println(student[i]);

//System.out.println( count + ") " + student[count].getName() + ", " + student[count].getGender() );

i++;

}

}

private Student findStudentByName() {

Scanner sc = new Scanner(System.in);

String search;

System.out.println("Please enter Student Name: ");

search = sc.nextLine();

for(int i=0; i

Student input = student[i];

if ( input.getName().equals( search )) {

return input;

}

System.out.println(i + ")" + input);

}

return null;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!