Ajout
This commit is contained in:
BIN
BUT1/MiniProjet/Calculatrice/Calculatrice.class
Normal file
BIN
BUT1/MiniProjet/Calculatrice/Calculatrice.class
Normal file
Binary file not shown.
38
BUT1/MiniProjet/Calculatrice/Calculatrice.java
Normal file
38
BUT1/MiniProjet/Calculatrice/Calculatrice.java
Normal file
@@ -0,0 +1,38 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Calculatrice{
|
||||
|
||||
|
||||
public static void main(String args[]){
|
||||
|
||||
// Création d'une fenêtre nommée "Calculatrice"
|
||||
JFrame fenetre = new JFrame("Calculatrice");
|
||||
// Configuration de la fenêtre
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetre.setSize(400, 700);
|
||||
fenetre.setLocation(100,100);
|
||||
|
||||
// Initialisation des tableaux
|
||||
JButton[] boutonsChiffre = new JButton[10];
|
||||
JButton[] boutonsOperations = new JButton[4];
|
||||
String[] logoOperations = {"+","-","/","*"};
|
||||
|
||||
GridLayout gestionnaire = new GridLayout(3, 5);
|
||||
fenetre.setLayout(gestionnaire);
|
||||
|
||||
// Ajout des chiffres
|
||||
for(int i=0; i<=9; i++){
|
||||
boutonsChiffre[i] = new JButton(""+i);
|
||||
fenetre.add(boutonsChiffre[i]);
|
||||
}
|
||||
|
||||
// Ajout des opérations
|
||||
for(int i=0; i<4; i++){
|
||||
boutonsOperations[i] = new JButton(logoOperations[i]);
|
||||
fenetre.add(boutonsOperations[i]);
|
||||
}
|
||||
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
29
BUT1/MiniProjet/Calculatrice/Operation.java
Normal file
29
BUT1/MiniProjet/Calculatrice/Operation.java
Normal file
@@ -0,0 +1,29 @@
|
||||
public class Operation{
|
||||
// attributs
|
||||
|
||||
// constructeur
|
||||
|
||||
|
||||
// méthodes
|
||||
|
||||
public double addition(double a, double b){
|
||||
return a+b;
|
||||
}
|
||||
|
||||
public double soustraction(double a, double b){
|
||||
return a-b;
|
||||
}
|
||||
|
||||
public double multiplication(double a, double b){
|
||||
return a*b;
|
||||
}
|
||||
|
||||
public double division(double a, double b){
|
||||
if(b != 0){
|
||||
return a/b;
|
||||
}else{
|
||||
System.out.println("Erreur : la division par 0 est impossible");
|
||||
return Double.NaN;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user