Hello everyone, I quite new at JAVA and one assignment is on my nose and I am going crazy..
My task is: "Create a solution for the following scenario: A local community mobile college unit holds 2 different classes in literacy and numeracy for mature students. A student can join the mobile unit and sign up to one or both classes. The students ID number, name, age and telephone no should be held on the system for initial sign up." and "An ultimate solution would be where the two courses can be set up and then students enrolled on the courses. A menu system should allow for input of extra courses (in case of expansion) input of student details and students to enroll on courses.
The menu should also allow a list of students by course, a list of all students by age.
".
Maybe I am doing it the wrong way, but..
I have created the WHILE for number of students to enroll on specific courses and my friend helped me to array it.. but I cant figure out how to print.out the information and if the array is where it supposed to be.
1st file:
import java.util.Scanner;
class test1
{
static student mystudent[] = new student[30]; // - create the array (30 element will be more then enough)
static int arrindex = 0; // - item index for the array
public static void menu()
{
System.out.println("\n\n1. Numeracy");
System.out.println("2. Literacy");
System.out.println("3. Add another course and enroll to it");
System.out.println("4. List of students by age");
System.out.println("5. List of students by course.");
System.out.println("6. Exit");
}
public static void main (String[]args)
{
Scanner input = new Scanner(System.in);
String studName, newCourse;
int studId, studAge, studTelNr, option=0;
System.out.println("Wellcome to mobile college!");
while (option!=6)
{
System.out.println("Choose your course you want to enroll to.");
menu();
System.out.println("");
option = input.nextInt();
if (option!=6)
{
if (option==1)
{
System.out.println("\n\nFill in all details to enroll to Numeracy:");
System.out.println("\nYour student ID number ");
studId = input.nextInt();
System.out.println("Your Name ");
studName = input.next();
System.out.println("Your Age ");
studAge = input.nextInt();
System.out.println("Your telephone number ");
studTelNr = input.nextInt();
mystudent[arrindex] = new student (studId, studName, studAge, studTelNr, "Numeracy"); // - put the new student to the array
arrindex++; // - increase itemindex
}
if (option==2)
{
System.out.println("Fill in all details to enroll to Literacy:");
System.out.println("\nYour student ID number ");
studId = input.nextInt();
System.out.println("Your Name ");
studName = input.next();
System.out.println("Your Age ");
studAge = input.nextInt();
System.out.println("Your telephone number ");
studTelNr = input.nextInt();
mystudent[arrindex] = new student (studId, studName, studAge, studTelNr, "Literacy");
arrindex++;
}
if (option==3)
{
System.out.println("Please enter the name of the course: ");
newCourse = input.next();
System.out.println("\nYour student ID number ");
studId = input.nextInt();
System.out.println("Your Name ");
studName = input.next();
System.out.println("Your Age ");
studAge = input.nextInt();
System.out.println("Your telephone number ");
studTelNr = input.nextInt();
mystudent[arrindex] = new student (studId, studName, studAge, studTelNr, "Literacy");
arrindex++;
}
if (option==4)
{
}
if (option==5)
{
System.out.println(""+student.getAge());
}
}
}
}
void sortbyage()
{// - sort the array by age
student tmp = null;
int i=0;
int j=1;
while(i<=arrindex)
{
while(j<=arrindex)
{
if(mystudent[i].getAge()>mystudent[j].getAge())
{
tmp = mystudent[i];
mystudent[i]=mystudent[j];
mystudent[j]=tmp;
}
else
{//if
j++;
}//else
}//for j
i++;
}//for i
}
}
2nd file:
/* the pets class*/
class student
{
private int id;
private String name;
private int age;
private int number;
private String course;
student (int i, String n, int a, int nr, String c)
{
id = i;
name = n;
age = a;
number = nr;
course = c;
}
int getId()
{
return id;
}
String getName()
{
return name;
}
int getAge()
{
return age;
}
int getNr()
{
return number;
}
String getCourse()
{
return course;
}
}
Any help is very much appreciated!