d'abord s'est mon 2ème programme lol alors soyez pas trop mechant avec me
ben ce petit programme resoud l'équation ax² + bx + c, il verifie que les valeurs données pour a, b, c sont bien des chiffres et vous donne le delta et la reponse ou les réponses final ....
@+
CHKDSK2K
Source / Exemple :
import java.awt.*;
import java.lang.Double;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;
public class projetMathUn
{
static byte OUI = 1;static byte NON = 0;
static byte Affiche_Panel_Executer = 0;
static String String_RacineCarré = "";
static String String_ReponseFinal1 = ""; static String String_ReponseFinal2 = "";
static String String_Nbre_A = ""; static String String_Nbre_B = ""; static String String_Nbre_C = "";
static double Nbre_A = 0; static double Nbre_B = 0; static double Nbre_C = 0;
static double Nbre_BauC; static double Delta = 0;
static double Reponse1 = 0; static double Reponse2 = 0;
static double ReponseFinal = 0;
static double RacineCarréDuDelta = 0;
static byte pourContinuer_Nbre_A = 0;static byte pourContinuer_Nbre_B = 0;static byte pourContinuer_Nbre_C = 0;
public static void main (String [] args)
{
final JLabel Label_Delta = new JLabel("");
final JPanel Panel_Output = new JPanel(null);
final JOptionPane MessageTest = new JOptionPane();
final JOptionPane PasNbre = new JOptionPane();
final JLabel Label_RacineCarré = new JLabel("");
final JLabel Label_Reponse = new JLabel("");
final JLabel Label_Reponse1 = new JLabel("");
final JLabel Label_DetailReponse = new JLabel("");
final JLabel Label_Formule = new JLabel("");
final JLabel Label_ReponseDet = new JLabel("");
// Label Formule de base
JLabel Label_ForBase = new JLabel("Formule de base : ax² + bx + c !");
Label_ForBase.setBounds(10,20,200,25);
// Label Votre Formule + Forumle
final JLabel Label_VotreFor = new JLabel("" );
// Button Input(entrez valeur)
JButton Button_Input = new JButton("Entrer Information");
Button_Input.setBounds(75,75,150,25);
Button_Input.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Affiche_Panel_Executer = NON;
while (Affiche_Panel_Executer == NON)
{
pourContinuer_Nbre_A = NON;
while (pourContinuer_Nbre_A == NON)
{
String_Nbre_A = JOptionPane.showInputDialog(null,"Que vaut A dans ax² + bx + c ? ","Entrez les informations",JOptionPane.INFORMATION_MESSAGE);
try {
Nbre_A = Double.valueOf(String_Nbre_A).doubleValue();pourContinuer_Nbre_A = OUI;
}
catch (NumberFormatException ex)
{
PasNbre.showMessageDialog(null,"Ce n'est pas un nombre : " + String_Nbre_A,"Problème avec A dans ax²+bx+c",JOptionPane.ERROR_MESSAGE);
pourContinuer_Nbre_A = NON;
}
}
pourContinuer_Nbre_B = NON;
while (pourContinuer_Nbre_B == NON)
{
String_Nbre_B = JOptionPane.showInputDialog(null,"Que vaut B dans ax² + bx + c ? ","Entrez les informations",JOptionPane.INFORMATION_MESSAGE);
try {
Nbre_B = Double.valueOf(String_Nbre_B).doubleValue();pourContinuer_Nbre_B = OUI;
}
catch (NumberFormatException ex)
{
PasNbre.showMessageDialog(null,"Ce n'est pas un nombre : " + String_Nbre_B,"Problème avec B dans ax²+bx+c",JOptionPane.ERROR_MESSAGE);
pourContinuer_Nbre_B = NON;
}
}
pourContinuer_Nbre_C = NON;
while (pourContinuer_Nbre_C == NON)
{
String_Nbre_C = JOptionPane.showInputDialog(null,"Que vaut C dans ax² + bx + c ? ","Entrez les informations",JOptionPane.INFORMATION_MESSAGE);
try {
Nbre_C = Double.valueOf(String_Nbre_C).doubleValue();pourContinuer_Nbre_C = OUI;
}
catch (NumberFormatException ex)
{
PasNbre.showMessageDialog(null,"Ce n'est pas un nombre : " + String_Nbre_C,"Problème avec C dans ax²+bx+c",JOptionPane.ERROR_MESSAGE);
pourContinuer_Nbre_C = NON;
}
}
Affiche_Panel_Executer = OUI;
}
Label_VotreFor.setText("Votre Formule : " + String_Nbre_A + "x² + " + String_Nbre_B + "x + " + String_Nbre_C + " !");
Label_VotreFor.setBounds(10,45,299,25);
Nbre_BauC = 0;Nbre_BauC = Math.pow(Nbre_B,2);
Delta = 0; Delta = Nbre_BauC - (4 * Nbre_A * Nbre_C);
if (Delta == 0)
{
ReponseFinal = 0; Reponse1 = - Nbre_B; Reponse2 = 2 * Nbre_A;
ReponseFinal = Reponse1 / Reponse2;
Label_Reponse.setText(""); Label_RacineCarré.setText("");
Label_Delta.setText("");Label_Formule.setText("");
Label_ReponseDet.setText("");Label_Reponse1.setText("");
String_ReponseFinal1 = Double.toString(ReponseFinal);
Label_Delta.setText("Delta : " + Delta + " ");Label_Delta.setBounds(5,5,299,50);
Label_Formule.setText("Donc x' = x'' = -b / 2a");Label_Formule.setBounds(5,20,299,50);
Label_ReponseDet.setText("Ici -b = " + - Nbre_B + " et 2a = " + 2 * Nbre_A);Label_ReponseDet.setBounds(5,35,299,50);
Label_Reponse.setText("Votre reponse est : " + String_ReponseFinal1);Label_Reponse.setBounds(5,50,299,50);
}
else
{
if (Delta > 0)
{
Label_Reponse.setText("");Label_Delta.setText("");
Label_Formule.setText("");Label_RacineCarré.setText("");
Label_ReponseDet.setText("");Label_Reponse1.setText("");
DecimalFormat Nbre_de_Decimal = new DecimalFormat(); // nombre de décimal
ReponseFinal = 0; RacineCarréDuDelta = 0;
RacineCarréDuDelta = Math.sqrt(Delta);
Reponse1 = (- Nbre_B - RacineCarréDuDelta)/(2 * Nbre_A);
Reponse2 = (- Nbre_B + RacineCarréDuDelta)/(2 * Nbre_A);
Nbre_de_Decimal.setMaximumFractionDigits(3);
String_ReponseFinal1 = Nbre_de_Decimal.format(Reponse1);
String_ReponseFinal2 = Nbre_de_Decimal.format(Reponse2);
String_RacineCarré = Nbre_de_Decimal.format(RacineCarréDuDelta);
Label_Delta.setText("Delta : " + Delta + " ");Label_Delta.setBounds(5,5,299,50);
Label_Formule.setText("La racine carré du delta est "+String_RacineCarré);Label_Formule.setBounds(5,20,299,50);
Label_Reponse.setText("Donc x' = ( -b - V(Delta) / 2a ) = " + String_ReponseFinal1);Label_Reponse.setBounds(5,35,299,50);
Label_Reponse1.setText("Donc x'' = ( -b + V(Delta) / 2a ) = " + String_ReponseFinal2);Label_Reponse1.setBounds(5,50,299,50);
}
else
{
Label_Reponse.setText("");Label_RacineCarré.setText("");
Label_Delta.setText("");Label_Formule.setText("");
Label_ReponseDet.setText("");Label_Reponse1.setText("");
Label_Delta.setText("Delta : " + Delta + " ");Label_Delta.setBounds(5,5,299,50);
Label_Formule.setText("Donc il n'y a pas reponse dans R");Label_Formule.setBounds(5,20,299,50);
Label_ReponseDet.setText("");Label_ReponseDet.setBounds(5,35,299,50);
Label_Reponse.setText("");Label_Reponse.setBounds(5,50,299,50);
}
}
}
});
//Le Panel Input
JPanel Panel_Input = new JPanel(null);
Panel_Input.add(Label_ForBase);
Panel_Input.add(Button_Input);
Panel_Input.add(Label_VotreFor);
Panel_Input.setBorder(BorderFactory.createTitledBorder("Information pour le calcul s.v.p. ? "));
//Le Panel_Output
Panel_Output.add(Label_Reponse);
Panel_Output.add(Label_Delta);
Panel_Output.add(Label_Formule);
Panel_Output.add(Label_ReponseDet);
Panel_Output.add(Label_Reponse1);
Panel_Output.setBorder(BorderFactory.createTitledBorder("Information Reponse . . ."));
//Le Panel Principale
JPanel Panel_Principale = new JPanel(new GridLayout(2,1,5,5));
Panel_Principale.add(Panel_Input);
Panel_Principale.add(Panel_Output);
//La Fenetre Principale
JFrame Frame_Principale = new JFrame ("ax² + bx + c VS 1.1");
Frame_Principale.setBounds(10,10,300,250);// Taille
Frame_Principale.getContentPane().add(Panel_Principale);// ajoute de Panel Principale
Frame_Principale.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// Fremer la Fenetre avec X
Frame_Principale.setResizable(false);//Pas Redimensionable
Frame_Principale.setVisible(true);//Afficher la fenetre
}
}
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.