My code uses two classes: Section and Lesson with matching IDs. I want a neat output showing each Section with its related Lesson.
class Section {
int secId;
String title;
List<Lesson> lessonSet;
Section(int secId, String title, List<Lesson> lessonSet) {
this.secId = secId;
this.title = title;
this.lessonSet = lessonSet;
}
public String getSummary() {
return title + " " + lessonSet;
}
}
class Lesson {
int lessonNum;
int secId;
String topic;
Lesson(int lessonNum, int secId, String topic) {
this.lessonNum = lessonNum;
this.secId = secId;
this.topic = topic;
}
public String showTopic() {
return topic;
}
}
class Runner {
public static void main(String[] args) {
List<Lesson> lessons = new ArrayList<>();
lessons.add(new Lesson(101, 1, "Mathematics"));
lessons.add(new Lesson(102, 2, "Literature"));
List<Section> sections = new ArrayList<>();
sections.add(new Section(1, "STEM", lessons));
sections.add(new Section(2, "Arts", lessons));
for (Section s : sections) {
System.out.println(s.getSummary());
}
}
}