Week 5 : Programming Assignment 1
Due on 2023-08-31, 23:59 IST
An interface Number is defined in the following program. You have to declare a class A, which will implement the interface Number. Note that the method findSqr(n) will return the square of the number n.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 | 25 | 25 | Passed |
Week 5 : Programming Assignment 2
Due on 2023-08-31, 23:59 IST
This program is to find the GCD (greatest common divisor) of two integers writing a recursive function findGCD(n1,n2). Your function should return -1, if the argument(s) is(are) other than positive number(s).
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 40 60 | 20 | 20 | Passed |
Test Case 2 | 2 0 | 2 | 2 | Passed |
Test Case 3 | -1 -1 | -1 | -1 | Passed |
Week 5 : Programming Assignment 3
Due on 2023-08-31, 23:59 IST
Complete the code segment to catch the ArithmeticException in the following, if any. On the occurrence of such an exception, your program should print “Exception caught: Division by zero.” If there is no such exception, it will print the result of division operation on two integer values.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4 0 | Exception caught: Division by zero. | Exception caught: Division by zero. | Passed |
Test Case 2 | 10 3 | 3 | 3 | Passed |
Week 5 : Programming Assignment 4
Due on 2023-08-31, 23:59 IST
In the following program, an array of integer data to be initialized. During the initialization, if a user enters a value other than integer value, then it will throw InputMismatchException exception. On the occurrence of such an exception, your program should print “You entered bad data.” If there is no such exception it will print the total sum of the array.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3
5 2 1 | 8 | 8 | Passed |
Test Case 2 | 2
1 1.0 | You entered bad data. | You entered bad data. | Passed |
Week 5 : Programming Assignment 5
Due on 2023-08-31, 23:59 IST
In the following program, there may be multiple exceptions. You have to complete the code using only one try-catch block to handle all the possible exceptions.
For example, if user’s input is 1, then it will throw and catch “java.lang.NullPointerException“.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 | No exception | No exception | Passed |
Test Case 2 | 0 | java.lang.ArithmeticException: / by zero | java.lang.ArithmeticException: / by zero | Passed |
Test Case 3 | 1 | java.lang.NullPointerException | java.lang.NullPointerException | Passed |
No comments