Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *Programmeur : David Chabot :^)
- *Date: Oct 25, 2014
- *Classe: ChabotDavidDevoir01.java
- *Description:Le Devoir #1 du cours Intro a la programmation.Calcule le salaire d'un employe fictif.
- */
- import java.util.Calendar;
- import javax.swing.*;
- public class ChabotDavidDevoir01 {
- public static void main (String [] args)
- {
- //Verifie que le string n'est pas vide.
- String info = JOptionPane.showInputDialog("Nom:Heures@taux").trim();
- String savedInfo = null;
- while (!info.equals("")) {
- info = JOptionPane.showInputDialog("Nom:Heures@taux").trim();
- int startIndexhdt = info.indexOf(':')+1;
- int endIndexhdt = info.indexOf('@');
- int startIndexth = info.indexOf('@')+1;
- int endIndexth = info.length();
- if (!info.equals("")) {
- double heuresDeTravail = Double.parseDouble(info.substring(startIndexhdt, endIndexhdt));
- double tauxHoraire= Double.parseDouble(info.substring(startIndexth,endIndexth));
- System.out.println(heuresDeTravail);
- System.out.println(tauxHoraire);
- savedInfo = info;
- double salaireRegulier = 0, salaireTempsDemi = 0, salaireSup = 0,salaireTotal = 0, salaireBonus =0;
- double salRegTotal= 0, salSupTotal = 0, SalTotTotal = 0;
- //Validation des heures de travail.
- if( heuresDeTravail <= 0 || heuresDeTravail > 60) {
- info = JOptionPane.showInputDialog("Nombre d'heures incorrect, essayez de nouveau. \n Nom:Heures@taux ").trim();
- }
- if( tauxHoraire <= 0) {
- info = JOptionPane.showInputDialog("Salaire incorrect, essayez de nouveau. \n Nom:Heures@taux ").trim();
- }
- //Calculs des salaires
- if (heuresDeTravail>40 && heuresDeTravail<45){
- salaireRegulier = 40*tauxHoraire;
- salaireTempsDemi = (heuresDeTravail-40)*tauxHoraire*1.5;
- salaireSup = 0.00;
- salaireTotal = salaireRegulier+salaireTempsDemi+salaireSup;
- salRegTotal += salaireRegulier;
- salSupTotal += salaireTempsDemi;
- SalTotTotal += salaireTotal;
- salaireBonus = salaireTempsDemi+salaireSup;
- //Imprime a la console le salaire,etc
- String name = info.substring(0,startIndexhdt);
- String ligne = String.format("%1$5fh %2$6f$ %3$10f$ %4$10f$ %5$10f$",heuresDeTravail,tauxHoraire,salaireRegulier,salaireBonus,salaireTotal);
- savedInfo += name+ligne;
- }
- else if (heuresDeTravail>45) {
- salaireRegulier = heuresDeTravail*tauxHoraire;
- salaireTempsDemi = 5*(tauxHoraire*1.5);
- salaireSup = heuresDeTravail-45*(tauxHoraire*2);
- salaireTotal = salaireRegulier+salaireTempsDemi+salaireSup;
- salRegTotal += salaireRegulier;
- salSupTotal += salaireTempsDemi;
- salSupTotal +=salaireSup;
- SalTotTotal += salaireTotal;
- String name = info.substring(0,startIndexhdt);
- String ligne = String.format("%1$5fh %2$6f$ %3$10f$ %4$10f$ %5$10f$",heuresDeTravail,tauxHoraire,salaireRegulier,salaireBonus,salaireTotal);
- savedInfo += name+ligne;
- }
- else
- {
- salaireRegulier = heuresDeTravail*tauxHoraire;
- salaireTotal = salaireRegulier;
- SalTotTotal += salaireTotal;
- String name = info.substring(0,startIndexhdt);
- String ligne = String.format("%1$5fh %2$6f$ %3$10f$ %4$10f$ %5$10f$",heuresDeTravail,tauxHoraire,salaireRegulier,salaireBonus,salaireTotal);
- savedInfo += name+ligne;
- }
- }
- }
- Calendar c = Calendar.getInstance();
- String date = String.format("%1$tY-%1$tm-%1$te %1$tH:%1$tM",c);
- //Imprime l'entete dans la console
- System.out.println("=============================================================================");
- System.out.println("Entreprise:DavidCorp™");
- System.out.println("Rapport de charge salariale: "+date);
- System.out.println("=============================================================================");
- System.out.println("nom NbH Taux Rég. Sup. Salaire");
- System.out.println("=============================================================================");
- System.out.println(savedInfo);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement