TYBCS Java Assignment 5 - Sem I

SET A

1. Write a program to accept a string as command line argument and check whether it is a file or directory. If it is a directory, list the contents of the directory, count how many files the directory has and delete all files in that directory having extension .txt. (Ask the user if the files have to be deleted). If it is a file, display all information about the file (path, size, attributes etc).

2. Write a menu driven program to perform the following operations on a text file “phone.txt” which contains name and phone number pairs. The menu should have options: 

i. Search name and display phone number 
ii. Add a new name-phone number pair.


SET B

1. Write a program to read item information (id, name, price, qty) in file “item.dat”. Write a menu driven program to perform the following operations using Random access file:         

i. Search for a specific item by name. 
ii. Find costliest item. 
ii. Display all items and total cost 
 

Post a Comment

1 Comments

  1. Slip13_1: Write a program to accept a file name from command prompt, if the file exits
    then display number of words and lines in that file.
    import java.io.*;
    class slip13_1
    {
    public static void main(String argd[]) throws Exception
    {
    String fname=argd[0];
    File f=new File(fname);
    if(f.isFile())
    {
    FileInputStream fis=new FileInputStream(fname);
    int ch,cnt=0;
    while((ch=fis.read())!=-1)

    {
    if(ch=='\n')
    {
    cnt++;
    }
    }
    System.out.println("Number of line in Given file is "+cnt);
    }
    else
    {
    System.out.println("file not exists");
    }
    }
    }
    Slip 13_2: Write a program to display the system date and time in various
    formats shown below: Current date is : 31/08/2021
    Current date is : 08-31-2021
    Current date is : Tuesday August 31 2021
    Current date and time is : Fri August 31
    15:25:59 IST 2021 Current date and time is :
    31/08/21 15:25:59 PM +0530
    import java.text.SimpleDateFormat;
    import java.util.Date;
    class slip13_2
    {
    public static void main(String[] args)
    {
    Date date = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    String strDate= formatter.format(date);

    System.out.println(strDate);
    SimpleDateFormat formatter1 = new SimpleDateFormat("MM-dd-yyyy");
    String strDate1= formatter1.format(date);
    System.out.println(strDate1);
    SimpleDateFormat formatter2 = new SimpleDateFormat("EEEEE
    MMMMM dd yyyy");
    String strDate2= formatter2.format(date);
    System.out.println(strDate2);
    SimpleDateFormat formatter3 = new SimpleDateFormat("EEEEE
    MMMMM dd HH:mm:ss z yyyy");
    String strDate3= formatter3.format(date);
    System.out.println(strDate3);
    SimpleDateFormat formatter4 = new SimpleDateFormat("dd/MM/yyyy
    HH:mm:ss a");
    String strDate4= formatter4.format(date);
    System.out.println(strDate4);
    }
    }

    ReplyDelete