Hi,
I format your code like this,
import java.util.Scanner;
public class YearEndBonus {
private double years;
private double salary;
public double bonus;
public YearEndBonus (double years,double salary)
{
this.years=years;
this.salary=salary;
}
public double busLogic()
{
if(years == 1){
bonus=salary*.10;
}
else if((years >=2)&&(years<=5)){
bonus=salary*.20;
}
else if((years >=6)&&(years<=10)){
bonus=salary*.50;
}
else if(years >=11){
bonus=salary*.75;
}
return bonus;
}
public void showData()
{
System.out.println("Bonus = "+ busLogic());
}
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in);
System.out.println("Years in service: ");
double years = sc.nextDouble();
System.out.println("Salary: ");
double salary = sc.nextDouble();
YearEndBonus yrBonus=new YearEndBonus (years,salary);
yrBonus.busLogic();
yrBonus.showData();
}
}
You can also use getter and setter methods to get the input that is upto you. But you can use methods, it is useful for resusing the code whenever we want the same functionality.
If any clarification please post here