Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

you can take a idea from this code: Q 1. Implement the following in Java: a Create a data type Person with three string fields:

image text in transcribedyou can take a idea from this code:
image text in transcribed
image text in transcribed
Q 1. Implement the following in Java: a Create a data type Person with three string fields: firstName, lastname and id. The field id is unique to each person. Add accessor methods, a constructor with three parameters, and the toString() method. b Within the main() program, instantiate a linked list (use the Java LinkedList class). Write the following functions(methods) that the main program will invoke all these will be static methods of the main class): store (, ) that reads the data for several persons from the input stream and stores the data in the linked list. display (output stream>, ) that writes the data for all person ob- jects in the linked list, on the output stream, one per line. find(string sid, ) that returns the index of the person object in the linked list, that has the same id value as sid (return -1 if no such person exists). This can be done as a simple search that goes sequentially through all the objects in the linked list. Create a data file with data for a few person objects. In the main method, call the store) and display() methods to read the data and display it. Invoke the find method a few times. Compile and test your code. c Construct a different version of the above program as follows: (1) create a data type Personlist that uses the Java Linkedlist, and supports the methods(re- written appropriately) from part b. (2) instantiate the PersonList object in the main program and invoke its methods (as per the appropriate syntax), so that program produces the same output as the one in part b. 1 import java.io.*; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.*; import java.lang.*; public class Merge { public static void main(String[] args) throws FileNotFoundException { int item1 = 0, item2 = 0; String fileName1, fileName2, outFileName; File dataFile1, dataFile2, outFile; boolean hasNext1 = false, hasNext2 = false; Scanner keyScanner = new Scanner(System.in); System.out.println("Please enter the first file name: "); fileName1 = keyScanner.nextLine(); System.out.println("Please enter the second file name: "); fileName2 = keyScanner.nextLine(); System.out.println("Please enter the output file nam name: "); outFileName = keyScanner.nextLine(); dataFile1 = new File(fileName); dataFile2 = new File(fileName2); outFile = new File(outFileName); Scanner fileScanner1 = new Scanner(dataFile1); Scanner file Scanner2 = new Scanner(dataFile2); PrintWriter printer = new Print Writer(outFile); if (file Scanner 1. hasNext() { hasNext1 = true; item1 = fileScanner1.nextInt(); } if (file Scanner2.hasNext() { hasNext2 = true; item2 = file Scanner2.nextInt(); )) } while (hasNext1 && hasNext2) { if (item1

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

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

Identify benefits and costs for Problem 1-21.

Answered: 1 week ago

Question

Question What is the advantage of a voluntary DBO plan?

Answered: 1 week ago