Clawdue4k / SCC-IT2E-UNDANG

0 stars 0 forks source link

Salaries #1

Open Clawdue4k opened 1 week ago

Clawdue4k commented 1 week ago

package school;

public class Salaries { int eid,hours; String ename; double rates,deduct,gross,netpay;

public void addSalary(int id, String name, double rate, int hour, double deduction){
    this.eid = id;
    this.ename = name;
    this.rates = rate;
    this.hours = hour;
    this.deduct = deduction;
    this.gross = this.rates * this.hours;
    this.netpay = this.gross - this.deduct;
}

public void getSalary(){

    System.out.printf("%-10d %-10s %-10.2f %-10d %-10.2f %-10.2f %-10.2f\n",eid,ename,rates,hours,gross,deduct,netpay);
}

}

Clawdue4k commented 1 week ago

package school; import java.util.Scanner;

public class Salary { public void getSalary(){ Scanner sc = new Scanner(System.in); Salaries[] sr = new Salaries[100];

    System.out.print("Enter number of employees: ");
    int em = sc.nextInt();

    for(int i = 0; i < em; i++){
        System.out.println("Details of EMP "+(i+1));
        System.out.print("ID: ");
        int id = sc.nextInt();
        System.out.print("Name: ");
        String name = sc.next();
        System.out.print("Rate(Hour): ");
        double rate = sc.nextDouble();
        System.out.print("Hours worked: ");
        int hour = sc.nextInt();
        System.out.print("Total deduction: ");
        double deduction = sc.nextInt();

        sr[i] = new Salaries();
        sr[i].addSalary(id, name, rate, hour, deduction);

        System.out.println("");
    }

    double Tsalary = 0;
    double Tdeduction = 0;
    double Tnetpay = 0;

    System.out.println("\nEMP ID     Name       Rate       Hours      Gross      Deductions Netpay");
    for(int i = 0; i < em; i++){

        Tsalary += sr[i].gross;
        Tdeduction += sr[i].deduct;
        Tnetpay += sr[i].netpay;

        sr[i].getSalary();
    }
    System.out.println("-------------------------------------");
    System.out.println("Total salary for request: "+Tsalary);
    System.out.println("Total deductions: "+Tdeduction);
    System.out.println("Total salary to release: "+Tnetpay);
}

}