gpt4 book ai didi

java - 如何根据用户的需要创建尽可能多的对象?

转载 作者:行者123 更新时间:2023-12-01 12:11:47 25 4
gpt4 key购买 nike

我即将完成一项作业,我将引用该作业(我不是要求您为我做,我只是不知道如何开始)

Your task is to write a (very simple:-) student record system. You should be able to store details about students - their name, subject and a student number; as well as the level they have most recently completed ranging from 0 (meaning they are still in the first year) through to 3 (meaning they have graduated). It should also store their result for each level they have completed as a number 0-100. Your program should allow the user to enter student data for as many students as they want.

这是否可以通过对象来完成,因为我对此部分感到非常困惑..

任何建议都会有帮助,我可以做除这部分之外的所有事情。

最佳答案

Student应该是一个类并包含提到的所有属性。一旦您拥有Student你可以上的课Student允许您拥有 ArrayList<Student> 的对象因此,您可以存储任意数量的学生。例如:

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

while(youWantToReadStudents){
Student student = new Student();
// read and add student details
students.add(student); // add student to ArrayList
}

请注意循环如何允许您将学生添加到 ArrayList只要youWantToReadStudents == true

关于java - 如何根据用户的需要创建尽可能多的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27230101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com