Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. /*
  2. *Programmeur : David Chabot :^)
  3. *Date: Oct 25, 2014
  4. *Classe: ChabotDavidDevoir01.java
  5. *Description:Le Devoir #1 du cours Intro a la programmation.Calcule le salaire d'un employe fictif.
  6. */
  7. import java.util.Calendar;
  8.  
  9. import javax.swing.*;
  10. public class ChabotDavidDevoir01 {
  11. public static void main (String [] args)
  12. {
  13. //Verifie que le string n'est pas vide.
  14. String info = JOptionPane.showInputDialog("Nom:Heures@taux").trim();
  15. String savedInfo = null;
  16. while (!info.equals("")) {
  17. info = JOptionPane.showInputDialog("Nom:Heures@taux").trim();
  18. int startIndexhdt = info.indexOf(':')+1;
  19. int endIndexhdt = info.indexOf('@');
  20. int startIndexth = info.indexOf('@')+1;
  21. int endIndexth = info.length();
  22.  
  23. if (!info.equals("")) {
  24. double heuresDeTravail = Double.parseDouble(info.substring(startIndexhdt, endIndexhdt));
  25. double tauxHoraire= Double.parseDouble(info.substring(startIndexth,endIndexth));
  26. System.out.println(heuresDeTravail);
  27. System.out.println(tauxHoraire);
  28. savedInfo = info;
  29. double salaireRegulier = 0, salaireTempsDemi = 0, salaireSup = 0,salaireTotal = 0, salaireBonus =0;
  30. double salRegTotal= 0, salSupTotal = 0, SalTotTotal = 0;
  31. //Validation des heures de travail.
  32. if( heuresDeTravail <= 0 || heuresDeTravail > 60) {
  33. info = JOptionPane.showInputDialog("Nombre d'heures incorrect, essayez de nouveau. \n Nom:Heures@taux ").trim();
  34. }
  35. if( tauxHoraire <= 0) {
  36. info = JOptionPane.showInputDialog("Salaire incorrect, essayez de nouveau. \n Nom:Heures@taux ").trim();
  37. }
  38. //Calculs des salaires
  39. if (heuresDeTravail>40 && heuresDeTravail<45){
  40.  
  41. salaireRegulier = 40*tauxHoraire;
  42. salaireTempsDemi = (heuresDeTravail-40)*tauxHoraire*1.5;
  43. salaireSup = 0.00;
  44. salaireTotal = salaireRegulier+salaireTempsDemi+salaireSup;
  45. salRegTotal += salaireRegulier;
  46. salSupTotal += salaireTempsDemi;
  47. SalTotTotal += salaireTotal;
  48. salaireBonus = salaireTempsDemi+salaireSup;
  49. //Imprime a la console le salaire,etc
  50.  
  51. String name = info.substring(0,startIndexhdt);
  52. String ligne = String.format("%1$5fh %2$6f$ %3$10f$ %4$10f$ %5$10f$",heuresDeTravail,tauxHoraire,salaireRegulier,salaireBonus,salaireTotal);
  53. savedInfo += name+ligne;
  54.  
  55. }
  56. else if (heuresDeTravail>45) {
  57.  
  58. salaireRegulier = heuresDeTravail*tauxHoraire;
  59. salaireTempsDemi = 5*(tauxHoraire*1.5);
  60. salaireSup = heuresDeTravail-45*(tauxHoraire*2);
  61. salaireTotal = salaireRegulier+salaireTempsDemi+salaireSup;
  62. salRegTotal += salaireRegulier;
  63. salSupTotal += salaireTempsDemi;
  64. salSupTotal +=salaireSup;
  65. SalTotTotal += salaireTotal;
  66. String name = info.substring(0,startIndexhdt);
  67. String ligne = String.format("%1$5fh %2$6f$ %3$10f$ %4$10f$ %5$10f$",heuresDeTravail,tauxHoraire,salaireRegulier,salaireBonus,salaireTotal);
  68. savedInfo += name+ligne;
  69.  
  70.  
  71.  
  72. }
  73. else
  74. {
  75. salaireRegulier = heuresDeTravail*tauxHoraire;
  76. salaireTotal = salaireRegulier;
  77. SalTotTotal += salaireTotal;
  78. String name = info.substring(0,startIndexhdt);
  79. String ligne = String.format("%1$5fh %2$6f$ %3$10f$ %4$10f$ %5$10f$",heuresDeTravail,tauxHoraire,salaireRegulier,salaireBonus,salaireTotal);
  80. savedInfo += name+ligne;
  81. }
  82. }
  83. }
  84.  
  85.  
  86. Calendar c = Calendar.getInstance();
  87. String date = String.format("%1$tY-%1$tm-%1$te %1$tH:%1$tM",c);
  88. //Imprime l'entete dans la console
  89. System.out.println("=============================================================================");
  90. System.out.println("Entreprise:DavidCorp™");
  91. System.out.println("Rapport de charge salariale: "+date);
  92. System.out.println("=============================================================================");
  93. System.out.println("nom NbH Taux Rég. Sup. Salaire");
  94. System.out.println("=============================================================================");
  95. System.out.println(savedInfo);
  96. }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement