I'm new to Java, and even newer to OOP. I am trying to complete this assignment for one of my classes.
B. Array of Objects Write a program that meets the following requirements:
Create a class for students. The class must contain each student’s name, (String), ID (int) and status (int.)
The status indicates the student’s class standing: 1 for freshman, 2 for sophomore, 3 for junior and 4 for senior.
Create 20 students whose names are Name1, Name2 and so on, to Name20, and who’s IDs and status are assigned randomly. Print out the array of student objects.
Find all juniors and print their names and IDs.
NOTE: Use the Math.random() method to create student ID and status.
I know this is relatively simple, but I'm just not quite getting it. Here is my code so far:
class ArryOfObjects{
public static void main(String[] args){
String stuName;
int stuID, stuStatus;
Student [] name = new Student[20];
int i;
while(i < name.length){
name[i] = new Student(creatStuInfo()); //hopefully this loads objects into arrays
i++;
}
}
}
class Student{
String stuName;
int stuID, stuStatus;
Student(){
stuName = this.stuName;
stuID = this.stuID;
stuStatus = this.stuStatus;
}
public void creatStuInfo(int i){
int min = 1;
int max = 4;
String stuName;
int stuID, stuStatus;
stuID = Math.random();
stuStatus = randInt();
stuName = Name + i;
}
public int randInt(int min, int max){
Random rand = new Random();
int randomNum = rand.nextInt((max - min) + 1) + min;
return randomNum;
}
}
The method randInt is my attempt to use math.random(), but I'm not sure how to get it to display between 1 and 4 like the requirements ask.
I might as well ask while I'm here, does anyone have any ideas on scanning through the array to find the juniors?
And how would you print out the objects in this particular case?
Also could you look through my code and simply point out my dumb mistakes?
Thank you so much for any help you could give!