I’m currently working on a project for class but struggling with a bit of coding relating to
ArrayLists. It is as yet unfinished code; however, when I’m working on the enrollstudent
method I’m having an issue comparing the length of an ArrayList to the variable amountstudents.
Below is a copy of the code for the full class. There is another seperate class related but I don’t think it’s relevant here.
Any help would be greatly appreciated.
import java.util.*;
import java.util.Scanner;
public class Course {
int amountstudents;
String coursename;
String level;
ArrayList<String> students = new ArrayList<String>();
String tutor;
Scanner in = new Scanner(System.in);
public Course(int MaxCapacity) {
MaxCapacity = amountstudents;
tutor = "Not set yet";
coursename = "Not set yet";
level = "Not set yet";
}
public void enrollstudent(String addstudent) {
if(students.size > amountstudents) {
System.out.println("Unfortunately the class is already full so you can not be enrolled at this time");
}
else {
students.add(Student.fname);
}
}
public void courselevel() {
System.out.println("Please enter course level");
level=in.next();
}
public void coursetitle() {
}
}
It’s
students.size(), notstudents.size.Also, there’s another error:
It should be
students.add(addstudent), notstudents.add(Student.fname).