Problem Statement:
In a company the salary structure is based upon the category and basic pay. The employee table has the following fields:
1. Employee Id 2. Name 3. Employee Category 4. Basic Pay
The salary consist of the components shown below:
Salary Component Category1 Category2 Category3
Dearness Allowance 87% 65% 45%
House Rent Allowance 8% 9% 10%
Other Allowance 0% 0% 2%
Vehicle Allowance Rs 500 Rs 1000 10%
Write a program to query the database for total salary of an employee. Assume the database is available (create database in Oracle thru SQLplus) in a server machine. The input format is has the following format from a client.
Input and Output Requirements:
The client accepts the employee id from the terminal through the applet. This is passed to server which calculates the total salary based on the category. The salary is send back to the client and is displayed on the applet.
Algorithm:
Server Side Connection procedure:
Create a server socket and begin listening
ServerSocket serSocket = new ServerSocket(port)
which creates a server socket and bind it to the port
Call accept() method to get new connections
Socket client = serSocket.accept()
this method returns a connected client socket used to converse with the caller.
Create input and output streams for the socket
DataInputStream inStream= new DataInputStream(client.getInputStream());
DataOutputStream outStream = new
DataOutputStream(client.getOutputStream());
Conduct the conversation based on agreed protocol
Close client streams and socket
Go back to step 2 or continue step7
Close the server socket
Client Side Connection procedure:
Create a client socket
Acquire input and output streams for the socket
Conduct the conversation based on agreed protocol
Close client streams and socket
Procedure CalculateSalary(Employeeid)
getdata(Employeeid)
if category = 1 then
da = basic pay * 0.87
hra = basic pay * 0.8
oa = 0
va = 500
elseif category = 2 then
da = basic pay * 0.65
hra = basic pay * 0.9
oa = 0
va = 1000
elseif category = 3 then
da = basic pay * 0.45
hra = basic pay * 0.10
oa = basic pay * 0.02
va = basic pay * 0.10
salary = da + hra + oa + va
return salary
End CalculateSalary
Program:
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; import java.awt.*; import java.awt.event.*; public class emp_sal extends Frame implements ActionListener { Frame fr; TextField id,sal; Button B1; TextArea TA; Label L1,L2,L3; public void setup() { fr = new Frame("Employee Details"); fr.setLayout(new GridLayout(7,7)); fr.setSize(300, 300); id = new TextField(7); sal = new TextField(10); TA = new TextArea("",10,30); B1 = new Button("Find Total Salary"); L1 = new Label("Employee ID : "); L2 = new Label("Details : "); L3 = new Label("Salary : "); fr.add(L1); fr.add(id); fr.add(B1); fr.add(L2); fr.add(TA); fr.add(L3); fr.add(sal); B1.addActionListener(this); fr.show(); } public void actionPerformed(ActionEvent ae) { String ID = id.getText(); TA.setText(""); if(ae.getActionCommand().equals("Find Total Salary")) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection ("jdbc:odbc:myds","system","manager"); Statement stmt = con.createStatement(); String query = "Select * from employee WHERE emp_id ='" + ID + "'"; ResultSet rs = stmt.executeQuery(query); ResultSetMetaData rmdt = rs.getMetaData(); int cols = rmdt.getColumnCount(); if(rs.next()) { for(int i = 1 ; i <= cols; i++) TA.setText(TA.getText() + rmdt.getColumnName(i)+ " : " + rs.getString(i)+ " \n "); } query = "Select * from employee WHERE emp_id ='" + ID + "'"; rs = stmt.executeQuery(query); rmdt = rs.getMetaData(); cols = rmdt.getColumnCount(); if(rs.next()) { String cat = rs.getString("emp_cat"); String b_pay = rs.getString("basic_pay"); if(cat.equalsIgnoreCase("1")) { double tot_sal = (.87 * Double.parseDouble(b_pay)) + (.8 * Double.parseDouble(b_pay)) + 0 + 500; sal.setText(Double.toString(tot_sal)); } if(cat.equalsIgnoreCase("2")) { double tot_sal = (.65 * Double.parseDouble(b_pay)) + (.9 * Double.parseDouble(b_pay)) + 0 + 1000; sal.setText(Double.toString(tot_sal)); } if(cat.equalsIgnoreCase("3")) { double tot_sal = (.45* Double.parseDouble(b_pay)) + (.10* Double.parseDouble(b_pay)) + 0 + (.02 * Double.parseDouble(b_pay)); sal.setText(Double.toString(tot_sal)); } } } catch(Exception e) { System.out.println(e.getMessage()); } } } public void closeApp() { fr.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); } public static void main(String[] args) { emp_sal emp = new emp_sal(); emp.setup(); emp.closeApp(); } } |
Output:
Happy republic day says
I seriously love your blog.. Excellent colors & theme.
Did you develop this amazing site yourself? Please reply back as I’m
wanting to create my own personal site and would love to
find out where you got this from or what the theme is called.
Appreciate it!
Vysakh V says
Hi, Thanks you. Yes, I developed this site myself. It’s a WordPress website and used News Pro Theme on Genesis Framework. You can create your own website by registering on WordPress then buy a genesis frame work and choose a theme.
I recommend Bluehost hosting service it is best for hosting and also you will get a one free domain name. You can use this link to SignUp: http://bluehost.in/?utm_source=affiliate&a_aid=51b57878
For Bluehost.com site sign up here: http://bluehost.com/track/shouttoworld.
gadget scanner says
This post is invaluable. Where can I find out more?
Vysakh V says
Check my other java examples post.
click here says
Pretty nice post. I just stumbled upon your blog and wished to say that I have really enjoyed browsing your blog posts.
In any case I’ll be subscribing to your rss feed and I
hope you write again soon!
Vysakh V says
Thanks for your interest. Yes I will add new contents soon.
Friendship Shayari says
This is my first time pay a visit at here and
i am actually pleassant to read all at alone place.
Vysakh V says
Thanks 🙂
www.bankofamerica.com says
Hey there! This is kind of off topic but I need some
help from an established blog. Is it very difficult to set up your own blog?
I’m not very techincal but I can figure things out pretty quick.
I’m thinking about setting up my own but I’m not sure where to start.
Do you have any tips or suggestions? Many
thanks
Vysakh V says
Hi, you can set up your own blog easily. It’s very easy to create in WordPress platform. Register on WordPress then buy a genesis frame work and choose a theme according to your blog contents. I recommend Bluehost hosting service it is best for hosting and also you will get a one free domain name. You can use this link to SignUp: http://bluehost.in/?utm_source=affiliate&a_aid=51b57878
For Bluehost.com site sign up here: http://bluehost.com/track/shouttoworld.
For more help contact me via mail: admin@shouttoworld.com
eebest8 back says
“Good information. Lucky me I recently found your website by chance (stumbleupon). I have saved as a favorite for later!”
more suggestions says
I loved your blog. Really Great.
how to pick powerball numbers says
Appreciate you sharing, great blog. Fantastic.
motuandpatlugames.com says
Muchos Gracias for your blog.Really thank you! Keep writing.
motupatlugameshd says
Very good blog article.Really thank you! Great.
hamptonbaylightinghd says
Wow, great blog.Really thank you!
motuandpatlugames.in says
Thanks again for the blog post.Really thank you! Great.
boat rental says
Major thanks for the article post.Really looking forward to read more. Awesome.