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
| class Sdz1 {
public static void main(String[] args) {
//Notre objet Scanner
Scanner sc = new Scanner(System.in);
//initialisation des variables
double c, f=0;
int i,j=0;
char reponse=' ';
System.out.println(" ------------------------------------------------------------------------");
System.out.println("| CONVERSION DEGRES CELSIUS ET DEGRES FARENHEIT |");
System.out.println(" ------------------------------------------------------------------------");
do{//tant que reponse = O//boucle principale
do{//tant que l'imprimante n'est pas prête//boucle de test pour savoir si l'utilisateur est prêt
do {// tant que valeur impossible rentrée
//saisie des valeurs
System.out.println("A partir de :");//affichage des directives et récupération des données
c = sc.nextDouble();
System.out.println("jusqu' à:");
i = sc.nextInt();
System.out.println("Par pas de :");
j = sc.nextInt();
if (c > i || j > i || j == 0)
System.out.println("Traitement impossible");
}while(c > i || j > i || j == 0);
do {//tant que la reponse n'est pas O ou N
System.out.println("Assurez-vous que l'imprimante est prête");
System.out.println("Si vous êtes prêt, tapez O, sinon tapez N");
//sc.reset();
reponse = sc.next().charAt(0);
}while (reponse != 'O' && reponse != 'N');
}while (reponse == 'N');
// Traitement des valeurs
System.out.println("TABLE DE CONVERSION CELSIUS / FARENHEIT");
System.out.println("---------------------------------------------");
System.out.println(" Celsius | Farenheit ");
System.out.println("---------------------------------------------");
do{//tant que l'affichage n'est pas fini, on boucle les données et les calculs
f = ((9.0/5.0) * c) + 32.0;
if (c < 10)//si le Celsius n'a qu'un chiffre, on affiche un certain nombre d'espaces
System.out.println(" "+c+" | "+arrondi(f,1));
else
{
if(c < 100)//S'il y a un chiffre en plus, on enlève un espace blanc...
System.out.println(" "+c+" | "+arrondi(f,1));
else
System.out.println(" "+c+" | "+arrondi(f,1));
}
c = c + j;//On incrémente le degré Celsius avec le pas
}while (c <= i);
do{
System.out.println("Souhaitez-vous éditer une autre table ?(O/N)");
reponse = sc.next().charAt(0);
}while(reponse != 'O' && reponse != 'N');
}while(reponse == 'O');
System.out.println("Au revoir !");
//Fin de programme
}
public static double arrondi(double A, int B) {
return (double) ( (int) (A * Math.pow(10, B) + .5)) / Math.pow(10, B);
}
} |