Starting from:

$30

EECS1022-Lab 1 Elementary Programming Solved

1         Task 1: 
•    For Lab1, you are assigned to study Week 2 Part A to Part G of the Java tutorial series:

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.

Parts A to E are directly relevant to this lab. Parts F and G are relevant to your Lab2.

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: EECS1022W21Lab1.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 EECS1022W21Lab1 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.

 

2.2.1       Method to Implement: getGeometricSequence
Problem.        You are asked to consider a geometric sequence (of integer values) of length 5.

ha1, a2, a3, a4, a5i

where a1, the start of the sequence, is called the first term. In a geometric sequence, there is a common ratio r between every two adjacent terms:

                                                                                                          2 ≤ i ≤ 5

For example, h6, 12, 24, 48, 96i is a geometric sequence with 6 being the first term, 2 being the common ratio, and 5 being the length.

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 GeometricSequenceApp if you wish (e.g., use the input and expected values from the JUnit tests). Here is an example run:

Enter the first term of a geometric sequence (of size 5):

3

Enter the common ratio of the geometric sequence: 2

[3][6][12][24][48] has average 18.6
Todo. Implement the Utilities.getGeometricSequence method. See the comments there for the input parameters and requirements. The String return value must conform to the expected format.

2.2.2       Method to Implement: getBMI
Problem. You are asked to compute the Body Mass Index (BMI), which is a measure of health based on height and weight specified in metric units (i.e., meters and kilograms, respectively). Given a user weighting k kilograms and who is m meter tall, their BMI is calculated as:   (i.e., weight divided by the square of height). Once the BMI is calculated, one may consult with the following table to interpret the result:

                                                                                  BMI Range                  Interpretation

BMI < 18.5
Underweight
18.5 ≤ BMI < 25.0
Normal
25.0 ≤ BMI < 30.0
Overweight
30.0 ≤ BMI
Obese
For this exercise, you are only asked to compute the BMI without interpreting it as specified above. Users of your program, however, will specify a weight in pounds and a height in inches, meaning that you need to consider the following conversions:

•    1 pound is equivalent to 0.4536 kilograms

•    1 inch is equivalent to 0.0254 meters

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 BMIApp if you wish (e.g., use the input and expected values from the JUnit tests). Here is an example run:

Enter your name: Jim

Jim, enter a non-negative floating-point number of your weight (in pounds): 223.5

Jim, enter a non-negative floating-point number of your height (in inches):

68.77

Jim, your BMI is: 33.22653789251047
Todo. Implement the Utilities.getBMI method. See the comments there for the input parameters and requirements. The double return value needs no formatting, but it must be within a tolerance range of 0.1 against the expected value. You can also play with calculations using this web-based BMI calculator here: https://www.nhlbi.nih.gov/health/educational/lose_wt/BMI/bmicalc.htm

2.2.3       Method to Implement: getTimeConversion
Problem. You are asked to convert a given (non-negative) integer number of seconds and convert it into its equivalent formatted in terms of days, hours, minutes, and seconds.

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 TimeConversionApp if you wish (e.g., use the input and expected values from the JUnit tests). Here is an example run:

Enter a non-negative integer number of seconds:

10000

0 days 2 hours 46 minutes 40 seconds
Todo. Implement the Utilities.getTimeConversion method. See the comments there for the input parameters and requirements. The String return value must conform to the expected format (e.g., words days, hours, minutes, and seconds are always in their plural form). Of course, in the output, the maximum values that can appear for hours, minutes, and seconds are, respectively, 23, 59, and 59.




More products