Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: describe this program code by code ....

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default describe this program code by code ....

    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);
            }
            }
    }
    Last edited by helloworld922; October 30th, 2011 at 12:39 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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
    Last edited by copeg; October 29th, 2011 at 11:09 AM.

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    84
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default Re: describe this program code by code ....

    Well it seems you don't know the Rules of this forum!

Similar Threads

  1. How do i fix my code?
    By beebee007 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 14th, 2012, 10:49 AM
  2. Improving the code to produce the same program
    By u-will-neva-no in forum Java Theory & Questions
    Replies: 13
    Last Post: April 8th, 2011, 09:41 PM
  3. Help me with this code.
    By faysal40 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 26th, 2011, 12:18 AM
  4. HELP with Java Paint Program Code
    By CheekySpoon in forum AWT / Java Swing
    Replies: 1
    Last Post: April 5th, 2010, 12:03 PM
  5. Convert Java Program to Java ME code
    By rinchan11 in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: October 5th, 2009, 10:18 PM