1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| import java.io.*;
/**
*
* @author Informatique
*/
public class impots {
public static void main(String arg[]){
//Données
//Limites des tranches d'impots
double Limites[]={12620,13190,15640,24740,31810,39970,48360,55790,92970,127860,151250,172040,195000,0};
//Coefficients appliqués
double coeffn[]={0,631,190.5,2072.5,3309.5,4900,6892.5,9316.5,12106,16754.5,23147.5,30710,39312,49062};
//Le programme
//Création du flux d'entré clavier
BufferedReader IN=null;
try{
IN=new BufferedReader(new InputStreamReader(System.in));
}catch(Exception e){
System.err.println("Creation de flux d'entré");
}
//On récupère le statut marital
boolean OK=false;
String reponse=null;
while(! OK){
try{
System.out.println("Êtes-vous marié(e) (O/N)?");
reponse=IN.readLine();
reponse=reponse.trim().toLowerCase();
if(! reponse.equals("o") && !reponse.equals("n")) {
System.out.println("Réponse incorrecte. Recommencer");
}
else {
OK=true;
}
}catch(Exception e){
erreur("Lecture etat marital",e,2);
}
}
boolean Marie = reponse.equals("o");
//Nombre d'enfant
OK=false;
int NbEnfants=0;
while(! OK){
try{
System.out.println("Nombre d'enfant : ");
reponse=IN.readLine();
try{
NbEnfants=Integer.parseInt(reponse);
if(NbEnfants>=0) {
OK=true;
}
else {
System.err.println("Réponse incorrecte.Recommencez");
}
}catch(Exception e){
System.err.println("Réponse incorrecte.Recommencez");
}
}catch(Exception e){
erreur("Lecture etat marital",e,2);
}
}
OK=false;
long Salaire=0;
while(! OK){
try{
System.out.println("Salaire annuel : ");
reponse=IN.readLine();
try{
Salaire=long.parseLong(reponse);
if(Salaire>0){
OK=true;
}
else{
System.err.println("Réponse incorrecte Recommencez");
}
}catch(Exception e){
System.err.println("Réponse incorrecte Recommencez");
}
}catch(Exception e){
erreur("Lecture Salaire",e,4);
}//try
}//while
//Calcul du nombre de parts
double NbParts;
if(Marie){
NbParts=(double)NbEnfants/2+2;
}
else{
NbParts=(double)NbEnfants/2+1;
}
if(NbEnfants>=3){
NbParts+=0.5;
}
//Revenu imposable
double Revenu;
Revenu=0.72*Salaire;
//Quotient familliale
double QF;
QF=Revenu/NbParts;
//Recherche de la tranche d'impots correspondant à QF
int i;
int NbTranches=Limites.length;
Limites[NbTranches-1]=QF;
i=0;
while(QF>Limites[i]) {
i++;
}
//L'impot
long impots=(long)(i*0.05*Revenu-coeffn[i]*NbParts);
//On affiche le resultat
System.out.println("Impots à payer : " + impots);
}//main
//Erreur
private static void erreur(String msg, Exception e, int exitCode){
System.err.println(msg+"("+e+")");
System.exit(exitCode);
}//erreur
}//class |
Partager