EECS030 Lab 02

Thu Sep 15, Mon Sep 19, and Tue Sep 20

Due date:
ALL SECTIONS: Tue Oct 4 before 23:59

Introduction

The goals of this lab are to:

2-dimensional vectors

This lab assumes that you are familiar with 2-dimensional spatial vectors. If you are not familiar with the basic mathematical operations that can be performed using vectors you should review the material found in this tutorial.

Getting started

To get started, you should do the following in eclipse:

  1. Create a new package called eecs2030.lab2
  2. In the package eecs2030.lab2 create a new Java class named Vector2. Replace the automatically created contents of Vector2 with the contents of this file. Use cut-and-paste, don't try typing it all in!
  3. Create a new class for the unit tester. Do this by right-clicking on Vector2.java in the Package Explorer on the left-hand side of the eclipse IDE, and selecting New -> JUnit test case. A dialog window will appear with the title New JUnit Test Case; the name of the test case should be Vector2Test. Click the Finish button.
  4. Replace the automatically created contents of Vector2Test with the contents of this file. Use cut-and-paste, don't try typing it all in!

 

Inspect the API

  1. Study the API for Vector2. Recall that the API for a class typically shows all of the public features of a class. You should see that Vector2 has three constructors, four static methods, and thirteen non-static methods. Make sure that you understand the API for each method.

 

Add the constructors

  1. To the class Vector2, add the three constructors. Recall that the job of a constructor is to set the values of the fields of the object that is being constructed. In this case, your constructors should set the values of this.x and this.y; this task is very similar to the task you completed last week for the Point2 class.
  2. Use the unit tester to test your constructors as you complete them.

 

Add the methods

  1. Add the methods of the class one at a time. Read the API of each method to guide your implementation.
  2. Use the unit tester to test your methods as you complete them.

 

Make a picture

The Koch snowflake is an example of a fractal curve; the shape of the curve appears the same no matter how far you zoom in on the curve. Wikipedia page presents a concise description of the Koch snowflake with some interesting illustrations of the snowflake and related curves.

The Vector2 class can be used by a second class (which you might implement in a future lab) to draw an approximation of the Koch snowflake (actually six overlapping snowflakes).

  1. Download this jar file and add it to your project:
    1. select the Project menu
    2. select Properties
    3. on the left side of the dialog that appears, select Java Build Path
    4. on the right, select the Libraries tab
    5. click the Add External JARs... button
    6. add the jar file you downloaded
  2. Add a new class named KochSnowflake to the eecs2030.lab2 package. Replace the automatically created contents of KochSnowflake with the contents of this file.
  3. Run the program to generate an image of the Koch snowflake.

Submit for students NOT working in a group

If you are not working in a group, submit your solution using the submit command. Remember that you first need to find your workspace directory, then you need to find your project directory. In your project directory, your files will be located in the directory src/eecs2030/lab1

submit 2030 lab2 Vector2.java

Submit for students working in a group

If you are working in a group, create a plain text file named group.txt. You can do this in eclipse using the menu File -> New -> File. Type your login names into the file with each login name on its own line. For example, if the students with login names rey, finn, and dameronp, worked in a group the contents of group.txt would be:

rey
finn
dameronp

Submit your solution using the submit command. Remember that you first need to find your workspace directory, then you need to find your project directory. In your project directory, your files will be located in the directory src/eecs2030/lab1

submit 2030 lab2 Vector2.java group.txt

Submit from outside of the lab

The process for submitting from outside of the Prism lab involves the following steps:

  1. transfer the files from your computer to the undergraduate EECS server red.eecs.yorku.ca
  2. remotely log in to your EECS account
  3. submit your newly transferred files in your remote login session
  4. repeat Steps 1 and 3 as required

Windows users will likely need to install additional software first. Mac users have all of the required software as part of MacOS.

Detailed instructions are here.