Compulsory Task 1 Answer the following questions: yperionDev • Design a class called Course. The class should contain: o The data fields courseName (String), numberOfStudents (int) and courseLecturer (String). A constructor that constructs a Course object with the specified courseName, numberOfStudents and courseLecturer. The relevant get and set methods for the data fields. A toString() method that formats that returns a string that represents a course object in the following format: (courseName, courseLecturer, numberOfStudents) • Create a new ArrayList called courses, add 5 courses to it and print it out. • Sort the List according to the numberOfStudents and print it out. • Swap the element at position 1 of the List with the element at position 2 and print it out. • Create a new ArrayList called courses2. • Using the addAll method add 5 courses to the courses2 List and print it out. • Copy all of the courses from courses into courses2 • Add the following two elements to courses2: Java 101, Dr. P Green, 55) (Advanced Programming, Prof. M Milton, 93) • Sort the courses in courses2 alphabetically according to the course name and print it out. • Search for the course "Java 101" in courses and print out the index of the course in the List. • Use the disjoint function to determine whether courses and courses2 have any elements in common and print out the result. Copyright © 2021 Hyperion Dev. All rights reserved. In courses2, find the course with the most students and the course with the least students and print each out.
Compulsory Task 1 Answer the following questions: yperionDev • Design a class called Course. The class should contain: o The data fields courseName (String), numberOfStudents (int) and courseLecturer (String). A constructor that constructs a Course object with the specified courseName, numberOfStudents and courseLecturer. The relevant get and set methods for the data fields. A toString() method that formats that returns a string that represents a course object in the following format: (courseName, courseLecturer, numberOfStudents) • Create a new ArrayList called courses, add 5 courses to it and print it out. • Sort the List according to the numberOfStudents and print it out. • Swap the element at position 1 of the List with the element at position 2 and print it out. • Create a new ArrayList called courses2. • Using the addAll method add 5 courses to the courses2 List and print it out. • Copy all of the courses from courses into courses2 • Add the following two elements to courses2: Java 101, Dr. P Green, 55) (Advanced Programming, Prof. M Milton, 93) • Sort the courses in courses2 alphabetically according to the course name and print it out. • Search for the course "Java 101" in courses and print out the index of the course in the List. • Use the disjoint function to determine whether courses and courses2 have any elements in common and print out the result. Copyright © 2021 Hyperion Dev. All rights reserved. In courses2, find the course with the most students and the course with the least students and print each out.
Chapter8: Arrays
Section: Chapter Questions
Problem 7PE
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage