Untitled

 avatar
unknown
java
a year ago
2.4 kB
6
Indexable
import java.*;

public class Student {
	private int stId;
	private String name;
	private Course courses[] = new Course[3];
	
	public Student() {
		this.stId = 123;
		this.name = "fr, tbh, ngl";
		for(int i = 0; i< this.courses.length; i++) {
			if(this.courses[i] == null) {
				this.courses[i] = new Course();
			}
		}
	}
	
	public Student(int stId, String name, Course courses[]) {
		this.stId = stId;
		this.name = name;
		
		for(int i = 0; i< this.courses.length; i++) {
			if(this.courses[i] == null) {
				this.courses[i] = courses[i];
			}
		}
	}
	
	public void setCourses(Course courses[]) {
		for(int i = 0; i < this.courses.length; i++) {
			if(this.courses[i] == null) {
				this.courses[i] = courses[i];
			}
		}
	}
	
	public Course[] getCourses() {
		return this.courses;
	}
	
	public void showDetails() {
		System.out.printLn("----- Student Details -----");
		System.out.printLn("Student ID" + this.stId);
		System.out.printLn("Student Name" + this.name);

		for(int i = 0; i < this.courses.length; i++) {
			if(this.courses[i] != null) {
				courses[i].showDetails();
			}
		}
	}
}



// Course



import java.*;

public class Courses {
	private int courseCode;
	private String courseName;
	private Student students[] = new Student[4];
	
	public Courses() {
		this.courseCode = 123;
		this.courseName = "fr, tbh, ngl";
		for(int i = 0; i< this.students.length; i++) {
			if(this.students[i] == null) {
				this.students[i] = new Student();
			}
		}
	}
	
	public Courses(int stId, String name, Course students[]) {
		this.courseCode = stId;
		this.courseName = name;
		
		for(int i = 0; i< this.students.length; i++) {
			if(this.students[i] == null) {
				this.students[i] = students[i];
			}
		}
	}
	
	public void setStudents(Student students[]) {
		for(int i = 0; i < this.students.length; i++) {
			if(this.students[i] == null) {
				this.students[i] = students[i];
			}
		}
	}
	
	public Student[] getStudent() {
		return this.students;
	}
	
	public void showDetails() {
		System.out.printLn("----- Course Details -----");
		System.out.printLn("Course ID" + this.courseCode);
		System.out.printLn("Course Name" + this.courseName);
		
		for(int i = 0; i < this.students.length; i++) {
			if(this.students[i] != null) {
				students[i].showDetails();
			}
		}
	}
}
Editor is loading...
Leave a Comment