import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class fileinput {
public static void main(String[] args) throws IOException {
BufferedReader br = null;
String sCurrentLine;
String emp[];
Scanner input=new Scanner(System.in);
String id;
boolean flag=false;
int position;
String position_desc="";
Double daily_rate=0.0;
System.out.print("Enter Code: ");
id=input.nextLine();
br = new BufferedReader(new FileReader("C:\\Users\\home\\Documents\\employees.txt"));
while ((sCurrentLine = br.readLine()) != null) {
emp=sCurrentLine.split(",");
if ( id.equals(emp[0]) ){
position= Integer.parseInt( emp[2] );
if (position==1){
position_desc="Manager";
daily_rate=650.0;
}else if(position == 2){
position_desc="Supervisor";
daily_rate=550.0;
}else if(position == 3){
position_desc="Messenger";
daily_rate=500.0;
}
System.out.println( "Name: " + emp[1]);
System.out.println( "Position: " + position_desc);
System.out.println( "Daily Rate: " + daily_rate);
flag=true;
}
}
if (flag==false ) System.out.println("Employee not found!");
}
}
No comments:
Post a Comment