FinalExamPart2-Programming
FinalExamPart2-Programming
Please carefully read the instructions below and ensure that you submit your project on time.
Question Types:
There will be 5 programming questions, covering the following topics:
Exception Handling
GUI - JavaFX
Submission Deadline:
This part is due on Saturday, May 14th, by 11:59 PM.
Submission Format:
All code and explanations should be documented in a Word document. Each question should
have its own section, including the code and screenshots of your program's output.
Screenshot Requirements:
Be sure to include screenshots of the output for each program in your document. This will aid in
better understanding and evaluation.
Important Notes:
We wish you the best of luck with your programming exam! If you have any questions or need
clarification on any aspect of the project, feel free to reach out to me.
Happy coding!
Sincerely,
Xiaojin Ye
Question 1: Write a Java program that:
Requirements
Example Outputs
Example 1:
Input:
Enter numerator: 10
Enter denominator: 2
Output:
Result: 5
Program completed.
Example 2:
Input:
Enter numerator: 10
Enter denominator: 0
Output:
Error: Division by zero is not allowed.
Program completed.
Example 3:
Input:
Enter numerator: ten
Enter denominator: two
Output:
Error: Please enter valid integers.
Program completed.
Your Task: Write and test the Java program to meet the above requirements.
Code template: (You can edit the code for your answer)
import java.util.Scanner;
try {
// Write your code here to perform division and print the result
} catch (ArithmeticException e) {
} catch (NumberFormatException e) {
} finally {
}
Question 2: Write a Java program to demonstrate the use of multiple catch blocks for handling
exceptions.
Requirements
Example Outputs
Example 1:
Array: {30, 20, 10, 40, 0, 50}
Output:
Division is 3
Index out of bounds.
End of program.
Example 2:
Array: {30, 20, 0, 40, 0, 50}
Output:
Code Template:
public class MultipleCatch {
public static void main(String[] args) {
try {
// Perform division and access array elements here
} catch (ArithmeticException e) {
} catch (ArrayIndexOutOfBoundsException e) {
// Handle invalid index exception
} finally {
// Print final message
}
}
}
Question 3: Write a JavaFX application that meets the following requirements: