navibar

Thursday, December 23, 2010

White simple template

Recently i am having my Sem break at the moment, so i decided to change the design of my website to white color base, and here it is.





Monday, December 6, 2010

[KDU] Data Structure & Algorithm (Assignment 1)

Data Structure & Algorithm (Assignment 1)

For the first assignment to be marked in week 4 (or 5) you should complete question 3 and you will be asked questions about your solutions in the week 4 (or 5) lab.

Marking scheme (out of 5 marks)

One mark for the program working correctly

Up to two marks each for the correct answer to two questions.

Coding

import java.io.*;

import java.util.*;

public class assignment1 {

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

{

//CREATE VARIABLE TO STORE FILE EXTENTION

String currentFile = "currAccounts.txt";

String oldFile = "oldAccounts.txt";

String NewFile = "newAccounts.txt";

String GraduateFile = "gradAccounts.txt";

TreeSet List = new TreeSet();

TreeSet List2 = new TreeSet();

//CREATE NEWACCOUNT AND GRADACCOUNT FILE

createNewStudent(NewFile,oldFile,currentFile,List);

createGradStudent(GraduateFile,oldFile,currentFile,List2);

System.out.println("Both file are created");

}

private static void createNewStudent(String NewFile,String oldFile,String currentFile,TreeSet List) throws Exception

{

FileWriter outputnew = new FileWriter(NewFile);

Scanner scold = null;

scold = new Scanner(new FileReader(oldFile));

while(scold.hasNext())

{

List.add(scold.next());

}

scold.close();

Scanner sccurrent = new Scanner(new FileReader (currentFile));

String tokennew;

String New ="";

int numberofnew = 0;

System.out.println("New Students Name:");

while (sccurrent.hasNext())

{

tokennew = sccurrent.next();

if(!List.contains(tokennew) && !tokennew.contains("0") && !tokennew.contains(".")&& !tokennew.contains("NA"))

{

New += tokennew;

New += " ";

System.out.println(tokennew);

numberofnew ++;

}

}

System.out.println("Number of New Students: "+numberofnew);

System.out.println("------------------New Student End------------------");

outputnew.write(New);

outputnew.close();

sccurrent.close();

}

private static void createGradStudent(String GraduateFile,String oldFile,String currentFile,TreeSet List) throws Exception

{

FileWriter outputgrade = new FileWriter(GraduateFile);

Scanner sc = null;

sc = new Scanner(new FileReader(currentFile));

while(sc.hasNext())

{

List.add(sc.next());

}

sc.close();

Scanner sc1 = new Scanner(new FileReader (oldFile));

String tokengrad;

String grad ="";

int numberofgrad= 0;

System.out.println("Graduate Students name:");

while (sc1.hasNext())

{

tokengrad = sc1.next();

if(!List.contains(tokengrad) && !tokengrad.contains("0") && !tokengrad.contains("."))

{

grad += tokengrad;

grad += " ";

System.out.println(tokengrad);

numberofgrad ++;

}

}

System.out.println("Number of Graduate Students: "+numberofgrad);

System.out.println("------------------Graduate Student End------------------");

outputgrade.write(grad);

outputgrade.close();

sc.close();

}

}


Print screen for the result


Output