Thursday, November 18, 2010

Calling Several Java Methods

Java can have several methods inside its body and regardless of the number of methods defined and called, the main method is always the first method searched and executed.

The sample program below calls two other methods that need to return values to their calling method, the main.

[+/-] show/hide

* @(#)
* @author
* @version 1.00 2010/11/17

import javax.swing.*;
public class Salary {

double tdeductions;
double netpay;
public static void main(String args[]){

String name=JOptionPane.showInputDialog(null,"Input employee's name");

String GrossPay=JOptionPane.showInputDialog(null,"Input employee's Gross Pay");
String SSS=JOptionPane.showInputDialog(null,"Input employee's SSS");
String PH=JOptionPane.showInputDialog(null,"Input employee's Philhealth");
String Others=JOptionPane.showInputDialog(null,"Input employee's Other deductions");

double xGrosspay=Double.parseDouble(GrossPay);
double xSSS=Double.parseDouble(SSS);
double xPH=Double.parseDouble(PH);
double xOthers=Double.parseDouble(Others);
Salary x = new Salary ();

JOptionPane.showMessageDialog(null,"Name:"+name+"\nGross Pay"+xGrosspay+"\n SSS:"+xSSS+"\n Philhealth"+xPH+"\nOther deductions "+xOthers+"\n Deductions:"+x.computeDeductions(xSSS,xPH,xOthers)+"\n Net Pay:"+x.computeNetPay(xGrosspay));

double computeDeductions(double aSSS, double aPH, double aOthers)
return tdeductions;

double computeNetPay(double aGrosspay)
netpay=aGrosspay - tdeductions;
return netpay;


No comments: