Week 2 Assignment1 OOP
Week 2 Assignment1 OOP
Task 1: Write a program that takes an integer as input and uses an 'if-else' statement to determine if
the number is odd or even. Output 'Odd' if the number is odd, and 'Even' if it is even."
Task 2: Write a program that takes a non-negative integer as input. Calculate and return the sum of
the digits that make up the integer. Handle the case where the input is negative by returning an
appropriate indicator."
Task 3: "Write a function that accepts an integer as input and returns a boolean value (true or false)
indicating whether the input is a prime number. Use the square root optimization to improve
efficiency."
Page 1 of 2
Task 5: "Write a function that accepts a string as input and returns two values: the count of vowels and
the count of consonants. Consider only alphabetic characters and ignore the numeric values.
Task 6: "Create a program that calculates the factorial of a positive integer using a loop. The factorial
of a number 'n' is the product of all positive integers less than or equal to 'n'. For example, 5! = 5 * 4 *
3 * 2 * 1 = 120."
Task 7: Write a program that generates the Fibonacci series up to a given number of terms.
For example, if the user enters 5, the output should be: 0, 1, 1, 2, 3
Task 8: "Mrs. Eleanor Vance, a retired school teacher, walks into your bank branch.
She's interested in opening a fixed deposit account. She tells you she's 68 years old and
wants to deposit $10,000 for one year.
At the same time, a young professional, Mr. David Crane, approaches your desk. He's
35 years old and wants to deposit $5,000 for one year in a similar fixed deposit account.
Questions:
1. Calculate the interest earned by Mrs. Vance and Mr. Crane.
2. What is the total amount (principal + interest) each depositor will have at the end of one
year?
3. Explain the logic (using if-else conditions) that your bank's system would use to
determine the interest rate for each customer.
4. If the bank decided to add a new condition: 'If the deposit amount is over $15,000, an
additional 0.5% interest is added regardless of age.' How would you modify your logic
and calculations to accommodate this new condition? Assume Mrs. Vance deposits
$16,000.
5. Write a java code snippet that implements the logic of the first three questions."
Page 2 of 2