Archive for the 'Programming' Category

JAVA Hands on Lab (2)

Read data from a file.
Object Oriented Software Engineering - Java
Khalilur Rahman

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package courseregistrationsystem2;

import java.io.BufferedReader;
import java.io.FileReader;

/**
 *
 * @author khal
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    static Course[] allCourses;
    public static void main(String[] args) {
        // TODO code application logic here
        allCourses = new Course[50];
        readSourceFile("StudentDataInput.txt");
    }
    public static void readSourceFile(String fileName){
        String code, venue, title, instructor;
        try {
            FileReader fileReader = new FileReader(fileName);
            BufferedReader in = new BufferedReader(fileReader);
            int numberOfCourse = Integer.parseInt(in.readLine());
            for (int i = 0; i < numberOfCourse; i++){
                if ((code = in.readLine())== null) break;
                if ((venue = in.readLine())== null) break;
                if ((title = in.readLine())== null) break;
                if ((instructor = in.readLine())== null) break;
                createCourse(i, code, venue, title, instructor);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    public static void createCourse(int index, String code, String venue,
            String title, String instructor){

        allCourses[index]= new Course();
        allCourses[index].code = code;
        allCourses[index].venue = venue;
        allCourses[index].title = title;
        allCourses[index].instructor = instructor;

        System.out.println(allCourses[index].code);
        System.out.println(allCourses[index].venue);
        System.out.println(allCourses[index].title);
        System.out.println(allCourses[index].instructor);
    }
}

JAVA Hands on Lab (1)

Object oriented Software Engineering - Java
Khalilur Rahman

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package courseregistration;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

/**
 *
 * @author khal
 */
public class courseRegistration {

