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
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
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