0

Why i have in next loop when index = 2 executes the first and second line in same time :

** My goal is Create a JAVA Class which would allow School to store a Student Info for a particular year. but i have in next loop when index = 2 executes the first and second line in same time**

public class ReportCardStudint {
static ArrayList<String> studentName = new ArrayList<String>();
static ArrayList<String> studentLevel = new ArrayList<String>();

static Scanner reader =  new Scanner(System.in);
public static void main(String[] args) {
    /**
     * 
     * those lines take input from user and call getStudentInfo Method For 10 times
     */
    
    for (int index = 0; index < 10 ; index++) {
        
        
        System.out.println("Enter student Name:");
        studentName.add(reader.nextLine());
        
        System.out.println("Enter student Level:");
        studentLevel.add(reader.nextLine());
        
        System.out.println("Enter student Dep:");
        String dep;
        dep = reader.nextLine();
        
        System.out.println("Enter student Year:");
        int year;
        year = reader.nextInt();
        
        System.out.println("Enter student Math grad:");
        int mathGrad;
        mathGrad = reader.nextInt();    
        
        System.out.println("Enter student Java besics grad:");
        int javaGrad;
        javaGrad = reader.nextInt();
        getStudinInfo(studentName, studentLevel, dep, year, mathGrad, javaGrad);        
    }
    System.out.println("Student Info has stored");  
}

/**
 * 
 * This Method Create a new object From Student Class To Stored a new Info 
 * and called when user input Student info
 * @param name
 * @param level
 * @param dep
 * @param year
 * @param mathGrad
 * @param javaBesicsGrad
 * @return
 */
static private ArrayList<StudintInfo> getStudinInfo
(ArrayList<String> name , ArrayList<String> level , String dep , int year , int mathGrad , int javaBesicsGrad) {
    
ArrayList<StudintInfo> info = new ArrayList<StudintInfo>();
info.add(new StudintInfo(name, level, dep, year , mathGrad , javaBesicsGrad));
return info;        
}

}

A calss for Student Info

public class StudintInfo {
ArrayList<String> studentName;
ArrayList<String> level;
String dep;
int year;
int mathGrad;
int javaBesicsGrad;

public StudintInfo
(ArrayList<String> studentName , ArrayList<String> level , 
        String dep , int year , int mathGrad , int javaBesicsGrad) {
    this.studentName = studentName;
    this.level = level;
    this.dep = dep;
    this.year = year;
    this.mathGrad = mathGrad;
    this.javaBesicsGrad = javaBesicsGrad;
    
}

}

  • You don't need to introduce yourself and tell people that you're a beginner. SO is about the questions and the questions only. Also, please don't use bold text as your default. – akuzminykh Nov 10 '20 at 08:12
  • @akuzminykh I agree but the fact that the OP is a beginner might help shaping the answers. We might refrain from making too many assumptions or commenting on style etc. - at least that's my reaction on "I'm a beginner". But I also appreciate a nicely formatted question without "default" bold text :) – Thomas Nov 10 '20 at 08:16
  • Khalid, do you mean `index == 2` or in the second run, i.e. `index == 1`? The problem is very likely the one described in the question Ivar linked and thus I assume you mean the second run, right? – Thomas Nov 10 '20 at 08:19
  • @akuzminykh OK ^_^ – khalid Morrshid Nov 10 '20 at 08:29
  • @Thomas i mean in the second run – khalid Morrshid Nov 10 '20 at 08:31

0 Answers0