    /**
     * @param args the command line arguments
     */
    static Course[] allCourses;
    public static void main(String[] args) {
        // TODO code application logic here
        allCourses = new Course[50];

        allCourses[0] = new Course();
        allCourses[0].code =  "CI6201";
        allCourses[0].title =  "Professional Seminar";
        allCourses[0].venue =  "LT2";
        allCourses[0].instructor =  "Paul Wu";
        allCourses[0].academicUnit = 3;

        allCourses[1] = new Course();
        allCourses[1].code =  "CI6202";
        allCourses[1].title =  "Information Architecture";
        allCourses[1].venue =  "LT3";
        allCourses[1].instructor =  "Chris Khoo";
        allCourses[1].academicUnit = 3;

        allCourses[2] = new Course();
        allCourses[2].code =  "CI6203";
        allCourses[2].title =  "Software Engineering";
        allCourses[2].venue =  "LT5";
        allCourses[2].instructor =  "W K Ng";
        allCourses[2].academicUnit = 3;

        displayCourse();
        pickCourse();
        pickCourseCode();
    }
    public static void displayCourse(){
        try {
            for (int i = 0; i < 50; i++ ){
                if (allCourses[i]==null) break;
                System.out.println(allCourses[i].code);
                System.out.println(allCourses[i].title);
                System.out.println(allCourses[i].instructor);
                System.out.println(allCourses[i].venue);
                System.out.println(allCourses[i].academicUnit);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }
    public static void pickCourse(){
        try {
            System.out.print("Enter the course code: ");
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(System.in));
            int i = Integer.parseInt(in.readLine());
                System.out.println(allCourses[i].code);
                System.out.println(allCourses[i].title);
                System.out.println(allCourses[i].instructor);
                System.out.println(allCourses[i].venue);
                System.out.println(allCourses[i].academicUnit);
        } catch (Exception e) {
        }
    }
    public static void pickCourseCode(){
        try {
            System.out.print("Enter course ID: ");
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(System.in));
            String code = in.readLine();
            for (int i =0; i < 50; i++){
                if (allCourses[i]==null) break;
                if (allCourses[i].code.equals(code)){
                    System.out.println(allCourses[i].code);
                    System.out.println(allCourses[i].title);
                    System.out.println(allCourses[i].instructor);
                    System.out.println(allCourses[i].venue);
                    System.out.println(allCourses[i].academicUnit);
                }
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

Microsoft Releases Robotics Developer Studio 2008 CTP

by Michael Desmond
09 April 2008

MSDN Logo Microsoft today released the first community technology preview (CTP) of Robotics Developer Studio 2008 at the RoboBusiness conference in Pittsburgh. The product is the third version of the robotics programming platform, which previously had been called the Microsoft Robotics Studio.

Microsoft Robotics Developer Studio 2008 (RDS 08) significantly improves runtime performance, from 150 percent to 300 percent, according to Microsoft General Manager of the Robotics Group Tandy Trower. “It’s not the monolithic, single-threaded model that people have normally used for robots. Instead this is a more asynchronous, distributed approach to programming,” Trower said.

Trower said RDS 08 will enable developers to write code and routines that rely on asynchronous message passing, providing for a more distributed runtime environment and expanding the potential for future robots to process and act on large volumes of information. According to a Microsoft release, RDS 08 adds support for distributed language integrated queries (LINQ), intended to enable “advanced filtering and inline processing of sensor data at the source.”

According to Trower, the distributed application architecture will make it easier for robotic applications to access processing from remote sources, enabling a simple machine to act on complex processing done on a corporate server or in the cloud.

“You can have cooperative robotic interaction, because the robots can easily share information among each other,” Trower said.

The RDS 08 CTP also provides improved sensor interaction, enabling sensors to send granular state change information to the processor, rather than requiring code that constantly checks sensor status.

Microsoft Robotics Studio was launched in 2006 to give developers a way to write high-level robotics applications without having to dive down into the minutiae of hundreds of different sensor and motor interfaces.

Ultimately, Trower said, the tools and techniques developers in the Robotics group could very well end up in mainstream development products at Microsoft.

“You will see that this year the core pieces — the CCR, which is our concurrency coordination runtime and our DSS services, which is its companion that provides the concurrency model across the distributed network — these pieces we actually will separate out and offer independently as well as in the toolkit, so that people who are interested in using this for [other] applications will be able to do that,” Trower said.

“You will also see them positioned as part of the development tools family outside of the robotics area by our marketing team in our developer tools marketing group.”
Michael Desmond, former editor at large of Redmond magazine, is the editor in chief of Redmond Developer News magazine. He has served as senior editor of news at PC World and executive editor at Multimedia World magazine, and has written for dozens of publications and Web sites. Desmond has also written four computing books, including Microsoft Office 2003 in 10 Simple Steps or Less.

A Random Number Generation Technique with Encryption and Genetic Algorithm Applications

This article has been taken from www.codeguru.com,  it’s working great.

Andy McGovern (view profile)
May 26, 2004

Environment: VC++ 6, Win32

Introduction

Many exciting applications, such as data encryption and genetic algorithm programs, use randomly generated numbers to make choices. In some (rare) cases, only truly random numbers will do; that makes things complex because programs are based on logic, and the logic they use can generally be reversed. In other words, it is difficult to program a series of logical steps that produces numbers that don’t follow some kind of pattern. One approach for generating truly random numbers is to measure some kind of continuous natural phenomena; for instance, the noise power level in a radio-frequency receiver. The noise power level appears to be random because the power level at any instant in time depends on so many variables, such as cosmic radiation, solar energy, Earth thermal energy, and so forth. For most applications, pseudo-random numbers are sufficient. Pseudo-random numbers follow predictable patterns, but they do so over very long periods. The idea is that you would have to look at a very long (maybe in the billions) string of numbers before you would see a repeat of the pattern.

A conceptually simple way to generate long sequences of pseudo-random numbers is with a linear feedback shift register (lfsr). The tapped elements (the memory slots connected to the circle with the plus inside) are XOR’ed (0 xor 1 = 1; 0 xor 0 = 0; 1 xor 1 = 0) and then placed in the right-most bit slot, pushing all the previous bits one slot to the left. The sequence of 1s and 0s that pop off the left side of the register are the pseudo-random number sequence. The catch is that some tap positions cause the register to short cycle; in other words, some tap positions do not use the register to its greatest capability. A register’s maximum-length sequence will be (2^n - 1) bits long; n is the number of slots in the register. A short cycle in the register has occurred if the register ends up with the same fill that it started with before (2^n - 1) cycles elapse. Any book on spread spectrum communications or error correcting codes is bound to have a table listing tap positions corresponding to maximal length sequences for given LFSR lengths.

prng.JPG

Figure 1: LFSR with an initial fill (0,0,1,1,0,1,0) and taps on elements (0,3) Continue reading ‘A Random Number Generation Technique with Encryption and Genetic Algorithm Applications’

Basic Binary Application in C#

I just want to share a small and basic application to do text to binary conversion. Like I do, sometimes I feel I really want to make a greeting really in different way that people may do that by putting plain words or messages in their greeting. But now, you can actually create a totally different way of doing a greeting, that is by using binary string. Alright, you may say what the hell is that?, why am I doing that for?, how will people understand the words in binary? It’s all up to you. Well, for me, I don’t really care what people will think about my messages that are written in binary strings. As long as I can get what I want. That is more than just enough.

So, here we go. Basically, the way converting text to binary and back, is very simple. I use MS Visual Studio .NET 2005 / Framework v2.0. It converts each letter on a text into ASCII decimal and then breaks it into 8 bit binary strings.

public string stringToBinary(string sData)
        {
            int bit = 8;
            byte[] bData = Encoding.UTF8.GetBytes(sData);
            string binData = "";
            foreach (byte b in bData)
            {
                string sBinary = Convert.ToString(GetBase(2, b));
                if (sBinary.Length < bit)
                    sBinary = sBinary.PadLeft(bit, Convert.ToChar("0"));
                binData = binData + sBinary;
            }
            return binData;
        }

That snippet shows you how to do the text to binary conversion. Anyway, you can just download, run and modify it as you want. Now, I am going to do the reverse conversion.
Continue reading ‘Basic Binary Application in C#’




IKIBLOGKU is Digg proof thanks to caching by WP Super Cache!