Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA Array Create a Student class. The class contains 2 attributes. 1. Student I

ID: 3683599 • Letter: J

Question

JAVA Array

Create a Student class.

The class contains 2 attributes. 1. Student ID Number (for example, 3356) – data type integer 2. An array of 3 CollegeCourse objects. Create a get( ) and set( ) method for the Student Id field. Create a get( ) method that returns a String representation one of the student’s CollegeCourse this method will have an integer parameter (0 through 2) that corresponds to the appropriate college course. Concatenate the values together with spaces. For example: “Course: CIS 210, Credit Hours: 3, Grade: A”. Be sure to check that the user has entered a valid index. If the index is invalid, return the string “Not a valid index”. Create a set( ) method that sets the value of one of the student’s CollegeCourses; the method takes 4 arguments. 1. The index (0 through 2) 2. Course ID 3. Credit Hours 4. Grade Be sure to check that the user has entered a valid index. If the index is invalid, do nothing. You must also initialize the object here. For example, if you named the array courses you would code: courses[i] = new CollegeCourse(); Save the file as Student.java

Explanation / Answer

hey heres the code:

class Student
{

int stuID;
CollegeCourse[] courses=new CollegeCourse[3];

public void setStudentID(int id)
{
stuID=id;
}
public int getStudentID()
{
return stuID;
}
public void setCollegeCourseSub(int i,String str,int ch,char g)
{
if(i>=0 && i<3)
{
courses[i].setValues(str,ch,g);
}
}
public String getCollegeCourseSub(int i)
{
if(i>=0 && i<3)
{
String str;
int n;
n=courses[i].getcr();
return " Course ID :"+courses[i].getCID()+" Credit hours "+Integer.toString(n)+" Grade: "+courses[i].getg();
}
else
return "INVALID STRING";
}
}
class CollegeCourse {
private String courseID;
int credithours;
char grade;
public void setValues(String s,int cr,char gr)
{
courseID=s;
credithours=cr;
grade=gr;
}
public String getCID()
{
return courseID;
}
public int getcr()
{
return credithours;
}
public char getg()
{
return grade;
}
}