pro

Ads

 
 

Share on Google+Share on Google+

dodo zayat
pro
2 Answer(s)      6 years and 9 months ago
Posted in : Java Beginners

a company need a system to store the data about the employees , the number of employees is dynamic , you need to store the following attributes : name , age , salary and note that we need to solve it using array and class

Ads
View Answers

December 7, 2010 at 1:07 PM


Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;
public class EmployeeData{
public static void main(String[] args) throws Exception{
    String name[]=new String[2];
    String age[]=new String[2];
    String salary[]=new String[2];
    String note[]=new String[2];
    Scanner input=new Scanner(System.in);
    for(int i=0;i<2;i++){
        System.out.println();
        System.out.println("Employe "+(i+1));
        System.out.print("Enter Name:  ");
        name[i]=input.nextLine();
        System.out.print("Enter Age:  ");
        age[i]=input.nextLine();
        System.out.print("Enter Salary:  ");
        salary[i]=input.nextLine();
        System.out.print("Enter Note:  ");
        note[i]=input.nextLine();
    }
    FileWriter fw=new FileWriter(new File("employee.txt"),true);
    BufferedWriter bw=new BufferedWriter(fw);
    for(int i=0;i<2;i++){
        bw.write(name[i]+" "+age[i]+" "+salary[i]+" "+note[i]);
        bw.newLine();
    }
    bw.close();
}
}

Thanks



December 7, 2010 at 1:07 PM


Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;
public class EmployeeData{
public static void main(String[] args) throws Exception{
    String name[]=new String[2];
    String age[]=new String[2];
    String salary[]=new String[2];
    String note[]=new String[2];
    Scanner input=new Scanner(System.in);
    for(int i=0;i<2;i++){
        System.out.println();
        System.out.println("Employe "+(i+1));
        System.out.print("Enter Name:  ");
        name[i]=input.nextLine();
        System.out.print("Enter Age:  ");
        age[i]=input.nextLine();
        System.out.print("Enter Salary:  ");
        salary[i]=input.nextLine();
        System.out.print("Enter Note:  ");
        note[i]=input.nextLine();
    }
    FileWriter fw=new FileWriter(new File("employee.txt"),true);
    BufferedWriter bw=new BufferedWriter(fw);
    for(int i=0;i<2;i++){
        bw.write(name[i]+" "+age[i]+" "+salary[i]+" "+note[i]);
        bw.newLine();
    }
    bw.close();
}
}

Thanks


Ads









Related Tutorials/Questions & Answers:
pro
Version of com.gocardless>gocardless-pro dependency
List of Version of com.gocardless>gocardless-pro dependency
Advertisements
Version of com.gocardless>gocardless-pro dependency
List of Version of com.gocardless>gocardless-pro dependency
Version of com.hynnet>jimi-pro dependency
List of Version of com.hynnet>jimi-pro dependency
home button macbook pro keyboard
home button macbook pro keyboard  what is the substitute of Home and End button on macbook pro keyboard?   Home = Function Key (Fn) + Left Arrow End = Function Key (Fn) + Right Arrow
Microsoft Visual Fox Pro - SQL
Microsoft Visual Fox Pro  how can create a query using sql on microsoft visual fox pro 6.0
Final Cut Pro X
Final Cut Pro X The Final Cut Pro X is the name of new innovation in the video... during video editing. In fact, today Final Cut Pro X has created... introduces the many formerly missing in action section of its Final Cut Pro site
Version of com.datomic>client-impl-pro dependency
List of Version of com.datomic>client-impl-pro dependency
WindowTester Pro
WindowTester Pro       Experience ultimate testing flexibility WindowTester Pro offers cutting-edge technology for testing Swing and SWT Java graphical user
Maven Dependency gocardless-pro >> 0.0.2
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version0.0.2 in your project
Maven Dependency gocardless-pro >> 0.2.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version0.2.0 in your project
Maven Dependency gocardless-pro >> 0.2.3
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version0.2.3 in your project
Maven Dependency gocardless-pro >> 0.4.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version0.4.0 in your project
Maven Dependency gocardless-pro >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version1.0.0 in your project
Maven Dependency gocardless-pro >> 1.11.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version1.11.0 in your project
Maven Dependency gocardless-pro >> 1.12.1
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version1.12.1 in your project
Maven Dependency gocardless-pro >> 1.12.4
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version1.12.4 in your project
Maven Dependency gocardless-pro >> 1.15.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version1.15.0 in your project
Maven Dependency gocardless-pro >> 1.15.3
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version1.15.3 in your project
Maven Dependency gocardless-pro >> 1.17.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version1.17.0 in your project
Maven Dependency gocardless-pro >> 1.2.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version1.2.0 in your project
Maven Dependency gocardless-pro >> 1.4.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version1.4.0 in your project
Maven Dependency gocardless-pro >> 1.6.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version1.6.0 in your project
Maven Dependency gocardless-pro >> 1.9.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version1.9.0 in your project
Maven Dependency gocardless-pro >> 2.2.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version2.2.0 in your project
Maven Dependency gocardless-pro >> 0.0.1
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version0.0.1 in your project
Maven Dependency gocardless-pro >> 0.0.3
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version0.0.3 in your project
Maven Dependency gocardless-pro >> 0.1.0
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version0.1.0 in your project
Maven Dependency gocardless-pro >> 0.2.1
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version0.2.1 in your project
Maven Dependency gocardless-pro >> 0.2.2
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version0.2.2 in your project
Maven Dependency gocardless-pro >> 0.2.4
You should include the dependency code given in this page to add Maven Dependency of com.gocardless >> gocardless-pro version0.2.4 in your project