Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Object Oriented Programming - Java 1) Create a frame as follows: x Calculator Enter Numarator Enter Denominator Result CALCULATE CLEAR There are 3 labels, 2
Object Oriented Programming - Java
1) Create a frame as follows: x Calculator Enter Numarator Enter Denominator Result CALCULATE CLEAR There are 3 labels, 2 textfields, 2 buttons and 1 textarea. If user fills the fields and clicks on calculate button, write a calculate() method to calculate the result of the operation. If the user makes a mistake, the program catches and handles the exception. If the user enters a zero denominator, an ArithmeticException occurs. If the user enters a string as a denominator, NumberFormatException occurs. If user clicks on "Clear" button all the fields should be cleared. For each exception, the user is informed of the mistake and asked to try again as in the following figures: a) Write try, catch in action of Calculate button. b) Write try, catch inside the method. Calculator X Calculator Enter Numarator 10 Enter Numarator 10 Enter Denominator hello Enter Denominator Result Result CALCULATE Exception:java.lang.NumberFormatException: For input string: "hello" You must enter integers. Please try again. CALCULATE Exception:java.lang. ArithmeticException: / by zero Zero is an invalid denominator. Please try again CLEAR CLEAR Calculator Enter Numarator 10 Enter Denominator 2 MA Result Result: 10/2 = 5 CALCULATE CLEAR Serialization: Serialization involves saving the current state of an object to a stream, and restoring an equivalent object from that stream. The stream functions as a container for the object. Its contents include a partial representation of the object's internal structure, including variable types, names, and values. The information stored in the container can later be used to construct an equivalent object containing the same data as the original. For an object to be serialized, it must be an instance of a class that implements either the Serializable or Externalizable interface. Both interfaces only permit the saving of data associated with an object's variables. They depend on the class definition being available to the Java Virtual Machine at reconstruction time in order to construct the object. The Serializable interface relies on the Java runtime default mechanism to save an object's state. Writing an object is done via the writeObject() method in the ObjectOutputStream class (or the ObjectOutput interface). Writing a primitive value may be done through the appropriate writeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started