[SOLVED] CS212 Lab 7-Working with Eclipse, Two-dimensional arrays and StringTokenizers

25.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Lab7-u6kw30.zip (44.9 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
Rate this product

Working with Eclipse, Two-dimensional arrays and StringTokenizers.

  1. Open Eclipse, set up your private workspace on the H: drive, and create a Java Project for Lab7. Instructions are provided separately.
  2. A Java program (HelloWorld.java) has been provided on the public Z: drive under the folder Lab7. Import this program into your Lab7 project in Eclipse:
    1. Right click on the src folder under Lab7 in your list of Eclipse projects.
    2. Choose Import, expand General by clicking on the + sign, choose File System
    3. Click on Next, then Browse and go to the Z: drive and select the folder Lab7 and

      click OK. Click the box next to HelloWorld.java (the file you want to import) and click Finish.

  3. In Eclipse, double click the file HelloWorld.java. It should open the file in a tab. With the cursor somewhere inside the tab with the source code, right click and choose Run As Java Application. The program should run, and the output should appear at the bottom in the Console tab.
  4. Using the same procedure to import a file, bring the program TwoDimArray.java into

    your Lab7 project. Open the file and observe what it does, and run it. The output in the

    console should be:

    123 456 789

  5. Fill in the method PrintArrayEven with code that only prints the even numbers in the

    array. Instead of the odd numbers, print an asterisk (“*”). The output should be:

    *2* 4*6 *8*

  6. Now let’s read the numbers for the array from a file. First, you will need to import the TextFileInput program from the Lab7 folder in the Z: drive to the src folder of your Lab7 Java project. Also, import the file twodimension.txt into the Lab7 folder from the Z: drive.

    Open the file twodimension.txt. The first two lines represent the number of rows and columns. The rest of the file contains the numbers to be put in the array row by row. Write a method a method:

               public static int[][] fillArray(String myFile)
    

    that will read from the input file myFile and return a two dimension array of integers that are read from the file. The method should read the first two lines of the file and declare the array (which it will eventually return), then have a doubly-nested for loop to read all the numbers into the array. Remember to use Integer.parseInt() to convert each of the strings read in from the file to integer. Run the main program again, using the array returned by this method for printing.

  • Lab7-u6kw30.zip