new to java, and i'm making a student record system. I want to use the specified year stored in the arraylist in this code (i have used an array list as i plan on eventually making this loop to allow multiple inputs)
import java.util.ArrayList;
import java.util.Scanner;
public class StudentYear
{
public ArrayList<Integer> studentYear;
public void StudentYear()
{
studentYear = new ArrayList<Integer>();
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the year the student has most recently completed: ");
studentYear.add(sc.nextInt());
System.out.println(studentYear);
}
public ArrayList<Integer> getStudentYear()
{
return studentYear;
}
}
This is the code for the class that i want the stored year value in the arraylist studentYear, from the above code to go into
import java.util.ArrayList;
import java.util.Scanner;
public class Results
{
public static void Results(StudentYear studentYear)
{
int year = studentYear.getStudentYear().get(0);
ArrayList<Integer> results = new ArrayList<Integer>();
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the results for "+year+":");
results.add(sc.nextInt());
System.out.println(results);
}
}
this is my main code
StudentYear yearInputobject = new StudentYear();
yearInputobject.StudentYear();
Results resultsInputobject = new Results();
resultsInputobject.Results(); //error here < The method Results(StudentYear) in the type Results is not applicable for the arguments ()
Any help would be greatly appreciated, ive been stuck on this for hours.
Edit: error now
exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method Results(StudentYear) in the type Results is not applicable for the arguments ()
at Main.main(Main.java:21)
results code once again
import java.util.ArrayList;
import java.util.Scanner;
public class Results
{
public static void Results(StudentYear studentYear)
{
int year = studentYear.getStudentYear().get(0);
ArrayList<Integer> results = new ArrayList<Integer>();
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the results for "+year+":");
results.add(sc.nextInt());
System.out.println(results);
}
}
NullPointerExceptionis not a compile-time error. And, I thought you said you had a compile-time error when usingget. Did you update your question with a new question?