EECS2030 – Assignment 1 - Summer 2021


Please submit your answers before Jun 2nd at 23:59 EST. Use the similar approach explained in Quiz0 to submit your code (e.g., https://webapp.eecs.yorku.ca/submit?acadyear=2020-21&term=S&course=2030&assignment=a1&ppy):


Make sure to use the exact below names for your answers:

• Q1.txt

• Q2.txt

• Q3.txt

• Fibonacci.java

○ and Q4.txt (if you like to explain anything in Q4)


Question 1 (20%): Given the one-line code below for a Java class, which of the following will produce a compile-time error and why?

public class B{}

1. B b = new B(); System.out.println(b);

2. B b = new B(); b.equals(“”);

3. B b = new B(); System.out.println(b.toString());

4. B b = new B(); System.out.println(b.getType ());


Question 2 (20%): Which one of the following can be a valid method overload for public static double kilometresToMiles (double k) and why?

1. public static double kilometresToMiles (double kilometres)

2. private static double kilometresToMiles (double k)

3. public static float kilometresToMiles (float k)

4. public static float kilometresToMiles (double k)


Question 3 (20%): Which one of the following is not correct in respect to Loop Invariants (LI) and why?

1. LI is an expression that holds true at the end of every iteration of the loop.

2. LI does not necessarily appear in the code.

3. LI is an expression that holds true at the beginning of every iteration of the loop.

4. LI typically is used for testing purposes and to prove correctness.


Question 4 (40%): Using Java programing language, create a utility class (Fibonacci.java) that computes the Fibonacci number n using an iterative approach. Make sure code is fully commented, compiles, and run correctly.