我不知道如何制作我的代码以便它允许用户输入信息,我知道如何创建一个数组列表数据库,但不知道如何制作它,以便一旦用户输入信息并按下“输入”数据库已完成...有人可以帮帮我吗?(在Java中)
感谢用户输入的开始提示!他们很有帮助!好的,所以现在我有:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class BestStudent
{
private String studentName;
private String studentGPA;
public BestStudent()
{
}
public BestStudent(String nName, String nGPA)
{
this.studentName = nName;
this.studentGPA = nGPA;
}
public void setStudentName(String newStudentName)
{
studentName = newStudentName;
}
public void setStudentGpa(String newStudentGPA)
{
studentGPA = newStudentGPA;
}
public String getStudentName()
{
return studentName;
}
public String getStudentGPA()
{
return studentGPA;
}
public static void main(String[] args)
{
List<BestStudent> students = new ArrayList<BestStudent>();
Scanner input = new Scanner(System.in);
System.out.println("Enter number of students");
int countStudents = input.nextInt();
for(int i = 0; i < countStudents; i++)
{
BestStudent student = new BestStudent();
System.out.println("Enter student details" + i);
System.out.println("Enter student name");
student.setStudentName(input.next());
System.out.println("Enter student GPA");
student.setStudentGpa(input.next());
students.add(student);
}
}
}
有没有办法让程序计算输入的最高 GPA?我不是在寻找任何人来给我答案,只要朝着正确的方向推动就会很棒,非常感谢!!