Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Write a pair of serialization / deserialization apps that create a users Car list, w/ a class named Car, which includes model, VINumber (int),

Java

Write a pair of serialization / deserialization apps that create a users Car list, w/ a class named Car, which includes model, VINumber (int), and CarMake (an enum, with valid values FORD, GM, TOYOTA, and HONDA) as fields. Use an array similar to the way the SerializeObjects did to handle several BankAccounts. Your app must include appropriate Exception Handling via try catch blocks (what if the file is not found, or the user inputs characters instead of digits for VINumber).

import java.io.*; import java.util.Scanner;

public class SerializeObjects { public static void main(String[] args) throws IOException { double balance; // An account balance final int NUM_ITEMS = 3; // Number of accounts // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Create a BankAccount2 array BankAccount2[] accounts = new BankAccount2[NUM_ITEMS]; // Populate the array. for (int i = 0; i < accounts.length; i++) { // Get an account balance. System.out.print("Enter the balance for " + "account " + (i + 1) + ": "); balance = keyboard.nextDouble();

// Create an object in the array. accounts[i] = new BankAccount2(balance); } // Create the stream objects. FileOutputStream outStream = new FileOutputStream("Objects.dat"); ObjectOutputStream objectOutputFile = new ObjectOutputStream(outStream); // Write the serialized objects to the file. for (int i = 0; i < accounts.length; i++) { objectOutputFile.writeObject(accounts[i]); }

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

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions