The Programming Project: 2000
Showing posts with label 2000. Show all posts
Showing posts with label 2000. Show all posts

Thursday, August 7, 2014

Telephone Directory ~ ISC COMPUTER SCIENCE PRACTICAL SOLLVED 2000

ISC COMPUTER SCIENCE PRACTICAL SOLLVED 2000, ISC JAVA PROGRAMS
A file contains a list of names and telephone numbers in the following form
AJIT 281050
ANIL 462890
HRISHIKESH 524352
.
.
.
.
.
.
The names contain only one word and the names and telephone numbers
are separated by white spaces. Write an interactive program to :
(i) Create the above file.
(ii) Display the contents in two columns.
(iii) Search a telephone number for a given name (Assure no duplication of names).
(iv) Exit the program.


Test your program using the following data :

AJAY 281050
AJIT 425382
ANIL 525122
AJHAR 528422
HRISHIKESH 524352
JAVAGAL 532673
MONGIA 691383
RAHUL 698114
ROBIN 524899
SACHIN 628266
SAURAV 708294
VENKATESH 492642

Test the (iii) option by searching the telephone numbers of :
(a) AJHAR
(b) SACHIN       

import java.util.*;
import java.io.*;
public class Telephone
    {
    public static void main(String[] args) throws IOException
        {
        String fileName = "Tele.dat";
        String nameCust,temp;
        String teleNumber,S;
        boolean flag;
        Scanner in = new Scanner(System.in);
        FileOutputStream fout = new FileOutputStream(fileName);
        while(true) {
            temp = "";
            flag = false;
            System.out.println("Enter Customer name:");
            nameCust = in.next();
            System.out.println("Enter telephone number");
            teleNumber = in.next();
            temp = nameCust+" "+teleNumber;
            temp = temp.toUpperCase();
            FileReader fr = new FileReader(fileName);   
            BufferedReader br = new BufferedReader(fr);
            while(( S=br.readLine() ) != null) {
                String check ="";
                int j = 0;
                while(S.charAt(j++) != ' ')
                    check += S.charAt(j-1); 
                if (check.equals(nameCust)) {
                    System.out.println("Name already exists, enter a different name:");
                    flag = true;
                    }
                }
            br.close();   
            if(flag == true)
                continue;   
            for( int i = 0; i < temp.length();i++)
                fout.write(temp.charAt(i));
            fout.write('\n');   
            System.out.println("Want to continue? (Y/N)");   
            String a = in.next();
            if ( a.toUpperCase().equals("N"))
                break;
            }
        fout.close();   
       
        String srchTele;
        System.out.println("Enter the customer name to search for telephone number:");
        srchTele = in.next();
        srchTele = srchTele.toUpperCase();
        FileReader fr = new FileReader(fileName);   
        BufferedReader br = new BufferedReader(fr);
        flag = false;
            while(( S=br.readLine() ) != null) {
                String check ="";
                int j = 0;
                while(S.charAt(j++) != ' ')
                    check += S.charAt(j-1); 
                if (check.equals(srchTele)) {                    
                    System.out.println(S.substring(j));
                    flag = true;
                    }
                }
        if( flag == false)
            System.out.println("Customer does not exists:");       
        br.close();       
        }
    }   

Tuesday, August 5, 2014

ISC COMPUTER SCIENCE PRACTICAL– 2000 Days Elapsed, ISC JAVA PROGRAMS

ISC COMPUTER SCIENCE PRACTICAL– 2000 Days Elapsed, ISC JAVA PROGRAMS
Write a program to input two valid dates, each comprising of day (2 digits), Month (2
digits) and year (4 digits) and calculate the days elapsed between the two dates.
Test your program for the following data values:

i) FIRST DATE : DAY : 24
        MONTH: 09
        YEAR: 1960
   SECONDDATE : DAY : 08
        MONTH: 12
        YEAR: 1852
       
ii) FIRST DATE : DAY : 10
        MONTH: 01
        YEAR: 1852
   SECONDDATE : DAY : 16
        MONTH: 10
        YEAR: 1952                
      
import java.util.*;
import java.io.*;
public class DaysElapsed {
    public static void main(String[] args) throws IOException {
        int day,month,year;
        int day1,month1,year1;
        boolean flag;
        Scanner in = new Scanner(System.in);
        DaysCalculation date = new DaysCalculation();
        DaysCalculation date1 = new DaysCalculation();
        do {
            System.out.println("INPUT THE FIRST DATE:");
            System.out.println("INPUT DAY:");
            day = in.nextInt();
            System.out.println("INPUT MONTH:");
            month = in.nextInt();
            System.out.println("INPUT YEAR:");
            year = in.nextInt();
            flag = date.checkDate(day,month,year);
            if (flag == false)
                System.out.println("INVALID,DATE,INPUT AGAIN");
            } while(flag != true);
        date.setDate(day,month,year);   
        do {
            System.out.println("INPUT THE SECOND DATE:");
            System.out.println("INPUT DAY:");
            day1 = in.nextInt();
            System.out.println("INPUT MONTH:");
            month1 = in.nextInt();
            System.out.println("INPUT YEAR:");
            year1 = in.nextInt();
            flag = date1.checkDate(day1,month1,year1);
            if (flag == false)
                System.out.println("INVALID,DATE,INPUT AGAIN");
            } while(flag != true);   
        System.out.println("DAYS ELAPSED:"+date.countDays(day1,month1,year1));       
        }
    }
