Results 1 to 9 of 9
  1. #1

    Default Need Help with Random Access File


    ga libog nako mga master, na stuck up nako.... unsay angay nako buhaton if level 1, dapat mo display cya ug salary na 1380.00....ako nani g suwayan ug if statement sulod sa loop (if salaryLvl == "1") sysout("1380.00"); wa may mo gawa....nag libug ko ani kay mo tawag man ko ug string sa txt file, murag sayup to ako pamaagi na g == nako ug "1"


    mao ni sulod sa akong text file...kanang naay 1,2,3 sa kinalasan mao na ilang level
    --------------------------
    Juan_De_La_Cruz,A001,1
    Miriam_Bismonte,A002,1
    Gloria_Macapagal,A003,3
    Manny_Pacquiao,A004,3
    Jose_Rizal,A005,2
    -------------------------

    mao ni akong code

    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.util.Scanner;


    public class Payroll
    {

    public Payroll()
    {
    }

    static Scanner input = new Scanner(System.in);
    static RandomAccessFile instream;

    public static void main(String [] args)
    {
    System.out.println("enter:");
    String data;
    String id = "", name = "",id2 = "", salaryLvl = "";
    boolean found = false;
    String idToFind = input.next();



    try
    {

    instream = new RandomAccessFile("employee.txt","r");
    int numberOfRecords = 5;
    instream.seek(0);
    for(int i = 0; i < numberOfRecords; i++)
    {
    data = instream.readLine();

    String [] record;
    record = data.split(",");

    for(int x = 0; x < record.length;x++)
    id = record[1];
    name = record[0];
    salaryLvl = record[2];

    if(id.equals(idToFind))
    {
    System.out.println(name);
    System.out.println(id);
    System.out.println(salaryLvl);

    if(salaryLvl == "1")
    {
    System.out.println("weee");
    }

    found = true;
    break;

    }



    }
    if(!found)
    System.out.println("not found!");
    }//try

    catch(IOException e)
    {
    }


    }
    }

  2. #2

    Default Re: Need Help with Random Access File

    T.S ingon akong amigo try daw ani

    // read the file by line and store line in data variable
    while ((data = instream.readLine()) != null) {
    // makuha na nimo ang line then parse lang what you need to do sa line
    }

  3. #3

    Default Re: Need Help with Random Access File

    kini pud:

    if(salaryLvl.equals("1"))
    {
    System.out.println("weee");
    }

  4. #4

    Default Re: Need Help with Random Access File

    Quote Originally Posted by akocdiego View Post
    if(salaryLvl == "1")
    {
    System.out.println("weee");
    }
    daghan kau ko saup nakita sa imo code. pro huwat lng ko kng makitan nmo, sa kron kani lng sa heheheh..

    salaryLvl.equals("1") ilisi sa akong g bold


    practice jud ug maau
    Last edited by trylle; 10-17-2012 at 01:58 PM.

  5. #5

    Default Re: Need Help with Random Access File

    salamat ooyak sa inyung mga tabang mga master....ari napud ko na stuck up, inig write nako padung sa txt file nag libog nako unsaon pag gamit ang .split...(kamo rah ko ani sa read) ako unta i split ang oras sa hour ug minute nya i split pajud nko ang time-in time-out sa lain2x na adlaw... so far mao ni akong na code.....

    import java.io.*;
    import java.util.Scanner;


    public class Payroll
    {


    public Payroll()
    {
    }

    static Scanner console = new Scanner(System.in);
    static RandomAccessFile instream;

    public static void main(String [] args )
    {
    System.out.print("Enter id: ");
    String data;
    String employeeId, employeeName, salaryLvl;
    String monTimeIn, monTimeOut, tueTimeIn, tueTimeOut, wedTimeIn, wedTimeOut, thuTimeIn, thuTimeOut , friTimeIn, friTimOut;
    boolean found = false;
    String idToFind = console.next().toUpperCase();

    try
    {

    instream = new RandomAccessFile("employee.txt","r");
    int numberOfRecords = 5;
    instream.seek(0);

    for(int i = 0; i < numberOfRecords; i++)
    {
    data = instream.readLine();

    String [] record;
    record = data.split(",");

    for(int x = 0; x < record.length;x++)
    {
    employeeId = record[1];
    employeeName = record[0];
    salaryLvl = record[2];

    if(employeeId.equals(idToFind))
    {
    System.out.println("----------------------");
    System.out.println("Name: " + employeeName);
    System.out.println("ID: " + employeeId);
    System.out.println("Salary Lvl: " + salaryLvl);

    if(salaryLvl.equals("1"))
    System.out.println("Salary rate: P1380.00/day");

    else if(salaryLvl.equals("2"))
    System.out.println("salary rate: P2450.00/day");

    else if (salaryLvl.equals("3"))
    System.out.println("Salary rate: P3550.00/day");




    found = true;
    break;

    }//boolean
    }//inside loop
    }//for loop


    if(!found)
    System.out.println("not found!");
    }//try

    catch(IOException e)
    {
    }

    try
    {
    RandomAccessFile write = new RandomAccessFile("dtr.txt", "rw");

    System.out.println("--------------------------");
    System.out.print("Time-in for Monday: ");
    monTimeIn = console.next();
    write.writeBytes(monTimeIn);
    System.out.print("Time-out for Monday: ");
    monTimeOut = console.next();
    write.writeBytes(monTimeOut);

    System.out.print("Time-in for Tuesday: ");
    tueTimeIn = console.next();
    write.writeBytes(tueTimeIn);
    System.out.print("Time-out for Tuesday: ");
    tueTimeOut =console.next();
    write.writeBytes(tueTimeOut);

    System.out.print("Time-in for Wednesday: ");
    wedTimeIn = console.next();
    write.writeBytes(wedTimeIn);
    System.out.print("Time-out for Wednesday: ");
    wedTimeOut = console.next();
    write.writeBytes(wedTimeOut);

    System.out.print("Time-in for Thursday: ");
    thuTimeIn = console.next();
    write.writeBytes(thuTimeIn);
    System.out.print("Time-out for Thursday: ");
    thuTimeOut = console.next();
    write.writeBytes(thuTimeOut);

    System.out.print("Time-in for Friday: ");
    friTimeIn = console.next();
    write.writeBytes(friTimeIn);
    System.out.print("Time-out for Friday: ");
    friTimOut = console.next();
    write.writeBytes(friTimOut);

    }

    catch(IOException e)
    {


    }

    finally
    {
    try
    {
    instream.close();
    }

    catch(IOException io){}
    }
    }//main
    }

  6. #6

    Default Re: Need Help with Random Access File

    mga basic lage inuha code.?

  7. #7

    Default Re: Need Help with Random Access File

    Quote Originally Posted by print+="helloworld" View Post
    mga basic lage inuha code.?
    istudyante paman ang TS hehehe

  8. #8

    Default Re: Need Help with Random Access File

    @akocdiego e trap sa daan ang input sa user. nya hatag example format sa input.

  9. #9

    Default Re: Need Help with Random Access File

    salamat mga master, g loop nako ang uban codes para d kaau taas...nag patabang nlng ko ug maestro, nakuha na tawn nako....may nlng nka fasar ko sa finals...post rah nya ko diri inig sugod napud sa 2nd sem

  10.    Advertisement

Similar Threads

 
  1. need help with file upload :)
    By c-chan in forum Programming
    Replies: 5
    Last Post: 04-06-2010, 10:56 AM
  2. NEED HELP WITH .mdf FILE
    By saulrhyz in forum Software & Games (Old)
    Replies: 3
    Last Post: 04-16-2008, 11:40 AM
  3. Need help with accessing my "gpedit.msc" cant seem to find it...
    By Maverick007 in forum Software & Games (Old)
    Replies: 3
    Last Post: 10-11-2007, 09:28 PM
  4. need help with p900
    By kloos in forum Gizmos & Gadgets (Old)
    Replies: 8
    Last Post: 09-04-2006, 01:55 PM
  5. Need help with CSS png transparency.
    By silent-kill in forum Websites & Multimedia
    Replies: 1
    Last Post: 07-01-2005, 11:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top