Starting from:

$30

EECS1022-Lab 3 Simple Loops Solved

Task 1: Complete Weekly Java Tutorial Videos
•   For Lab3, you are assigned to study Week 4 Part A to Part E of the Java tutorial series:

https://www.youtube.com/playlist?list=PL5dxAmCmjv_4yEdqdvaQH4LppQvGstofS To reference tutorial videos from the previous weeks, see:
 
https://www.youtube.com/playlist?list=PL5dxAmCmjv_6wy2m0yq2wObIWPz4tAxW6
 
These Java tutorial videos assigned to you are meant for you to:

1.   Obtain extra hands-on programming experience on Java, supplementing your weekly lectures.

2.   Complete the lab assignment with the necessary skills and background.

Though we do not require the submission of the weekly Java tutorial project (like in Lab0), examples and insights discussed in these tutorials will be covered in your (written and programming) tests and exam: should you decide to skip the weekly tutorial videos, it would be your choice.

As you study through the example Java classes in the tutorial videos, you are advised to type them out (but absolutely feel free to add new Java classes to experiment) on Eclipse.

•   You can find the iPad notes of illustrations from the tutorial videos here:

https://www.eecs.yorku.ca/˜jackie/teaching/tutorials/notes/EECS1022%20Tutorial%20on%20Java.pdf


2         Task 2: Complete Programming Exercises
Starting Task 2 should mean that you have already completed the weekly Java tutorial videos (Section 1).

2.1             Step 1: Download and Import the Starter Project
1.   Download the Eclipse Java project archive file from eClass: EECS1022W21Lab3.zip

2.   Launch Eclipse and browse to EECS1022-W21-workspace as the Workspace then click on Launch, e.g.,

 

3.3 Choose Select archive file. Make sure that the EECS1022W21Lab3 box is checked under Projects.

 

2.2         Step 2: Programming Tasks
From the Package Explorer of Eclipse, your imported project has the following structure.

•   You can manually test the assigned methods using the corresponding console application classes in package consoleapps. These classes are completed and given to you. See below for more descriptions.

•   Your goal is to pass all JUnit tests given to you (i.e., a green bar). To run them, as shown in the Java tutorials on Week 1, right click on TestUtilities.java and run it as JUnit tests. Of course, none of the given tests would pass to begin with.

 

How to Deal with a Failed JUnit Test? From the JUnit panel from Eclipse, click on the failed test, then double click on the first line underneath Failure Trace, then you can see the expected value versus the return value from your utility method.

 

2.2.1                                                        getNumbers
You are asked to implement a utility method which takes two integer bounds (lower and upper) and

returns a string consisting of all numbers between the two bounds, inclusively.

Requirement. It is strictly forbidden for you to use arrays or any library class (e.g., ArrayList). Violating this requirement will cause a 50% penalty on your lab marks.

Testing. Your goal is to pass all tests related to this method in the JUnit test class TestUtilities. These tests document the expected values on various cases: study them while developing your code. However, use the console application class GetSequenceApp if you wish (e.g., use the input and expected values from the JUnit tests). Here are two example runs:

Enter an integer lower bound: 88

Enter an integer upper bound:

88

1 number between 88 and 88: <[88]


Enter an integer lower bound: 23

Enter an integer upper bound:

28

6 numbers between 23 and 28: <{23}, (24), [25], {26}, (27), [28]


Todo. Implement the Utilities.getNumbers method. See the comments there for the input parameters and requirements. The String return value must conform to the expected format:

•   There are two possible errors: 1) when not both bounds are non-negative (≥ 0); and 2) when the lower bound is not less than or equal to the upper bound.

What if both error conditions hold simultaneously (e.g., lower 5 and upper -3, lower -3 and upper -5)?

In this case, error condition 1) takes the priority. That is, error condition 2) should only be checked when condition 1) is not the case (i.e., both bounds are non-negative). See the JUnit tests.

•   Notice that the second word in the output may be either singular (number) or plural (numbers, when there are more than one numbers in the sequence).

•   Each number in the sequence is wrapped differently: wrapped by round parentheses if the number is a multiple of 3 (e.g., (24)); wrapped by square brackets if the number is some multiple of 3 plus one (e.g., [25]); and wrapped by a pair of curly braces if the number is some multiple of 3 plus two (e.g., {26}).

•   All wrapped numbers are separated by commas (,). There is one space after each comma.

2.2.2                                                           getIntermediateStats
You are asked to implement a utility method which takes as inputs the first term (ft), common

difference (d), and size (n) of an arithmetic sequence. Based on these three input values, the corresponding arithmetic sequence (of n terms) is:

                                                 ht1, t2, t3, ...,tni                      where ti = ft + (i − 1) · d and 1 ≤ i ≤ n

