What I want to do
I'm a complete newbie to Java, starting yesterday with the basics. I installed Eclipse and I am trying to create a School Principal menu that can list all students and teachers in the school (and also add new ones, but that will come later). So far I want to show only existing students, because I have not created any teachers.
What I have
At the moment I have created my class of students: (If you see something wrong or bad form, let me know!)
public class Student {
String name;
int age;
String program;
public Student(String StudentName){
this.name = StudentName;
}
public void PrintInfo(){
System.out.println(name + " is a " + age +" year old student in " + program);
}
public static void main(String[] args) {
}
}
And I also have this menu class, which first requires students to settle:
import java.util.Scanner;
public class Menu {
public static void populate(){
Student s01 = new Student("David");
s01.age = 12;
s01.program = "Elementary School";
s01.PrintInfo();
Student s02 = new Student("Alex");
s02.age = 5;
s02.program = "Kindergarten";
s02.PrintInfo();
}
public static void main(String[] args) {
Menu.populate();
System.out.println("Hello!");
System.out.println("For a list of students, press 1");
System.out.println("For a list of teachers, press 2");
Scanner reader = new Scanner(System.in);
System.out.println("Enter a number: ");
int n = reader.nextInt();
System.out.println("You Entered: " + n);
if (n==1){
System.out.println("Here is a list of the students:");
}else if (n==2){
System.out.println("Here is a list of the teachers:");
}
}
}
, , , . , void populate. , s01.PrintInfo(); main(), s01. ?
David is a 12 year old student in Elementary School
Alex is a 4 year old student in Kindergarten
Hello!
For a list of students, press 1
For a list of teachers, press 2
Enter a number:
1
You Entered: 1
Here is a list of the students: