import java.io.*;

class complexe
{

  float re;
  float im;

  complexe ()
  {
    re = 0;
    im = 0;
  }  

  void somme (complexe z)
  {
    re += z.re;
    im += z.im;
  }

  void multiplication (complexe z)
  {
    float pre;
    
    pre = re;
    
    re = re * z.re - im * z.im;
    im = pre * z.im + im * z.re;
  }
  
  void saisie (String nom) throws IOException
  {
    DataInputStream lecture;
    Float f;
    
    lecture = new DataInputStream (System.in);
    
    System.out.println ("Entrer la partie reelle de " + nom);
    f = new Float (lecture.readLine());
    re = f.floatValue();
      
    System.out.println ("Entrer la partie imaginaire de " + nom);
    f = new Float (lecture.readLine());
    im = f.floatValue();
  }
  
  void affichage ()
  {
    System.out.println (re + " + i" + im);
  }      

  public static void main (String[] arguments)
  {
    try
    {
      complexe z,t,s,m;
      
      z = new complexe ();
      t = new complexe ();
      
      z.saisie ("z");
      t.saisie ("t");
      
      System.out.println ();
    
      System.out.println ("z vaut:");
      z.affichage();
      
      System.out.println ("On ajoute t a l'instance z. z vaut:");
      z.somme(t);
      z.affichage();
    
      System.out.println ("On multiplie l'instance z par t. z vaut:");
      z.multiplication(t);
      z.affichage();
    }
    
    catch (IOException e) {}
  }
}
    

Retour