clevernessisamyth

Examen JAVA 2014

Aug 21st, 2020 (edited)
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1. // QCM: a, c, a, ab, a, b, a, a, a, b', a, c, a, a'
  2.  
  3. // ex2
  4.  
  5. public class Complex {
  6.  
  7.  // Variables d'instance
  8.  private double real, imag;
  9.  // Constructeur
  10.  public Complex (double r, double i) {
  11.      this.real = r;
  12.      this.imag = i;
  13.  }
  14.  // Partie réelle
  15.  public double getRealPart() {
  16.      return real;
  17.  }
  18.  // Partie imaginaire
  19.  public double getImagPart(){
  20.      return imag;
  21.  }
  22.  // Additionner deux complexes
  23.  public Complex add (Complex c) {
  24.      return new Complex(this.real + c.getRealPart(), this.imag + c.getImagPart());
  25.  }
  26.  // Soustraire deux complexes
  27.  public Complex subtract (Complex c) {
  28.      return new Complex(this.real - c.getRealPart(), this.imag - c.getImagPart());
  29.  }
  30.  // Calculer le conjugué
  31.  public Complex conjugate() {
  32.      return new Complex(this.real, -this.imag);
  33.  }
  34.  
  35.     public static void main(String args[]) {
  36.         Complex a = new Complex(2.5, 1);
  37.         Complex b = new Complex(1, 1.5);
  38.        
  39.         Complex c = a.add(b);
  40.         double r = c.getRealPart();
  41.         double i = c.getImagPart();
  42.        
  43.         System.out.println(r+" + "+i+"i");
  44.        
  45.         Complex d = c.conjugate().subtract(b);
  46.         System.out.println(d.getRealPart()+" + "+d.getImagPart()+"i");
  47.     }
  48. }
  49.  
  50. // ex3
  51.  
  52. public class Pawn extends ChessPiece {
  53.  
  54.     public Pawn(int color, int row, int col) {
  55.         super(color, row, col);
  56.     }
  57.    
  58.     @Override
  59.     public int[][] getMoves() {
  60.         int[][] T = new int[1][2];
  61.         T[0][1] = col; // wont change as long as we ignore other pieces
  62.        
  63.         if(super.color == BLACK && row < 7)
  64.             T[0][0] = row + 1;
  65.        
  66.         else if(super.color == WHITE && row > 0)
  67.             T[0][0] = row - 1;
  68.         else
  69.             T[0][0] = row;
  70.        
  71.         return T;
  72.     }
  73.    
  74.     public static void main(String args[]) {
  75.         Pawn pion = new Pawn(BLACK, 4, 2);
  76.                 int[][] moves = pion.getMoves();
  77.         System.out.print(moves [0][0] + " " + moves[0][1]);
  78.     }
  79. }
  80.  
  81. // ex4
  82.  
  83. import java.util.Scanner;
  84.  
  85. public class Voyelles{
  86.     public static void main (String args[]){
  87.         Scanner sc = new Scanner(System.in);
  88.         String str = sc.nextLine();
  89.         char[] T = {'a', 'e', 'i', 'o', 'u', 'y'};
  90.         int[] cpt = new int[6];
  91.         for ( int i=0 ; i<str.length() ; i++ )
  92.         {
  93.             for( int j=0 ; j<T.length ; j++)
  94.                 if(str.toLowerCase().charAt(i) == T[j])
  95.                     cpt[j]++;
  96.         }
  97.        
  98.         for(int i=0; i<T.length ; i++)
  99.             System.out.println(cpt[i] + " fois la lettre " + T[i]);
  100.        
  101.     }
  102. }
  103.  
  104. // ex5
  105.  
  106.     JFrame -> Frame -> Window -> Container -> Component -> Object
Add Comment
Please, Sign In to add comment