Solve using arrays system please Problem : Dr Becky need your help to determine
ID: 3661912 • Letter: S
Question
Solve using arrays system please Problem : Dr Becky need your help to determine which students are eligible for CSC1311-Computer Programming 2. She wants you to write a Java program to accomplish this feat. STUDENT WHO PASS csc1310-COMPUTER PROGRAMING 1 WITH grade of C or better (A,B) can enroll in CSC 1311-computer Programming2.your program should verify the following students are eligible.
Banner ID ---------------------Grade
54000001----------------------- D
54000011 ---------------------A
54000201---------------------- F
54600023==------------------ I
54020002 ----------------------C
54002004-------------------- B
54602222 --------------------W
you must write your program in methods including accessors and mutator.
use a loop to process the students.
Sumit algorithm(typed), Programs(source code Java),
Sample output Comment
Solve using arrays system please
Explanation / Answer
Algorithm:
Created a Student class with bannerId and grade as member variables with accessor and mutators.
I am taking the number of students as an input from user and then creating an array of student of that size.
Taking the student bannerId and grade input from user,creating a student object and stoiring it in array of students,
Finally iterate over the array of students and check for eligiblity and display eligible or ineligible in front of bannerId
Student.java
public class Student {
private String bannerID;
private String grade;
//Constructor to create a student with a bannerID and grade in the subject csc1310
public Student(String id,String grade)
{
bannerID=id;
this.grade=grade;
}
//Mutators
public String getBannerID() {
return bannerID;
}
public void setBannerID(String bannerID) {
this.bannerID = bannerID;
}
//Accessors
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
}
Main.java(for execution of program)
import java.io.*;
public class Main {
public static void main(String args[])throws IOException
{
InputStreamReader ir =new InputStreamReader(System.in);
BufferedReader br =new BufferedReader(ir);
//Asking the user for number of students
System.out.println("Enter the number of students");
int n=Integer.parseInt(br.readLine());
//Taking input for each student one by one and adding those student to the array of students
Student students[]=new Student[n];
for(int i=0;i<n;i++)
{
String id=br.readLine();
String grade=br.readLine();
students[i]=new Student(id,grade);
}
//Iterating over the array of students to check if a student is eligible or not for CS1311
for(int i=0;i<students.length;++i)
{
if(students[i].getGrade().equalsIgnoreCase("C")||students[i].getGrade().equalsIgnoreCase("A")||students[i].getGrade().equalsIgnoreCase("A"))
{
System.out.println(students[i].getBannerID()+"------- eligible");
}
else
{
System.out.println(students[i].getBannerID()+"------- ineligible");
}
}
}
}
Sample output for sample input
54000001------- ineligible
54000011------- eligible
54000201------- ineligible
54600023------- ineligible
54020002------- eligible
54002004------- ineligible
54602222------- ineligible