K, I'm basically brand new to java and have to do an assignment way beyond anything I've learned.
this is what im trying to accomplish:
Specification
So right now I'm trying to work on creating a class "Student" that has all those fields and methods. Then somehow once I have all that I've got to figure out how to get that into an array that can make more students with that information and stuff etc. I'm confused and barely know how to make an array. =S
It would be helpful if someone told me how to call an array without a pre-set amount of items in the list.
Anyway this is what I have so far:
For my menu:
package ArrayList; import java.util.Scanner; public class Menu { public static void main( String[] args ) { System.out.println("Welcome!"); Scanner input = new Scanner (System.in); int UR; //user Response 1 System.out.println("Please type the number of the task you would like to perform."); System.out.println("1. Add a student"); System.out.println("2. Find a student"); System.out.println("3. Delete a student"); System.out.println("4. Display all students"); System.out.println("5. Display the total number of students"); System.out.println("6. Exit"); UR = input.nextInt(); if (UR == 1){ Student sDisplay = new Student(); sDisplay.Display(); } } }
For my Student:
package ArrayList; public class Student { String fName; String lName; int sNumber; String Major; Double GPA; static int Count; public void fName() { fName = "Sarah"; } public void lName() { lName = "Somethin"; } public void sNumber() { sNumber = 1; } public void Major() { Major = "Computer Science"; } public void GPA() { GPA = 4.0; } public static void Count() { Count = 0; } public void Display() { Student firstName = new Student(); firstName.fName(); System.out.printf("The name is: %d\n", GPA); System.out.print(fName); } }
__________________________________________________ ______________________
When I ran my program what I expected to get was this:
The name is: 4.0
Sarah
But when I run it with user input 1
I get:
1
The name is: null
null
Yes, what im trying to accomplish there doesn't relate to assignment specifically but how am I suppose to get it to work? and why isn't the name being assigned to the String or the int receiving its number? (I'm assuming its cause its only running through part of the program. or that particular class. which is why I tried to make Display call fName and run it so its assigned. But it didn't work and I'm obviously confused.) =S
Basically I need as much help as I can get with this, especially with the arrays. So thanks in advance.