Please scroll down for latest Programs. 👇
Week 9 : Programming Assignment 1
- int begin;
- int end;
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1
5 | 1\n
4\n
9\n
16\n
25\n
25\n
16\n
9\n
4\n
1 | 1\n
4\n
9\n
16\n
25\n
25\n
16\n
9\n
4\n
1\n
| Passed after ignoring Presentation Error |
Test Case 2 | 9
6 | 81\n
64\n
49\n
36\n
36\n
49\n
64\n
81 | 81\n
64\n
49\n
36\n
36\n
49\n
64\n
81\n
| Passed after ignoring Presentation Error |
Week 9 : Programming Assignment 2
Complete the code segment to catch the exception in the following, if any.
On the occurrence of such an exception, your program should print
§ Please enter valid data
If there is no such exception, it will print the square of the number entered.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2 | 4 | 4 | Passed |
Test Case 2 | q | Please enter valid data | Please enter valid data | Passed |
Week 9 : Programming Assignment 3
The program given below stores characters in a byte array named byte_array, which means ‘A’ is stored as 65.
Your task is the following:
§ Given a user input `n`, print the output in the given format, if `n` = 1, print:
o byte_array[1] = ‘P’
§ If the value of n is negative or is out of bound, then use TRY_CATCH to print the following:
o Array index is out of range
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 0 | byte_array[0] = 'N' | byte_array[0] = 'N' | Passed |
Test Case 2 | -1 | Array index is out of range | Array index is out of range | Passed |
Week 9 : Programming Assignment 4
Define a class Point with members
§ private double x;
§ private double y;
and methods:
§ public Point(double x, double y){} // Constructor to create a new point?
§ public double distance(Point p2){} // Function to return the distance of this Point from another Point
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 0 0
1 1 | 1.4142135623730951 | 1.4142135623730951 | Passed |
Test Case 2 | 0 0
0 5 | 5.0 | 5.0 | Passed |
Week 9 : Programming Assignment 5
Complete the code below with a catch statement to print the following if the denominator (b) is zero
§ Cannot Divide by ZERO
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 6 3 | 2 | 2\n
| Passed after ignoring Presentation Error |
Test Case 2 | 1 0 | Cannot Divide by ZERO | Cannot Divide by ZERO | Passed |
Week 10 : Programming Assignment 1
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 6
-5 -9 8 12 1 3 | Elements of array sorted in ascending order:\n
-9 -5 1 3 8 12 | Elements of array sorted in ascending order:\n
-9 -5 1 3 8 12 | Passed after ignoring Presentation Error |
Week 10 : Programming Assignment 2
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5
6 3 2 1 4
7 8 3 12 9
1 11 10 5 8
5 18 6 9 14
19 23 3 12 11 | 6 3 2 1 4 9 8 14 11 12 3 23 19 5 1 7 8 3 12 5 9 6 18 11 10 | 6 3 2 1 4 9 8 14 11 12 3 23 19 5 1 7 8 3 12 5 9 6 18 11 10 | Passed after ignoring Presentation Error |
Week 10 : Programming Assignment 3
- The PrintNumbers class is declared, and it implements the Runnable interface. This interface is part of Java's concurrency support and is used to represent a task that can be executed concurrently by a thread.
- Create a constructor of this class that takes two private instance variables (start and end) to represent the range of numbers that will be printed by the thread.
- Create a run method that is required by the Runnable interface and contains the code that will be executed when the thread is started. In this case, it should prints odd numbers within the specified range (start to end) using a for loop.
- Hints: Thread.currentThread().getName() returns the name of the currently executing thread, which is useful for identifying which thread is printing the numbers.
Follow the naming convention as given in the main method of the suffix code.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
10
3
7 | EvenThread: 2\n
EvenThread: 4\n
EvenThread: 6\n
EvenThread: 8\n
EvenThread: 10\n
OddThread: 3\n
OddThread: 5\n
OddThread: 7 | EvenThread: 2\n
EvenThread: 4\n
EvenThread: 6\n
EvenThread: 8\n
EvenThread: 10\n
OddThread: 3\n
OddThread: 5\n
OddThread: 7\n
| Passed after ignoring Presentation Error |
Week 10 : Programming Assignment 4
The range value will be positive.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4
13 | 36 | 36\n
| Passed after ignoring Presentation Error |
Week 10 : Programming Assignment 5
- Use exception handling to handle invalid input temperatures (if celsius < -273.15 and fahrenheit < -459.67 , program should throw exception error).
- The TemperatureConverter class contains two methods for temperature conversion (celsiusToFahrenheit and fahrenheitToCelsius).
- The TemperatureException class is a custom exception class that extends Exception and is used to handle invalid temperatures.
- The TemperatureConverterApp class is the main class that takes user input for temperatures and handles potential exceptions during the conversion process.
- celsiusToFahrenheit = (celsius * 9 / 5) + 32
- fahrenheitToCelsius = (fahrenheit - 32) * 5 / 9
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | -278 | Error: Invalid Celsius temperature (below absolute zero) | Error: Invalid Celsius temperature (below absolute zero)\n
| Passed after ignoring Presentation Error |
Test Case 2 | -1
-500 | Temperature in Fahrenheit: 30.2\n
Error: Invalid Fahrenheit temperature (below absolute zero) | Temperature in Fahrenheit: 30.2\n
Error: Invalid Fahrenheit temperature (below absolute zero)\n
| Passed after ignoring Presentation Error |
Test Case 3 | 45
112 | Temperature in Fahrenheit: 113.0\n
Temperature in Celsius: 44.44444444444444 | Temperature in Fahrenheit: 113.0\n
Temperature in Celsius: 44.44444444444444\n
| Passed after ignoring Presentation Error |
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.