import java.util.Scanner;
public class Mini_Project {
public static void main(String[] args) {
int i = 0;
Scanner sc = new Scanner(System.in);
int emp_no;
String employee_info[][] =
{
{"1001", "Ashish", "01/04/2009", "e", "R&D", "20000", "8000", "3000"},
{"1002", "Sushma", "23/08/2012", "c", "PM", "30000", "12000", "9000"},
{"1003", "Rahul", "12/11/2008", "k", "Acct", "10000", "8000", "1000"},
{"1004", "Chahat", "29/01/2013", "r", "Front Desk", "12000", "6000", "2000"},
{"1005", "Ranjan", "16/07/2005", "m", "Engg", "50000", "20000", "20000"},
{"1006", "Suman", "1/1/2000", "e", "Manufacturing", "23000", "9000", "4400"},
{"1007", "Tanmay", "12/06/2006", "c", "PM", "29000", "12000", "10000"}
};
String DA[][] =
{
{"e", "Engineer", "20000"},
{"c", "Consultant", "32000"},
{"k", "Clerk", "12000"},
{"r", "Receptionist", "15000"},
{"m", "Manager", "40000"}
};
System.out.println("Enter the employee number.");
emp_no = sc.nextInt();
for(i = 0; i < employee_info.length; i++)
{
if(emp_no == Integer.parseInt(employee_info[i][0]))
{
emp_no = Integer.parseInt(employee_info[i][0]);
break;
}
if(i == 6)
{
System.out.println("There is no employee with emp id : " + emp_no);
}
}
String emp_name = employee_info[i][1];
String emp_dept = employee_info[i][4];
char emp_designation_code = employee_info[i][3].charAt(0);
String emp_designation = "NULL";
int emp_salary = 0;
int basic = Integer.parseInt(employee_info[i][5]);
int hra = Integer.parseInt(employee_info[i][6]);
int it = Integer.parseInt(employee_info[i][7]);
switch(emp_designation_code)
{
case 'e': emp_designation = DA[0][1];
emp_salary = basic + hra + Integer.parseInt(DA[0][2]) - it;
break;
case 'c': emp_designation = DA[1][1];
emp_salary = basic + hra + Integer.parseInt(DA[1][2]) - it;
break;
case 'k': emp_designation = DA[2][1];
emp_salary = basic + hra + Integer.parseInt(DA[2][2]) - it;
break;
case 'r': emp_designation = DA[3][1];
emp_salary = basic + hra + Integer.parseInt(DA[3][2]) - it;
break;
case 'm': emp_designation = DA[4][1];
emp_salary = basic + hra + Integer.parseInt(DA[4][2]) - it;
break;
}
if(emp_no == 1001 || emp_no== 1002 ||emp_no == 1007)
{
System.out.println("Emp No.\t\tEmp Name\t\tDepartment\t\tDesignation\t\tSalary");
System.out.println(emp_no+"\t\t"+emp_name +"\t\t\t"+emp_dept+"\t\t\t"+emp_designation+"\t\t"+emp_salary);
}
if(emp_no == 1003 || emp_no == 1005)
{
System.out.println("Emp No.\t\tEmp Name\t\tDepartment\t\tDesignation\t\tSalary"); System.out.println(emp_no+"\t\t"+emp_name+"\t\t\t"+emp_dept+"\t\t\t"+emp_designation+"\t\t\t"+emp_salary);
}
if(emp_no == 1004 || emp_no == 1006)
{
System.out.println("Emp No.\t\tEmp Name\t\tDepartment\t\tDesignation\t\tSalary");
System.out.println(emp_no+"\t\t"+emp_name +"\t\t\t"+emp_dept+"\t\t"+emp_designation+"\t\t"+emp_salary);
}
sc.close();
}
}
I want to remove the error from the output and want to print "There is no employee with emp id:" this only. Right now it is printing both output and error. How can I remove the error without to print only the statement if the emp no entered is not present in the array employee_info?
If it is possible to remove the error without using try and catch block then how can I do so.