Introduction

In this assignment, we'll assess the following skills,

  • Defining a class from scratch given the JUnit tests and specs.
  • Completing method definitions given JUnit tests.
  • Writing JUnit tests and completing methods based on those.

Starting point

Starting point is provided in comp1010_s1_2020_assignment_2_template.zip.

It IS full of compilation errors because Point class isn't implemented. That's your first task. So, read on :)

Stage 1 - Point.java

The Point class represents a point in a 2-dimensional plane. For the sake of simplicity, we limit points to the first quadrant where the x and y coordinates are non-negative.

You should start by studying the test file PointTest.java and making notes. See which are the variables being accessed and what is the type of values they are being compared against. For example, if there is something like:

Student s = new Student("Ginny", 87);
assertEquals(87, s.mark);

It indicates that the class Student has an instance variable mark of type int (otherwise the assertion would be assertEquals(87, s.mark, 0.001); where 0.001 is the tolerance.

The JUnit tests have comments where required. Study those comments. One thing I will recommend is to do the following in given order.

  • identify and add instance variables
  • add default constructor
  • add parameterized constructor (the one with the two parameters). Especially, since other tests assume the constructor is implemented correctly.

You can implement getPathToOrigin recursively. And I suggest you give that a shot.

Stage 2 - Polygon.java

For our purpose, a polygon is a collection of points and straight lines connect each adjacent point in the array (where the last and first item are considered adjacent points as well).

So, a polygon from (1,1) to (4,1) to (2, 3) to (5, 2) (and back to 1, 1) is a Polygon , and has two edges intersecting, which is fine. For more details, see the following and feel free to do your own research.

https://en.wikipedia.org/wiki/Polygon https://www.mathsisfun.com/definitions/polygon.html

Note that the tests for Polygon are not provided. You can use the following input output mappings.

  • circumference of a polygon (1,1) -> (3,1) -> (2,2), and back to (1,1),is 4.828
  • circumference of a polygon (1,1) -> (3,1) -> (7,5) -> (0,2), and back to (1,1), is 16.686
  • longestSide of a polygon (1,1) -> (3,1) -> (2,2), and back to (1,1),is 2
  • longestSide of a polygon (1,1) -> (3,1) -> (7,5) -> (0,2), and back to (1,1), is 7.615

Stage 3 - Line.java

This class contains only one method - getPointsOnCrosshair, which is our question.

Creating helper methods

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.