Kotlinlearncs.online LogoJava
Return to List

Test Writing: Math Course Inheritance

Created By: Pranav Narayanan
/ Version: 2024.10.0

Write a public class MathCourse which inherits from the existing class Course:

public class Course {
 private String code;
 private String title;
 public Course(String code, String title) {
   this.code = code;
   this.title = title;
 }
 //getters omitted
}

MathCourse should have an additional String field area, which is the branch of math that course pertains to. Provide only a getter for area following the standard naming convention. You should define a MathCourse constructor that accepts parameters for the code, title, and area in that order. Reject null values for area.

MathCourse should also override toString() so that it returns a String of the format: "(code): (title) is in the (area) branch of math."

Test Design Challenge

You're challenge is to write tests for this problem described above.

  • Provide a public class named TestMathCourse with a single non-private class method named test that accepts no arguments and does not return a value.
  • If the implementation of the class described above is incorrect, your test method should throw an exception.
  • If it is correct, do not throw an exception.
  • You may want to use Java's assert method
Report a Problem

Attribution must link to this page: https://www.learncs.online/testtesting/java/math-course-inheritance/[email protected]