class DaysCalculation {
    public void setDate(int d, int m, int y ){
        day = d;
        month = m;
        year = y;
        }
    public int countDays(int day1, int month1, int year1 ){
        int daysCount = 0;
        int y=0,y1=0;
        boolean small = false;
        if (year == year1)
            if (month == month1)
                if (day < day1)
                    small = true;
                else
                    small = false;       
            else if ( month < month1)
                small = true;
            else
                small = false;           
        else if( year < year1)
            small = true;
        else
            small = false;
        if (small == false) {
            int td,tm,ty;
            td = day;
            day = day1;
            day1 = td;
            tm = month;
            month = month1;
            month1 = tm;
            ty = year;
            year = year1;
            year1=ty;
            }   
        if (checkLeap(year) == true) {
                y += (ldays[month-1]-day);
                for ( int i = month; i <=11;i++)
                    y +=ldays[i];
                }
            else    {
                y += (mdays[month-1]-day);
                for ( int i = month; i <=11;i++)
                    y +=mdays[i];
                }    
            if (checkLeap(year1) == true) {
                y1 += day1-1;
                for ( int i = 0; i <month1-1;i++)
                    y1 +=ldays[i];
                }
            else    {
                y1 += day1-1;
                for ( int i = 0; i <month1-1;i++)
                    y1 +=mdays[i];
                }   
            for ( int i = year+1; i <= year1-1; i++) {
                if(checkLeap(i) == true)
                    daysCount +=366;
                else
                    daysCount +=365;
                }    
            if (year == year1)
                if (checkLeap(year) == true)
                    daysCount = y1-(366-y);
                else   
                    daysCount = y1-(365-y);   
            else    {
                daysCount += (y1+y);
                }           
        return daysCount;           
        }
    public boolean checkDate(int day, int month, int year) {
        if (checkLeap(year) == true) {
            if( 1 <= month && month <=12) {
                if(day>ldays[month-1] || day < 1 )
                    return false;
                else
                    return true;   
                }
            else
                return false;   
            }
        else {
            if( 1 <= month && month <=12) {
                if(day>mdays[month-1] || day < 1 )
                    return false;
                else
                    return true;   
                }
            else
                return false;   
            }
           
        }
    private boolean checkLeap(int year) {
        if(year%400==0)
           leap=true;
        else if (year%100==0)
           leap=false;
        else if (year%4==0)
           leap=true;
        else
           leap=false;
           return leap;
        }    
    private boolean flag;
    private static boolean leap;   
    private int day,month,year;
    private int daysCount;
    int[] mdays={31,28,31,30,31,30,31,31,30,31,30,31};
    int[] ldays={31,29,31,30,31,30,31,31,30,31,30,31};   
    }       

Monday, August 4, 2014

ISC COMPUTER SCIENCE PRACTICAL– 2000 DIAMOND SHAPE PATTERN

ISC COMPUTER SCIENCE PRACTICAL– 2000 DIAMOND SHAPE PATTERN, ISC JAVA PROGRAMS
Write a program to print a rectangle with diamond shape gap exactly at the centre of
the rectangle, using an input string with odd number of characters, not exceeding 20.

For example:

INPUT:

HAPPY-HAPPY
OUTPUT:

HAPPY HAPPY
HAPP      APPY
HAP           PPY
HA               PY
H                   Y
HA               PY
HAP           PPY
HAPP      APPY
HAPPY HAPPY

INPUT:

ISCPRAC*ISCPRAC

OUTPUT:

ISCPRAC ISCPRAC
ISCPRA     SCPRAC
ISCPR         CPRAC
ISCP              PRAC
ISC                  RAC
IS                       AC
I                            C
IS                       AC
ISC                  RAC
ISCP              PRAC
ISCPR         CPRAC
ISCPRA    SCPRAC
ISCPRAC ISCPRAC



import java.util.*;
import java.io.*;
public class DiamondShape {
    public static void main(String[] args) throws IOException {
        String msg;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));   
        System.out.println(" Enter the sentence:");
        msg = br.readLine();
        while ( msg.length() > 20 || (msg.length())%2 == 0) {
            System.out.println("INCORRECT FORMAT, INPUT AGAIN:");
            msg = br.readLine();
            }
        Pattern pt = new Pattern(msg);
        System.out.println("OUTPUT:");
        pt.patternPrint();
        }
    }   
class Pattern {
    Pattern(String msg) {
        inputMsg = msg;
        middle = (inputMsg.length()-1)/2;
        reverse = new String[middle+2];
        }
    public void patternPrint() {
       
        int index,temp = middle+1;
        index = temp;
        reverse[index] += inputMsg;
        for ( int i = middle; i > 0; i--) {  // loop to print the pattern till we have one character at left and one at right **
            reverse[index-1] = "";
            for ( int j = 0; j <= middle; j++) { // loop to print left half from the centre
                if ( j > i-1) {
                    System.out.print(" ");
                    reverse[index-1] += " ";
                    }
                else {   
                    System.out.print(inputMsg.charAt(j));
                    reverse[index-1] += inputMsg.charAt(j);
                    }
                }   
            for ( int k = middle+1; k < inputMsg.length(); k++) { // loop to print right half from the centre
                if( k < temp ) {
                    System.out.print(" ");
                    reverse[index-1] += " ";
                    }
                else {   
                    System.out.print(inputMsg.charAt(k));   
                    reverse[index-1] += inputMsg.charAt(k);
                    }
                }
            temp++;   
            index--;
            System.out.println();            
            }
        for ( int i = 2; i < middle+1; i++) // once the loop ** is completed we just print the string in reverse order to get the pattern
            System.out.println(reverse[i]);
       
        }   
    private String inputMsg;
    private String[] reverse;
    private int middle;
    }