I have been working a program that allow the user to perform the following task, add student, display student, delete student, and find student. I need help with add student name, gpa..etc to the arraylist. But I keep getting either compiler messages or other error message. I have been trying many different way to make it, but it all failed.

This is the constructors I create(I don't get any error here):

import java.util.Scanner;

public class StudentArrayList
{
		static int count;
		String fName;
		String lName;
		String major;
		double gpa;
		int sNumber;
	
	public StudentArrayList()
	{
	
	}
	public StudentArrayList(String fN, String lN, String mj, double ga, int sN)
	{
		fName = fN;
		lName = lN;
		major = mj;
		gpa = ga;
		sNumber = sN;
		count++;
	}
	
	public void setFName (String fN)
	{
		fName = fN;
	}
	public void setlName (String lN)
	{
		lName = lN;
	}
	public void setmajor (String mj)
	{
		major = mj;
	}
	public void setGa (double ga)
	{
		gpa = ga;
	}
	public void setSnumber (int sN)
	{
		sNumber = sN;
	}
	public void setCount (int ct)
	{
		count = ct;
	}
	public String getFname()
	{
		return fName;
	}
	public String getLname()
	{
		return lName;
	}
	public String getMajor()
	{
		return major;
	}
	public double getGpa()
	{
		return gpa;
	}
	public int getSNumber()
	{
		return sNumber;
	}
	public int getCount()
	{
		return count;
	}

}

Here is class I create to perform the task, but keep getting errors:

import java.util.Scanner;
import java.util.ArrayList;
public class StudentList
{	
	
	public static void pause() 
	{ 
		try 
		{ 
			System.out.print("Press <Enter> to continue..."); 
			System.in.read(); 
		} 
		catch (Exception e)
		{
			System.err.printf("Error %s%c\n",e.getMessage(),7);
		}
	}
	
	public static void main(String[] args)
	{
		ArrayList <StudentArrayList> record = new record <StudentArrayList>();
	
		Scanner keyBd = new Scanner( System.in );
		char selection;

		do{
			System.out.println("\n--------------");
			System.out.println("1. Add Student");
			System.out.println("2. Remove Studnet");
			System.out.println("3. Find Studnet");
			System.out.println("4. Display All Studnet");
			System.out.println("5. Exit\n");
			System.out.print  ("Selection: ");

			selection = keyBd.next().charAt(0);
						
			switch (selection){
				case '1':
				
					Scanner keybd = new Scanner( System.in );
					System.out.println("First Name: ");
					String fName = keybd.nextLine();
					System.out.println("Last Name: ");
					String lName = keybd.nextLine();
					System.out.println("Major: ");
					String major = keybd.nextLine();
					System.out.println("gpa: ");
					double gpa = keybd.nextDouble();
					System.out.println("S number: ");
					int sNumber = keybd.nextInt();
					String s = String.format("Studnet Name: %s %s. Major: %s. GPA:  SNumber: ", fName, lName, major);
					record.add(s);
					
					
					pause();
					break;
				case '2':
					pause();
					break;
				case '3':
					pause();
					break;
				case '4':
					pause();
					break;
				case '5':
					break;
				default :
					
					System.out.println("Invalid Selection");
			}//end switch

		}while( selection != '6');
		
	/*public static StudentArrayList addStudent()
	{
		Scanner keyBd = new Scanner( System.in );
		System.out.println("First Name: ");
		String fName = keyBd.nextLine();
		System.out.println("Last Name: ");
		String lName = keyBd.nextLine();
		System.out.println("Major: ");
		String major = keyBd.nextLine();
		System.out.println("gpa: ");
		double gpa = keyBd.nextLine();
		System.out.println("S number: ");
		int sNumber = keyBd.nextLine();
		
		return new StudentArrayList(String fN, String lN, String mj, double ga, int sN);
	}*/
	
		
		

	}
}

at Line 75-90 is the method I try to create to add the name, but for some reasons I'm getting compiler errors. So I comment it out and try to use string.format to store the information and add it to the arraylist which is line 40-52. I still keep gettign compiler error.
Is there other way to do it or should I just change some parts of my code and everything will just work fine? Thank you so much

Post the stack trace of the errors. They will tell you exactly what the errors are and what line they occur on.

Line 21

ArrayList <StudentArrayList> record = new record <StudentArrayList>();

What is this record? .......................... :)

It must be ArrayList

You have compile errors in your 'addStudent()' method because it's inside the 'main' method. It needs to be between the two closing braces ('}') at the end.

Once you fix that, you'll want to change the last two '.nextLine()' calls, as you did in the copy of the code above it.

I believe that the method call syntax you're looking for is 'new StudentArrayList(fName, lName, major, gpa, sNumber)'.

Now you might say that the 'record.add(s);' line doesn't compile because you're not using the 'addStudent()' method. Or maybe you don't need the 'addStudent()' method.

aw... Thank you guys so much. Silly me, no wonder it keeps getting compiler errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.