java help ASAP

Anonymous
timer Asked: Sep 12th, 2013
account_balance_wallet $5

Question Description

this is a java program which I am working on but it has been along time since I used java and am really lost.  I am suppose to code the sections which I marked in the project  please help me. 

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Arrays;

import java.util.Scanner;

/**

 * 

public class AlumniFinder {

/**

* Read in a file containing student records and create an array of Student

* objects

* @param file The filename

* @param num The number of students in the file

* @return An array of Student objects

*/

static Student[] readStudentsFromFile(String filename, int num) {

try (Scanner in = new Scanner(new File(filename))) {

Student[] students = new Student[num];

// YOUR CODE HERE

// Hints:

// To read a line from the file you can call 

//String line = in.nextLine();

// The split method of the String class might come in handy to get the fields

return students;

} catch (FileNotFoundException e) {

e.printStackTrace();

return null;

}

}

/**

* Write an array of Student objects to a file

* @param students The array of Student objects to write out

* @param filename The output filename

*/

static void writeStudentsToFile(Student[] students, String filename) {

try (FileWriter out = new FileWriter(filename)) {

// YOUR CODE HERE

// Hints:

// To write a line to the file you can call 

//   out.write("Hello World!" + "\n");

} catch (IOException e) {

e.printStackTrace();

}

}

/**

* Find students belonging to both groups.

* This function checks each student in group1 for membership in group2 by

* comparing it with every student in group2.

* @param group1 A group of Students

* @param group2 A group of Students

* @param numCommon number of students belonging to both groups

* @return An array of Students which belong to both group1 and group2

*/

static Student[] findCommonStudents1(Student[] group1, Student[] group2,

int numCommon) {

Student[] common = new Student[numCommon];

// YOUR CODE HERE

return common;

}

/**

* Find students belonging to both groups.

* This function checks each student in group1 for membership in group2 by

* doing a binary search on group2.

* @param group1 A group of Students

* @param group2 A group of Students

* @param numCommon number of students belonging to both groups

* @return An array of Students which belong to both group1 and group2

*/

static Student[] findCommonStudents2(Student[] group1, Student[] group2,

int numCommon) {

Student[] common = new Student[numCommon];

// YOUR CODE HERE

// Hints:

// To sort an array of Comparables you can call    

//Arrays.sort(arr);

// To search for an element in a sorted array you can call

// Arrays.binarySearch(arr, element)

// if the returned index is >= 0, the element was found at that index

return common;

}

/**

* @param args

*/

public static void main(String[] args) {

/***** These files provided to help you with initial testing *****/

Student[] uc = readStudentsFromFile("sample_uc_students.txt", 10);

Student[] cs = readStudentsFromFile("sample_cs_grads.txt", 5);

final int cs_UC_GradsNumber = 2;

/***** Use these files for the output you submit *****/

//Student[] uc = readStudentsFromFile("uc_students.txt", 350000);

//Student[] cs = readStudentsFromFile("cs_grads.txt", 75000);

//final int cs_UC_GradsNumber = 25000;

long start, end;

start = System.currentTimeMillis();

Student[] common1 = findCommonStudents1(uc, cs, cs_UC_GradsNumber);

end = System.currentTimeMillis();

System.out.println("Cross checking took " + (end - start) / 1000.0

+ " seconds.");

Arrays.sort(common1);

writeStudentsToFile(common1, "cs_grads_at_uc_1.txt");

start = System.currentTimeMillis();

Student[] common2 = findCommonStudents2(uc, cs, cs_UC_GradsNumber);

end = System.currentTimeMillis();

System.out.println("Using binary search it took " + (end - start)

/ 1000.0 + " seconds.");

Arrays.sort(common2);

writeStudentsToFile(common2, "cs_grads_at_uc_2.txt");

}

}


Tutor Answer

fitting k
School: University of Virginia

Thank you for the opportunity to help you with your question!

in general, do not need to be licensed or pass any standardized (or governmentally regulated) certification tests in order to call themselves "programmers" or even "software engineers.

Please let me know if you need any clarification. I'm always happy to answer your questions.

flag Report DMCA
Review

Anonymous
Top quality work from this guy! I'll be back!

Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors