Question
Use JUnit to create Unit Tests for the following Courses class: Courses.java import java.util.ArrayList; import java.util.Iterator; import java.util.stream.Stream; import java.util.*; public class Courses { ArrayList
Use JUnit to create Unit Tests for the following Courses class:
Courses.java
import java.util.ArrayList;
import java.util.Iterator;
import java.util.stream.Stream;
import java.util.*;
public class Courses {
ArrayList
void loadCourses() {
courses.add(new Course("COSC", "111", "Computer Programming I ",
"Introduction to the design, implementation, and understanding of computer programs. Topics include problem solving, algorithm design, and data and procedural abstraction, with emphasis on the development of working programs. ",
"Prerequisite: A score of 70% or higher in one of PREC 12, MATH 12, MATH 125."));
courses.add(new Course("COSC", "121", "Computer Programming II ",
"Advanced programming in the application of software engineering techniques to the design and implementation of programs manipulating complex data structures. ",
"Prerequisite: A score of 60% or higher in COSC 111"));
courses.add(new Course("COSC", "122", "Computer Fluency ",
"Introduction to computer skills (electronic communication, websites, Internet, document editing, programming, data analysis using spreadsheets/databases) and concepts (information representation, abstraction, algorithmic thinking). Course objectives are life-long productivity and understanding of technology in society ", "Prerequisite: none"));
courses.add(new Course("COSC", "222", "Data Structures ",
"Introduction to the design, implementation and analysis of data structures. Topics will include lists, stacks, queues, trees, and graphs. ",
"Prerequisite: A score of 60% or higher in COSC 121"));
}
public void listAll() {
Course c;
for (int i = 0; i < courses.size(); i++) {
c = courses.get(i);
System.out.println(c.accr + " " + c.number + " " + c.title + " " + c.desc + " " + c.prereq);
}
}
void displayCourse(String number) {
Course c;
for (int i = 0; i < courses.size(); i++) {
c = courses.get(i);
if (c.number.equals(number)) {
System.out.println(c.accr + " " + c.number + " " + c.title + " " + c.desc + " " + c.prereq);
return;
}
}
}
public void listAllIter() {
Iterator
Course c;
while (iterator.hasNext()) {
c = iterator.next();
System.out.println(c.accr + " " + c.number + " " + c.title + " " + c.desc + " " + c.prereq);
}
}
public void listAllStream() {
Stream
stream.forEach(
c -> System.out.println(c.accr + " " + c.number + " " + c.title + " " + c.desc + " " + c.prereq));
}
public void storedStreams() {
Stream
long count = stream.count();
System.out.println("There are " + count + " Courses stored");
}
public void database() {
Course c;
for (int i = 0; i < courses.size(); i++) {
if (courses.get(i).desc.contains("database")) {
c = courses.get(i);
System.out.println(c.accr + " " + c.number + " " + c.title + " " + c.desc + " " + c.prereq);
}
}
}
public void listNumbered() {
courses.sort(new Comparator
@Override
public int compare(Course o1, Course o2) {
// TODO Auto-generated method stub
return o1.number.compareTo(o2.number);
}
});
listAll();
}
public static void main(String[] args) {
Courses L = new Courses();
L.loadCourses();
L.listAll();
System.out.println("");
L.listAllIter();
System.out.println("");
L.listAllStream();
System.out.println("");
L.storedStreams();
System.out.println("");
L.database();
System.out.println("");
L.listNumbered();
}
}
Course.java
//extend/modify as needed to complete the lab
public class Course {
String accr, number, title, desc, prereq;
public Course(String accr, String number, String title, String desc, String prereq) {
this.accr = new String(accr);
this.number = new String(number);
this.title = new String(title);
this.desc = new String(desc);
this.prereq = new String(prereq);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started