我正在尝试做什么:
输入1到5之间的数字
退出计划
向4学生数组添加详细信息(ID,姓名,assignment_mark1,assignment_mark2,考试)
输出学生的详细信息
计算并输出学生的平均整体分数(assignment_mark1,assignment_mark2,examination)/ 3
输入学生ID并显示输入学生详细信息
我不能使用数组列表
public class Student{
Scanner keyboard = new Scanner(System.in);
private String name;
private int ID;
private float assignment_mark1;
private float assignment_mark2;
private float examination;
StudentDetail(){ //default constructor
this.name= "default";
this.ID =0;
this.assignment_mark1 = 0;
this.assignment_mark2 = 0;
this.examination = 0;
}
Student(String name, int ID, float assignment_mark1, float
assignment_mark2,
float examination){
this.name = name;
this.ID= ID;
this.assignment_mark1= assignment_mark1;
this.assignment_mark2 = assignment_mark2;
this.examination = examination;
}
/*
get and set methods here
*/
quit(){ //quit program }
addDetailsToAllStudent();
outputAllDetails();
computeAverageMarks(double assignment1, double assignment2, double
examination, double practical_work) {
double total=0;
total = (assignment1 + assignment2 + examination) / 3.0;
return total;
displayStudentDetail();
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Student[] array = new Student[4];//
boolean isRunning = true;
int choice = 0;
while(isRunning){
System.out.println("1. Quit ");
System.out.println("2. Add Details to all students ");
System.out.println("3. Output all student details");
System.out.println("4. compute average student marks");
System.out.println("5. Display student details based on ID");
choice = keyboard.nextInt();
while(choice>0 && choice<=5)
{
if (choice == 1) //quit
{
System.exit(0);
}
else if (choice == 2) //Add Details to all students
{
for(int i=0; i< array.length ; i++)
{
array[i] = new StudentDetail();
System.out.println("enter student"+(i +1) +":");
System.out.println("name");
String first_name = keyboard.nextLine();
array[i].setName(name);
System.out.println("Student id");
int ID= keyboard.nextInt();
array[i].setStudent_id(ID);
System.out.println("get Assignment1");
int getAssignment1 = keyboard.nextInt();
array[i].setAssignment1(getAssignment1);
System.out.println("get Assignment2 ");
int getAssignment2 = keyboard.nextInt();
array[i].setAssignment2(getAssignment2);
System.out.println("get Examination");
int getExamination = keyboard.nextInt();
array[i].setExamination(getExamination);
}
}
else if (choice == 3) //Output all student details
{
for(int i=0; i< array.length ; i++)
{
System.out.println(array[i].getName());
System.out.println(array[i].getStudent_id());
System.out.println(array[i].getAssignment1());
System.out.println(array[i].getAssignment2());
System.out.println(array[i].getExamination());
}
}
else if (choice == 4) //compute average student marks
{
for(int i=0; i< array.length ; i++)
{
double temp = array[i].getAssignment1();
double temp2= array[i].getAssignment2();
double temp3= array[i].getPractical_work();
double temp4 = array[i].getExamination();
System.out.println(array[i].averageOverallMark(temp,
temp2,temp3,temp4));
}
}
else if (choice == 5) // Display student details based on ID
{
numberOfStudentAchieveMark();
}
我的问题:
-------------已解决-------------------
答案 0 :(得分:0)
对于你的问题1:你可以像上面一样排列[i] .getName()。 对于你的问题2:因为你使用私人浮动来获得任务分数。你需要完成你的getter和setter。 对于您的问题3:在步骤2中创建设置后,您可以在静态类中创建的Student对象上调用该setter。