The utility method should return a string value containing the following equal-sized sequence of statistical items:

hs1, s2, s3, ..., sni

where each statistical item si (1 ≤ i ≤ n) reports the sum and average of the sub-sequence ht1, ..., tii (of size i). For example, the statistical item s3 reports the sum and average of the sub-sequence ht1, t2, t3i (which, of course, is just a smaller arithmetic sequence).

Requirement. It is strictly forbidden for you to use arrays or any library class (e.g., ArrayList). Violating this requirement will cause a 50% penalty on your lab marks.

Testing. Your goal is to pass all tests related to this method in the JUnit test class TestUtilities. These tests document the expected values on various cases: study them while developing your code. However, use the console application class GetIntermediateStatsApp if you wish (e.g., use the input and expected values from the JUnit tests). Here is an example run:

Enter the first integer term of an arithmetic sequence: 23

Enter the common difference of the sequence: 11

Enter the size of the sequence:

2

{[sum of <23: 23 ; avg of <23: 23.00], [sum of <23, 34: 57 ; avg of <23, 34: 28.50]}
Todo. Implement the Utilities.getIntermediateStats method. See the comments there for the input parameters and requirements. The String return value must conform to the expected format:

•   All statistical terms are wrapped within curly braces ({}) and separated by commas (,).

•   Each statistical term is wrapped within square brackets ([]) and reports the sum and average of the corresponding sub-subsequence.

•   Each sum is an integer and each average should be formatted as a floating-point number with 2 digits after the decimal point, using String.format(%.2f, someNumber).

•   In the above example, the arithmetic sequence implied by the three input values (23, 11, and 2) is h23, 34i, and the output string contains the statistical items for the two sub-sequences: h23i and h23, 34i.

•   As a slightly longer example, consider the statistical terms that should be included in the output string by input values 23 (first term), 11 (common difference), and 5 (size):

[sum of <23: 23 ; avg of <23: 23.00]

[sum of <23, 34: 57 ; avg of <23, 34: 28.50]

[sum of <23, 34, 45: 102 ; avg of <23, 34, 45: 34.00]

[sum of <23, 34, 45, 56: 158 ; avg of <23, 34, 45, 56: 39.50]

[sum of <23, 34, 45, 56, 67: 225 ; avg of <23, 34, 45, 56, 67: 45.00]

All five statistical items above should be wrapped within curly braces ({}) and separated by commas (,).

•   There is one space before and after the semicolon (;).

•   There is one space after each comma (,) and colon (:).

2.2.3                                                           getInterlevaings
You are asked to implement a utility method which takes as inputs the first terms (f1, f2), common

differences (d1, d2), and sizes (n1, and n2) of two arithmetic sequences. The utility method should return a string value containing a new sequence interleaving items drawn from the two arithmetic sequences. The interleaving starts from an item drawn from the first sequence, if it is not empty. For example, consider two arithmetic sequences with the same length: h3, 8i and h11, 4i. Their interleaving is then h3, 11, 8, 4i, where the 1st and 3rd items are drawn from the first arithmetic sequence, and the 2nd and 4th items are drawn from the second arithmetic sequence. In general, your implementation of the utility method should consider when the two arithmetic sequences are of different lengths (in which case the last items in the interleaving should be drawn from the longer arithmetic sequence).

Requirement. It is strictly forbidden for you to use arrays or any library class (e.g., ArrayList). Violating this requirement will cause a 50% penalty on your lab marks.

Testing. Your goal is to pass all tests related to this method in the JUnit test class TestUtilities. These tests document the expected values on various cases: study them while developing your code. However, use the console application class GetInterleavingsApp if you wish (e.g., use the input and expected values from the JUnit tests). Here are two example runs:

Enter the first integer term of arithmetic sequence 1: 3

Enter the common difference of the sequence: 5

Enter the size of the sequence:

2

Enter the first integer term of arithmetic sequence 2: 11

Enter the common difference of the sequence: -7

Enter the size of the sequence:

2

<(3), [11], (8), [4]


Enter the first integer term of arithmetic sequence 1: 3

Enter the common difference of the sequence: 5

Enter the size of the sequence:

1

Enter the first integer term of arithmetic sequence 2: 11

Enter the common difference of the sequence: -7

Enter the size of the sequence:

3

<(3), [11], [4], [-3]


Todo. Implement the Utilities.getInterlevaings method. See the comments there for the input parameters and requirements. The String return value must conform to the expected format:

•   All interleaved items should be wrapped within angle brackets (<) and separated by commas (,). There is one space after each comma.

•   Items drawing from the first arithmetic sequence should be wrapped within round parentheses (e.g., (3)).

•   Items drawing from the second arithmetic sequence should be wrapped within square brackets (e.g., [11]).

More products