Hilan International Bank decided to have a salary plan for its employees. In the new Policy, bonus is based on the fact that one is a senior staff or junior staff. You have been called in as a programmer to develop a software to meet this policy’s requirement:
(a.) Create a class called Salary.
(b.) Create methods/functions that will calculate
i. the tax which is 5% of the gross salary
ii. Bonus depending on the status of employee-senior/junior
Senior staff-1hr-15 US dollars
Junior staff-1hr-12 US dollars
iii. Net Salary=Bonus+gross salary-tax
(c.)Create another class called SalDemo with the main function
(d.)Declare an instance of the salary class called cal.
(e.)Use the cal object to check the net salary
(f.)Use JOptionPane to allow a user to enter the status, time and the gross salary.

solution

import javax.swing.JOptionPane;
 class salary{
 	String status;
 	double T;   //T represents time.
 	double gross_salary;
 	double bonus;
 	double GetTax(double gross_salary){
 		double tax=gross_salary*0.05;
 		return tax;
 	}
 	double GetBonus(double T,String status){
 			if(status=="senior staff"){
 			double bonus=T*15;
 			}
 		         else if(status=="junior staff"){
 				 bonus=T*12;
 				 }		
 				return bonus;
 	}
 	double GetNetSalary(double bonus,double gross_salary,double tax){
 		double netSalary=(bonus+gross_salary)-tax;
 		return netSalary;
 	}
 }
 class SalDemo{
 	public static void main(String args[]){
 		salary cal = new salary();
 		String T=JOptionPane.showInputDialog("Enter time");
 		double time=Double.parseDouble(T);
 		String status=JOptionPane.showInputDialog("Enter status");//where st represent status.
 		String st=String.parseString(status);
 		String g_salary=JOptionPane.showInputDialog("Enter gross salary");
 		double gross_salary=Double.parseDouble(g_salary);
 		System.out.println(cal.GetTax(gross_salary));
 		System.out.println(cal.GetBonus(time,status));
 		System.out.println(cal.GetNetSalary(cal.GetBonus(time,status),gross_salary,(cal.GetTax(gross_salary))));
 		JOptionPane.showMessageDialog(null,"Your Net salary is ="+cal.GetNetSalary
 			(cal.GetBonus(time,status),gross_salary,(cal.GetTax(gross_salary))));
 	}
 }

Because there is no parseString method in String. Simply assign the provided String to the new variable. The API docs are your friend, BTW. Ask them first.

cross-posted and all because someone can't use five minutes to read the API docs, but will spend days waiting on someone else to read it for him.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.