Use the class ClassObjectIODemo shown in Listing 10.10 of Chapter 10 to create a file of Species
Question:
Use the class ClassObjectIODemo shown in Listing 10.10 of Chapter 10 to create a file of Species objects. The class Species is given in Chapter 10, Listing 10.9. Then write a program that reads the Species objects from the file you created into an instance of ArrayList, sorts these instances alphabetically by Species name, and then writes the sorted data to both the screen and a file. Read all file names from the user.
Listing 10.10
Listing 10.9
Transcribed Image Text:
import java.io.FileInputStream; import java.io.FileOutputStream; i mport java.io.10Exception; i mport java.io.0bjectInputStream; import java.io.0bjectOutputStream; public class ClassobjectIODemo { public static void main(String []args) { ObjectoutputStream outputStream = null; String fileName = "species.records"; try { outputStream = new ObjectOutputStream( new FileOutputStream (fileName)); } catch (10Exception e) { System.out.println("Error opening output file + fileName + "."); System.exit (0); Species califCondor = new Species ("Calif. Condor", 27, 0.02); Species blackRhino = new Species ("Black Rhino", 100, 1.0); try { outputStream.writeObject (califCondor); outputStream.writeObject (blackRhino); outputStream.Close(); catch (10Exception e) { System.out.println("Error wring to file fileName + "."); System.exit (0) } System.out.printin("Records sent to file fileName + "."); + System.out.println( "Nov et's reopen the file and echo "the records.");
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (9 reviews)
public class SpeciesSortedByNameToFile public static void mainString args String fileName getFileName Enter name of Species file to read ObjectInputStream inputStream null try inputStream new ObjectIn...View the full answer
Answered By
RADHIKA MEENAKAR
I am a qualified indian Company Secretary along with Masters in finance with over 6 plus years of professional experience. Apart from this i am a certified accounts and finance tutor on many online platforms.
My Linkedin profile link is here https://www.linkedin.com/in/radhika-meenakar-88b9808a/
5.00+
12+ Reviews
22+ Question Solved
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Question Posted:
Students also viewed these Computer science questions
-
Write a program that reads a connected graph from a file. The graph is stored in a file using the same format specified in Programming Exercise. Your program should prompt the user to enter the name...
-
Write a program that reads a connected graph from a file. The graph is stored in a file using the same format specified in Exercise. Your program should prompt the user to enter the name of the file,...
-
Write a program that reads N points in a plane and outputs any group of four or more colinear points (i.e., points on the same line). The obvious brute-force algorithm requires O(N4) time. However,...
-
Which market segments are the most favorable for Hyundai card? Does the company do an effective job of targeting and reaching those segments? If so, How? If not, why not?
-
Refrigerant-134a enters an adiabatic compressor as saturated vapor at 100 kPa at a rate of 0.7 m3/min and exits at 1-MPa pressure. If the isentropic efficiency of the compressor is 87 percent,...
-
Fire Out Company manufactures its product, Vitadrink, through two manufacturing processes: Mixing and Packaging. All materials are entered at the beginning of each process. On October 1, 2020,...
-
Suicides among Vietnam veterans. Did the horrors of fighting in Vietnam drive many veterans of that war to suicide? A figure of 150,000 suicides among Vietnam veterans in the 20 years following the...
-
On January 1, 2007 the Stimpson Company sells land to Barker Company for $2.5 million, then immediately leases it back. The relevant information is as follows: 1. The land was carried on Stimpsons...
-
Rooney Corporation sells products for $37 each that have variable costs of $8 per unit. Rooneys annual fixed cost is $678,600. Required Use the per-unit contribution margin approach to determine the...
-
Nucor Corporation produces steel and steel products at its eight mills and is a major recycler of scrap metal. The following data relate to Nucor for four years. Required: 1. Calculate Nucor's ROA...
-
Write a static method removeDuplicates(ArrayList data) that will remove any duplicates of characters in the object data. Always keep the first copy of a character and remove subsequent ones.
-
Repeat Exercises 6 and 7 in Chapter 7, but use an instance of ArrayList instead of an array. We will no longer need to know the maximum number of sales, so the methods will change to reflect this....
-
What structural components are found in muscles? What do these components have to do with muscle performance?
-
MATA 31 Calculus 1 winter 2024 Problem Set 2 Feb 11 Feb 18 on Crowdmark Each question is 25 points. 1. (25) (a) (15) Given that lim 3 2x + 3 for = 0.1 = 3, find the largest & that works (b) (10) Find...
-
A retailer has product demand 9600 units a year. The carrying cost of one unit of the product is $3.50 per year. Ordering costs are $28 per order. a. What is the Economic Order Quantity (EOQ)? (2...
-
How do I key in this into journal entries Crest Pte Ltd Trial Balance Cash Accounts receivable, Augusta Office Equipment Opening Bal as at 1 Mar 2021 Debit (5) Credit ($) 15,000 5,000 13,000...
-
If an atomic layer is approximately 0.1nm thick, how fast are the protein synthesis machines working in atomiclayers/satomiclayers/s?
-
Consider the 4 sets of data shown below for v(t) the velocity of an object in freefall with the corresponding linear curve fits. The slope of the best fit line gives the acceleration, and for...
-
Blood types are determined by the presence or absence of three antigens: A antigen, B antigen, and an antigen called the Rh factor. The resulting blood types are classified as follows: type A if the...
-
A Firm intends to invest some capital for a period of 15 years; the Firm's Management considers three Options, each consisting of purchasing a machinery of a specific brand, different for each...
-
Given the following periods, calculate the corresponding frequencies. a. 5 s b. 12 s c. 220 ns
-
What does the amplitude of a signal measure? What does the frequency of a signal measure? What does the phase of a signal measure?
-
What is the relationship between period and frequency?
-
help me A 35% discount on 3 smart phone amounts to $385. What is the phone's list price? Answer =$ (rounded to the nearest cent)
-
What effect is there on the income statement and balance sheet when an expense is left too long as a liability
-
Which of the following programs covers custodial care? A HMOs B Medicare Part B C PPOs D Medicare Part A E Medicaid
Study smarter with the SolutionInn App