| | |
Please help me to explain these codes
![]() |
•
•
•
•
import java.util.*;
import java.io.*;
class Week3Question2
{
public static void main (String args[])
{
TreeSet OldAccount = new TreeSet();
TreeSet CurrentAccount = new TreeSet();
TreeSet PseudoAccount = new TreeSet();
try
{
RetrieveAcc(OldAccount,CurrentAccount);
}
catch(Exception exc)
{
System.out.println("No such file!");
}
try
{
WriteAcc(OldAccount,CurrentAccount,PseudoAccount);
}
catch(Exception exc)
{
System.out.println("Process failed !");
}
System.out.println(CurrentAccount);
System.out.println(CurrentAccount.size()+"\n\n");
System.out.println(OldAccount);
System.out.println(OldAccount.size());
}
public static void RetrieveAcc(TreeSet Old, TreeSet Current)throws Exception
{
String dataStore = "";
Scanner oldAcc = new Scanner(new FileReader("oldAccounts.txt"));
Scanner currAcc = new Scanner(new FileReader("currAccounts.txt"));
oldAcc.skip("ID\tName");
currAcc.skip("ID\tName");
while(oldAcc.hasNext())
{
dataStore = oldAcc.nextLine();
Old.add(dataStore);
}
while(currAcc.hasNext())
{
dataStore = currAcc.nextLine();
Current.add(dataStore);
}
Old.remove("\t");
Current.remove("\t");
oldAcc.close();
currAcc.close();
}
public static void WriteAcc(TreeSet Old, TreeSet Current,TreeSet Pseudo)throws Exception
{
FileWriter gradAcc = new FileWriter("gradAccounts.txt");
FileWriter newAcc = new FileWriter("newAccounts.txt");
Pseudo.addAll(Old);
Pseudo.removeAll(Current);
Object IteData;
Iterator PseudoIte = Pseudo.iterator();
gradAcc.write("ID\tName\r\n");
while(PseudoIte.hasNext())
{
IteData = PseudoIte.next();
gradAcc.write(IteData+"\r\n");
}
gradAcc.close();
newAcc.write("ID\tName\r\n");
Pseudo.clear();
Pseudo.addAll(Current);
Pseudo.removeAll(Old);
PseudoIte = Pseudo.iterator();
while(PseudoIte.hasNext())
{
IteData = PseudoIte.next();
newAcc.write(IteData+"\r\n");
}
newAcc.close();
//System.exit(0);
}
}
&
import java.util.*;
import java.io.*;
class Week3Question3
{
public static void main (String args[])
{
String[] OldAccounts = new String[31];
String[] CurrentAccounts = new String[15];
try
{
loadOldAcc(OldAccounts,CurrentAccounts);
}
catch(Exception e)
{
System.err.println("Error in reading file!");
}
try
{
loadCurrAccounts(OldAccounts,CurrentAccounts);
}
catch(Exception e)
{
System.err.println("Error in reading file!");
}
try
{
writeRecord(OldAccounts,CurrentAccounts);
}
catch(Exception e)
{
System.err.println("Error in reading file!");
}
}
public static void writeRecord(String[] Old,String[] Current) throws Exception
{
BufferedWriter gradAccounts = new BufferedWriter(new FileWriter("gradAccounts.txt"));
gradAccounts.write("ID\tName\r\n");
boolean GradIsAvailable = false;
for(int m=1; m<Old.length; m++)
{
for(int n=1; n<Current.length; n++)
{
if(Old[m].trim().equals(Current[n].trim()))
{
GradIsAvailable = true;
break;
}
}
if(!GradIsAvailable)
{
gradAccounts.write(Old[m] + "\r\n");
}
GradIsAvailable = false;;
}
gradAccounts.close();
BufferedWriter newAccounts = new BufferedWriter(new FileWriter("newAccounts.txt"));
newAccounts.write("ID\tName\r\n");
boolean NewIsAvailable = false;
for(int m=1; m<Current.length; m++)
{
for(int n=1; n<Old.length; n++)
{
if(Current[m].trim().equals(Old[n].trim()))
{
NewIsAvailable = true;
break;
}
}
if(!NewIsAvailable)
{
newAccounts.write(Current[m] + "\r\n");
}
NewIsAvailable = false;;
}
newAccounts.close();
}
public static void loadOldAcc(String[] Old, String[] Current) throws Exception
{
Scanner oldAccounts = new Scanner(new FileReader("oldAccounts.txt"));
for(int m=0; m<Old.length; m++){
Old[m] = oldAccounts.nextLine();
}
}
public static void loadCurrAccounts(String[] Old, String[] Current) throws Exception
{
Scanner currAccounts = new Scanner(new FileReader("currAccounts.txt"));
for(int n=0; n<Current.length; n++){
Current[n] = currAccounts.nextLine();
}
}
}
// Please help me to explain these codes by writing the explanation beside the codes using '//'.thanks
Last edited by lordx78; Oct 24th, 2007 at 1:22 pm.
![]() |
Similar Threads
- How to open pdf documents from a Microsoft Access Form (MS Access and FileMaker Pro)
- C# codes (C#)
- opening a pdf document?? (Visual Basic 4 / 5 / 6)
- help help plzzzzzzzz (Java)
- URGENT!: Saving Database information from ASP.NET Button (ASP.NET)
- Checking source codes of image, audio and video files (Site Layout and Usability)
- Problems creating a DHTML menu script with a stylish dropdown menu (JavaScript / DHTML / AJAX)
- Can't view source codes (Web Browsers)
Other Threads in the Java Forum
- Previous Thread: Two Static HashTables
- Next Thread: Drawing a spiral
| Thread Tools | Search this Thread |
addball android applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) button card class classes client code collision columns component constructor crashcourse css database designadrawingapplicationusingjavajslider draw eclipse ee error eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer html ide image integration intellij j2me java javaarraylist javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia jvm linux loan loop method migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle phone physics plazmic print problem program programming project radio scanner server service set sharepoint smart sms smsspam software sql subclass support swing textfield threads tree trolltech unlimited utility windows






