Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi I need some help on this project. The world depends on its successful compilation. import java.io.*; import java.util.*; public class Project7 { public static

Hi I need some help on this project. The world depends on its successful compilation.

import java.io.*;

import java.util.*;

public class Project7

{

public static void main( String args[] ) throws Exception

{

if (args.length < 2 )

{

System.out.println(" usage: C:\\> java Project7 set1.txt set2.txt ");

System.exit(0);

}

BufferedReader infile1 = new BufferedReader( new FileReader( args[0] ) );

BufferedReader infile2 = new BufferedReader( new FileReader( args[1] ) );

String[] set1 = loadSet( infile1 );

Arrays.sort( set1 );

String[] set2 = loadSet( infile2 );

Arrays.sort( set2 );

printSet( "set1: ",set1 );

printSet( "set2: ",set2 );

String[] union = union( set1, set2 );

Arrays.sort( union );

printSet( " union: ", union );

String[] intersection = intersection( set1, set2 );

Arrays.sort( intersection );

printSet( " intersection: ",intersection );

String[] difference = difference( set1, set2 );

Arrays.sort( difference );

printSet( " difference: ",difference );

String[] xor = xor( set1, set2 );

Arrays.sort( xor );

printSet(" xor: ", xor );

System.out.println( " Sets Echoed after operations.");

printSet( "set1: ", set1 );

printSet( "set2: ", set2 );

}// END MAIN

// USE AS GIVEN - DO NOT MODIFY

// CAVEAT: This method will not work *correctly* until you write a working upSize() method.

static String[] loadSet( BufferedReader infile ) throws Exception

{

final int INITIAL_LENGTH = 5;

int cnt=0;

String[] set = new String[INITIAL_LENGTH];

while( infile.ready() )

{

if (cnt >= set.length)

set = upSize( set );

set[ cnt++ ] = infile.readLine();

}

infile.close();

return downSize( set, cnt );

}

// USE AS GIVEN - DO NOT MODIFY

static void printSet( String caption, String [] set )

{

System.out.print( caption );

for ( String s : set )

System.out.print( s + " " );

System.out.println();

}

/* ###############################################################

For each of the following set operations you must execute the following steps:

1) dimension an array that is just big enough to handle the largest possible set for that operation.

2) add the appropriate elements to the array as the operation prescribes.

3) before returning the array, downSize it to the exact size as the number of elements in it.

*/

static String[] union( String[] set1, String[] set2 )

{

return null; // change this to return a downSized full array

}

static String[] intersection( String[] set1, String[] set2 )

{

return null; // change this to return a downSized full array

}

static String[] difference( String[] set1, String[] set2 )

{

return null; // change this to return a downSized full array

}

static String[] xor( String[] set1, String[] set2 )

{

return null; // change this to return a downSized full array

}

// return an array of length newSize with all data from the old array stored in the new array

static String[] upSize( String[] old )

{

return null; // you change accordingly

}

// return an array of length cnt with all data from the old array stored in the new array

static String[] downSize( String[] old, int cnt )

{

return null; // you change accordingly

}

} // END PROJECT7

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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

Define compactness.

Answered: 1 week ago

Question

3. What may be the goal of the team?

Answered: 1 week ago

Question

Is how things are said consistent with what is said?

Answered: 1 week ago

Question

Has the priority order been provided by someone else?

Answered: 1 week ago