Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i tried to run this program Jgrasp, but it does not run. I don't know. Could you fix it for me please thatnks. and this

i tried to run this program Jgrasp, but it does not run. I don't know. Could you fix it for me please thatnks. and this requarization:( Write program to store bunch of Rectangles ans squares in an arrlylist. use object serialization to write the arrylist into a fle.read the arrylist object from the file. print the arrylist.) this is the code that I wrote.

importjava.io.*; importjava.util.ArrayList; publicclassSerializableObjects { staticclassRectangle implementsSerializable { privatedoublewidth, length; publicRectangle() { } publicRectangle(doublewidth, doublelength) { this.width = width; this.length = length; } publicdoublegetWidth() { returnwidth; } publicvoidsetWidth(doublewidth) { this.width = width; } publicdoublegetLength() { returnlength; publicvoidsetLength(doublelength) { this.length = length; Override publicString toString() { return"Rectangle{"+ "width="+ width + ", length="+ length + '}'; } staticclassSquare implementsSerializable { 4privatedoubleside; publicSquare() { publicSquare(doubleside) { this.side = side; publicdoublegetSide() { returnside; } publicvoidsetSide(doubleside) { this.side = side; } @Override publicString toString() { return"Square{"+ "side="+ side + '}'; } } }

Main:

publicstaticvoidmain(String[] args) throwsIOException, ClassNotFoundException { ArrayList list = newArrayList<>(); list.add(newRectangle(2, 3)); list.add(newSquare(5)); list.add(newRectangle(1, 4)); list.add(newSquare(1)); list.add(newRectangle(7, 1)); list.add(newRectangle(5, 6)); list.add(newSquare(9)); ObjectOutputStream oos = newObjectOutputStream(newFileOutputStream("rectangleandsquares.txt")); oos.writeObject(list); ObjectInputStream ois = newObjectInputStream(newFileInputStream("rectangleandsquares.txt")); System.out.println(ois.readObject()); ois.close(); oos.close(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions