Home / Expert Answers / Computer Science / q2-answer-q2-a-q2-e-based-on-java-code-segments-in-figure-q2-a-and-gui-in-figure-q2-b-b-p-pa898

(Solved): Q2 Answer Q2(a) - Q2(e) based on Java code segments in Figure Q2(a) and GUI in Figure Q2(b). (b) p ...



Q2
Answer Q2(a) - Q2(e) based on Java code segments in Figure Q2(a) and GUI in Figure
Q2(b).
(b)
public class Age {
(c)
publi

Q2 Answer Q2(a) - Q2(e) based on Java code segments in Figure Q2(a) and GUI in Figure Q2(b). (b) public class Age { (c) public static void main(String[] args) { int age; age= Integer.parseInt (JOptionPane.showInput Dialog ("How old are you?")); System.out.println("Your age is:" +age); Input ? Figure Q2(a) How old are you? twenty years old OK Cancel Figure Q2(b) (a) If the user enters the input as in Figure Q2(b) and click the OK button, what is the output of the program? Justify your answer. (6 marks) X Apply exception handling for the segment code in Figure Q2(a) by using try.. catch block and showMessageDialog (). (8 marks) With appropriate examples, discuss types of Java exceptions. (6 marks)


We have an Answer from Expert

View Expert Answer

Expert Answer


Part 1 The above program throws an error as the user input is not a valid number. The method throws a NumberFormatException if the string it has been given cannot be parsed into an integer. Part 2 import java.util
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe