Assessment #2 Submission deadline: 21st November 2022 (5:00pm MYT) via Moodle
Instructions Below are the coding tasks that you need to complete for assessment 2. Your work and your submission should be independent. Please download the IntelliJ project folder below and unzip it. This will provide you with a partial code in which to program your answers. Please complete each task in the appropriate section of the partial code, and submit upon completion.
File Assessment2.zip This assessment is worth 6% of the unit total. It contains 60 marks and is comprised of the following components:
Code correctness has is worth 50 marks
Task 1 is worth 17 marks
Task 2 is worth 7 marks
Task 3 is worth 10 marks
Task 4 is worth 9 marks
Task 5 is worth 7 marks
Code readability & documentation is worth 5 marks
Code development is worth 5 marks
Academic Integrity Please be reminded of the academic integrity mentioned in Week 01. You should code alone and ask the unit staff for help if needed. Do not post your code in public forums or send your code to anyone.
HOW TO TEST YOUR ☕️ JAVA CODE YOU HAVE WRITTEN?
Task 1 (W3 - 17 marks) Please implement your code in the method labelled task1() method in the Assessment2 class project.
Implement a code expression that checks the value of an integer variable, "n", and returns true if n is between 1 to 100 (inclusive) but not an even integer between 40 to 50 (inclusive).
Design a set of test values and use these to test that your code expression works as expected.
The output should have the following format: "For the number n the value is true/false."
Examples:
For n=2, the output should be "For the number 2 the value is true."
For n=40, the output should be "For the number 40 the value is false."
Task 2 (W3 - 7 marks) Please implement your code in the method labelled task2() method in the Assessment2 class project.
The assignment operator allows you to assign the value of one variable to another variable but how can you swap the values in two variables? Write code that declares and initializes 2 boolean variables and then swaps their values. You must do this using only variables. Use System.out.println() to print the values of each variable before and after the swap.
Hint: you can use additional variables if needed.
Task 3 (W3 - 10 marks) Please implement your code in the method labelled task3() method in the Assessment2 class project.
An engineer was asked to estimate some measurements for a client. The client wants to know an off-the-cuff estimate on how many stone slabs would be needed to fill the land area between two buildings. The dimensions of the stone slabs are 1m by 1m, however they can be cut down if required. The engineer was able to use an app on his smartphone to visually estimate some angles between the buildings, shown below.
Angle alpha, between the base of building B to the top of building A, is estimated as 53.13°
Angle beta, from the base of building A to the top (on the opposite side) of building A, is estimated as 41.00°
The height of both buildings is reported as 20.00m
Please implement code that is able to solve the problem and find out how many stone slabs are required (rounded to the next largest whole number). You only have to consider the area of the space that needs to be filled.
Hint: Note that to get the distance between Building A & B and the length of building A, you need to apply the Law of Tangents. You will need Math.PI, Math.tan() and Math.ceil() from the Java Math library. Note also that the angles given are in degrees and you may need to convert them to radians first.
Task 4 (W3 - 9 marks) Please implement your code in the method labelled task4() method in the Assessment2 class project. Please declare 2 variables of type int, x and y, and input their values from the keyboard using the Scanner Class. Compute the result of applying the "bitwise and (&)" and "bitwise exclusive OR (^)" operators on these integers and print each output separately using System.out.println(). Explain step by step how the results were obtained as inline comments.
Task 5 (W4 - 7 marks) Please implement your code as a new method in the Assessment2 class project.
Code a method called volumeOfACylinder that returns the volume of a cylinder. The method should accept variables (radius and height) from the main method and return the computed volume to the main method.
Please carefully consider how many variables the method should accept with appropriate data type as well as the return type of the final value. The formula for the volume of a cylinder is as shown below.
The method should print the result of the equation above using System.out.println()
Hint: You will need to use Math.PI from the Java Math library.
Once done, test your method by calling it from the main class to ensure it is working as expected.
Code Readability (5 marks) Overall code submission must be well organised and very easy to follow including, but not limited to, code indentation, code consistency, effective use of whitespace etc.
Code Development & Documentation (5 marks) Overall code submission should demonstrate correct syntax usage and meaningful naming conventions. Code documentations/inline comments should be thorough and detailed.
Submission Instruction Please submit your IntelliJ project folder as a .zip file and submit to Moodle as shown below. If you are not sure how to zip your project, please refer to the video here.