Question

Einishing writing the method readhin.cities. Read a binary record of the two properties of the class -City. Use the array - readCity to store the records from the file. Use the open file dialog processing to select a file for reading..,See the separate page for the class-City Return the number of records read. Do not forget try and catch processing. using System; using System.IO class Prog1 static void Main(stringlI acgs) string svalue char another int arayct 0; City D city new City/20] arrayct-ceadbin(city) int x 0; Coosole Witelicelf inloCity NametPopulation) do Caosolc.Writel inel foht(1) city[x].CityNamd city x).Populate) 1/l end of main slatic int ceadbin.cites(C tyl teadcity) // asdd code here
0 0
Add a comment Improve this question Transcribed image text
Answer #1

static int readbin_cities(City[] readCity){
FileInputStream fis = new FileInputStream("outputFile");
boolean cont = true;
try{
ObjectInputStream input = new ObjectInputStream(fis);
while(cont){
Object obj = input.readObject();
if(obj != null)
readCity.add(obj);
else
cont = false;
}
}
catch(Exception e){
System.out.println("Error");
}

return readCity.length;
}

Add a comment
Know the answer?
Add Answer to:
Einishing writing the method readhin.cities. Read a binary record of the two properties of the class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Binary files The binary file data.dat contains characters and numbers- it has 16 characters, foll...

    java Binary files The binary file data.dat contains characters and numbers- it has 16 characters, followed by numbers of type int alternating with numbers of type double -so after the first 16 characters, there will be an int, followed by a double, followed by an int, followed by a double, and so on. Write a program to open the file and until the end of file is reached, read in the values in the appropriate data types (that is, read...

  • I am writing a program in C++, which requires me to read an input text file...

    I am writing a program in C++, which requires me to read an input text file using command line argument. However, I am using xcode on my Macbook to write C++ program, and use terminal instead of command. How do you use int main(int argc, char** argv[]) to read an input file. My professor requires us not to hard code the text file name like .open("example.txt"); Thank you!

  • MUST BE ANSWERED BY USING C++ Question 1 Unsorted List Implement a template class UnsortedList as...

    MUST BE ANSWERED BY USING C++ Question 1 Unsorted List Implement a template class UnsortedList as defined by the following skeleton: #define MAX_ITEMS 10 typedef char ItemType; class UnsortedList {        private:             int length; ItemType values[MAX_ITEMS]; int currentPos;        public:             SortedList( ); // default constructor: lenght=0, currentPos=-1             void MakeEmpty;    // let length=0             void InsertItem(ItemType x);   // insert x into the list                 void DeleteItem(ItemType x); // delete x from the list bool IsFull( );   // test...

  • QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes...

    QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes to a file. Compile and run these programs. There are several ways to read/write text files. The examples shown here are just one way of achieving this. Look at the API for the BufferedReader class. The readline() method is a simple way to read the text file line by line. It returns null when the end of the file has been reached. https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html Look...

  • P5: The program below has a parent thread that is a writer and 2 child threads that are both read...

    I need help with the following question: P5: The program below has a parent thread that is a writer and 2 child threads that are both readers. Complete the "child" function so that readers can continuously print the value of x" whenever the writer is not writing. No reader should starve while the other reader is reading sem t mutex, Xw mutex; int x; int read count = 0; int main (int argc, char "argv[]) { sem init (&mutex, 0,...

  • A binary tree is a complete binary tree if all the internal nodes (including the root...

    A binary tree is a complete binary tree if all the internal nodes (including the root node) have exactly two child nodes and all the leaf nodes are at level 'h' corresponding to the height of the tree. Consider the code for the binary tree given to you for this question. Add code in the blank space provided for the member function checkCompleteBinaryTree( ) in the BinaryTree class. This member function should check whether the binary tree input by the...

  • The purpose of this is to use inheritance, polymorphism, object comparison, sorting, reading binary files, and...

    The purpose of this is to use inheritance, polymorphism, object comparison, sorting, reading binary files, and writing binary files. In this application you will modify a previous project. The previous project created a hierarchy of classes modeling a company that produces and sells parts. Some of the parts were purchased and resold. These were modeled by the PurchasedPart class. Some of the parts were manufactured and sold. These were modeled by the ManufacturedPart class. In this you will add a...

  • package Lab11; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Lab10 {    public...

    package Lab11; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Lab10 {    public static void main (String [] args)    {    // ============================================================    // Step 2. Declaring Variables You Need    // These constants are used to define 2D array and loop conditions    final int NUM_ROWS = 4;    final int NUM_COLS = 3;            String filename = "Input.txt";    // A String variable used to save the lines read from input...

  • import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {              ...

    import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {               int total = 0;               int num = 0;               File myFile = null;               Scanner inputFile = null;               myFile = new File("inFile.txt");               inputFile = new Scanner(myFile);               while (inputFile.hasNext()) {                      num = inputFile.nextInt();                      total += num;               }               System.out.println("The total value is " + total);        } } /* In the first program, the Scanner may throw an...

  • (Reading & Writing Business Objects) I need to have my Classes be able to talk to...

    (Reading & Writing Business Objects) I need to have my Classes be able to talk to Files. How do I make it such that I can look in a File for an account number and I am able to pull up all the details? The file should be delimited by colons (":"). The Code for testing 'Select' that goes in main is: Account a1 = new Account(); a1.select(“90001”); a1.display(); Below is what it should look like for accounts 90000:3003:SAV:8855.90 &...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT