Archive for August, 2008

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());
        }
    }



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