Java Design a user defined class called Course. Each course object will hold dat
ID: 3669164 • Letter: J
Question
Java Design a user defined class called Course. Each course object will hold data about a course. The data includes courseID, courseName, credits and instructorName. Define the instance variables required of appropriate type. Provide only get methods along with toString( ) and equals( ) methods. Use JavaDoc style comments.
Design another user defined class called Student. Each student object will hold data on studentID, name, GPA, gender, and courseList. Make sure to define studentID of int type, name as String, gender as a char type and courseList as an array of Course. Declare a static variable named nextID initialized to 1000. nextID will be incremented inside the constructor and it’s value would be assigned to studentID. Please note the constructor will not require a separate parameter to initialize studentID. Provide only get methods. Also implement the toString( ) and equals( ) methods. Use JavaDoc style comments.
Create a client program with main method. Start by creating Course objects for each of the courses you are taking this semester. Next create two Student objects. Use the course objects you created to populate the courseLists for the two student objects. Demonstrate the various methods of the Student class.
Explanation / Answer
import java.util.Arrays;
public class Course {
int course_id;
String courseName;
int credits;
String InstructorName;
static int NextId=1000;
public int getCourse_id() {
return course_id;
}
public String getCourseName() {
return courseName;
}
public int getCredits() {
return credits;
}
public String getInstructorName() {
return InstructorName;
}
@Override
public String toString() {
return "Course id ->"+course_id+"Course Name "+courseName+"Credits "+credits+"Instructor name "+InstructorName;
}
class Student
{
int studentID;
String name;
float GPA;
String gender;
Course courseList[];
public Student()
{
studentID=NextId++;
}
@Override
public String toString() {
return "Student [studentID=" + studentID + ", name=" + name + ", GPA="
+ GPA + ", gender=" + gender + ", courseList="
+ Arrays.toString(courseList) + "]";
}
}
public static void main(String[] args) {
Course cr=new Course();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.