Answered step by step
Verified Expert Solution
Link Copied!

Question

00
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

image text in transcribedimage text in transcribed

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 write() method. Reading the serialized object is accomplished using the readObject() method of the objectInputStream class, and primitives may be read using the various read() methods. Write a program that serializes a array list in a binary file, reads it from the binary file and writes it to the text area. Create the following classes: DIS: + doctors: ArrayList Doctor: serializable -id: String -name: String -surname: String -department: String +Doctor (id name.surname dept) +toString(): String + AddToArrayList (Doctor e): void + WriteArrayListtobin (): void + DisplayBin(): String Doctors Doctor ID: Add to ArrayList Name: Write ArrayList To Bin Display the Binary You have 5 labels, 3 buttons, 4 text fields, 1 scroll pane and 1 text area over it. "Add to arraylist" button will create an object of doctor and add to an arraylist type Doctor by calling the AddToArrayList() method. "Write ArrayList to Bin" button will write the Arraylist into a binary file named Doctor_bin by calling WriteArrayListtoBin() method: objo = new ObjectOutputStream (new FileOutputStream("Doctor_bin")); Surname: Department: Display Doctor doctor_id=111 doctor_name=Ceren, doctor_sur-Ser department=Dahiliye Doctor doctor id.222 "Display the Binary" button will read the data from the binary file and display it to the text area by calling DisplayBin) method: ObjectInputStream obji = new ObjectInputStream (new FileInputStream("Doctor_bin")); ArrayList stemp=(ArrayList>(obji.readobject())

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions