Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


dodo zayat
pro
2 Answer(s)      3 years and 11 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


Advertisement
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



Related Tutorials/Questions & Answers:
pro
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
Advertisements
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
WindowTester Pro
WindowTester Pro       Experience ultimate testing flexibility WindowTester Pro offers cutting-edge technology for testing Swing and SWT Java graphical user
Re-installing Mac OS X on Mac Book Pro by formatting the Hard Disk
and then reinstalling the Mac OS X on your Mac Book Pro. Sometimes you need to reinstallMac OS X on your Mac Book pro due to certain reasons and often it looks a tedious task but it is actually not so. You can reinstall your Mac Book pro
GNATbench
GNATbench       GNATbench for Wind River Workbench brings the advantages of AdaCore?s GNAT Pro toolset to Wind River?s Workbench integrated development environment
XMLBuddy
. Now in two models: XMLBuddy and XMLBuddy Pro. Key features of XMLBuddy Pro
Clear Data Builder
Clear Data Builder        Clear Data Builder Plugin automates Flex-Java development with Flex Data Services: whether you are a Java Pro or have never coded in Java before
hi
hi   'print("code sample");`class example(){ public.static.void.main(); system.out.println("this is first pro");}   class example{ public static void main(String[]args){ System.out.println("this is first pro
Java - Java3D
Java  , Java Windows XP pro 64-bit Prompt please what install Java on computer with system Windows XP pro 64-bit
javascipt - Java Beginners
"; var pro_desc = document.createElement('input'); pro_desc.type="text"; pro_desc.id="pro_desc"; pro_desc.size=22
registration key - Java Beginners
registration key  I want the serial key for JCreator Pro 4.50. I lost it. If any body has it please send
javascript - Java Beginners
pro_desc = document.createElement('input'); pro_desc.type="text"; pro_desc.id="pro_desc"; pro_desc.size=13; pro
javascript - Java Beginners
"; var pro_desc = document.createElement('input'); pro_desc.type="text"; pro_desc.id="pro_desc"; pro_desc.size=22
programming of foxpro
programming of foxpro  hello sir , sir i am use the foxpro . but i know about c . sir how can i learn fox pro . i know about something about foxpro
PaintShopProTutorials
Paint Shop Pro Tutorials   ... NNTP forums for Paint Shop Pro, Photo Album and Studio are now available... Shop Pro Tutorial The only thing better than getting new software
conncetion with oracle throuth jdbc - JDBC
conncetion with oracle throuth jdbc  i use jdk1.5 when i compile our JDBC java pro. with ojdbc14.jar file it give no error. but when i run that class it give error of unsupported class version. which jar file use for compile
Get Java Version
array variable name 'pro' is initialized with respective value. 1.... for loop is used to display the name of Java version present in String pro using System.out.println. 2)properties.getproperties(pro[i])-This method return you
Andrew Stone Designs Twitter Applications
developed by Stone Designs called Twittlelator Pro. The Andrew Stone developed... The Twittelator Pro for iphone has the following features: Copy and Paste support
struts2
struts2  how to read properties file in jsp of struts2   Hi, You can use the Properties class of Java in your action class. Properties pro = new Properties(); FileInputStream in = new FileInputStream(f); pro.load
program and Interface builder
more custom them you will use UI elements pro grammatically and if you are making
Problem with Link To website with my Java Appliaction - Java Beginners
*; public class menu5 extends JFrame //implements ActionListener { //coursefrm pro... actionPerformed(ActionEvent ae){ coursefrm pro=new coursefrm(); pro.dis...); } public static void main(String z[]){ menu5 pro=new menu5(); pro.dis
GWT Designer
WindowBuilder Pro? and leverages its sophisticated development facilities
How to open an Acroform in iText?
How to open an Acroform in iText?  I modified a client's Acroform in Acrobat Pro 9, and now the client says he can't open it in iText. I had never even heard of iText before this. It's been a while since I did any Java coding
How to find the exact PHP template I need?
How to find the exact PHP template I need?  Hi! I'm a PHP Pro?I think I am one?, but this is the first time for me to try a PHP template, so I have no clue on how to choose one. Do you have some tips to help me choose
Java - Development process
to integrate two java program. u can integrate java pro with other software or tool
How to Upload Site Online
and office. Since 1999, CuteFTP Pro and CuteFTP Mac Pro have also been available alongside CuteFTP Home with free trial periods. WS_FTP Pro is a Windows-based program
Paint.NET
editing software packages such as Adobe Photoshop, Corel Paint Shop Pro
Advertisements
 

 

 

DMCA.com