Assignment 9 - Methods
Assignment 9 - Methods
Methods
4*10 = 40
2 2 4 Assessment
2*5 = 10
The students must complete the classwork tasks in the lab class to obtain the lab performance
marks. They will also be marked based on the assessment tasks. The lab instructors may
show/explain a few of the classwork tasks to the students if necessary. Any plagiarism in
classwork or homework will lead to the student getting zero in the entire assignment. A random
viva may take place.
Classwork
ClassWork 1
[A,B,C,D should be written in a single java file]
evenChecker(10); Even!!
evenChecker(17); Odd!!
Note: You must call the methods from CW-1B and CW-1C, otherwise this
task would be considered invalid.
ClassWork 2
C. Write a method called findSpace that takes two values in its parameters one
is an integer diameter and another one is a String. Using the given diameter,
this method should calculate the Area of a circle or the Volume of a sphere
depending on the value of the second parameter. Finally, it should print the
result inside the method.
Note: You must call the method written in task CW-2A & CW-2B,
otherwise this task would be considered invalid.
findSpace(10,"circle"); 78.5398
findSpace(10,"sphere"); 523.5987
Area of triangle = [s(sa)(sb)(sc)], where 's' is the semi perimeter of the triangle. So, semi-p
Note: You must call the method written in task Evaluation-A, otherwise
this task would be considered invalid.
Sample Method Call Sample Output Explanation
HomeWork
HomeWork 1
C. Write a method called special_sum that calculates the sum of all numbers
that are either prime numbers or perfect up till the integer value given in its
parameter. This integer value must be taken as user input and passed into the
method.
Note: You must call the methods written in task HW-1A & HW-1B,
otherwise this task will be considered invalid.
HomeWork 2
showDots(5); …..
showDots(3); …
Note: You can use System.out.print() to avoid the next output being
printed on the next line
show_palindrome(5) 123454321
show_palindrome(3) 12321
showDiamond(5) ....1....
...121...
..12321..
.1234321.
123454321
.1234321.
..12321..
...121...
....1....
..1..
.121.
showDiamond(3) 12321
.121.
..1..
HomeWork 3
A. Write a method called calcTax that takes 2 arguments which are your age
then your salary. The method must calculate and return the tax as per the
following conditions:
Note: You must call the method written in task HW-3A, otherwise this task
would be considered invalid.
HomeWork 4
Hint: N is a number taken as input from the user and you need to print the
numbers starting from 1 to N recursively.
N=5 oneToN(1,N); 1 2 3 4 5
N=11 oneToN(1,N); 1 2 3 4 5 6 7 8 9 10 11