describe this program code by code ....
Code Java:
import java.util.*;
import java.io.*;
class StudAccount {
public static void main (String[] args)throws IOException {
TreeSet currAccounts = new TreeSet();
TreeSet oldAccounts = new TreeSet();
TreeSet gradAccounts = new TreeSet();
TreeSet newAccounts = new TreeSet();
try
{
readAccounts
("curraccounts.txt", currAccounts);
readAccounts
("oldaccounts.txt", oldAccounts);
gradAccounts.addAll(oldAccounts);
gradAccounts.removeAll(currAccounts);
newAccounts.addAll(currAccounts);
newAccounts.removeAll(oldAccounts);
}
catch(IOException ioe)
{
System.out.println("Cannot open file");
System.exit(1);
}
FileOutputStream out1;
PrintStream p1;
FileOutputStream out2;
PrintStream p2;
try
{
out1 = new FileOutputStream("gradaccounts.txt");
out2 = new FileOutputStream("newaccounts.txt");
p1 = new PrintStream( out1 );
p2 = new PrintStream( out2 );
p1.println (gradAccounts);
p2.println (newAccounts);
p1.close();
p2.close();
}
catch (Exception e)
{
System.err.println ("Error writing to file");
}
System.out.println("The people who have graduated are" + gradAccounts);
System.out.println("The people who are new" + newAccounts);
}
public static void readAccounts(String filename, TreeSet Accounts)
throws IOException
{
Scanner sc = new Scanner(new FileReader(filename));
String id = null;
String name = null;
String cgpa = null;
while (sc.hasNext())
{
id = sc.next();
name = sc.next();
cgpa = sc.next();
Accounts.add(name);
}
}
}
Re: describe this program code by code ....
Please see the link in my signature entitled 'getting help'
Edit: and that link applies to every one of your other posts as well. I would also encourage you to read the following: http://catb.org/~esr/faqs/smart-questions.html
Re: describe this program code by code ....
Well it seems you don't know the Rules of this forum!