APL2.1 - Controle Machine & DEV 2.3
This commit is contained in:
parent
79791b395c
commit
e7f9cf7b1f
@ -0,0 +1,12 @@
|
||||
//HORVILLE Ewen Groupe N°4
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Aléatoire {
|
||||
public static void main(String[] args) {
|
||||
Random r = new Random();
|
||||
|
||||
System.out.println("random propose :\t" + Math.random());
|
||||
System.out.println("nextDouble propose :\t" + r.nextDouble());
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
//HORVILLE Ewen Groupe N°4
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Fermeture {
|
||||
public static void main(String[] args) {
|
||||
JFrame f = new JFrame("Fermeture");
|
||||
f.setLocation(150, 150);
|
||||
f.setSize(500, 500);
|
||||
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
f.addWindowListener(new FermetureListener());
|
||||
f.setVisible(true);
|
||||
|
||||
TileBackground tb = new TileBackground(100, "./tuile.jpg");
|
||||
f.add(tb);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
//HORVILLE Ewen Groupe N°4
|
||||
|
||||
import java.awt.event.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class FermetureListener implements WindowListener {
|
||||
|
||||
private boolean hasBeenMinimised = false;
|
||||
|
||||
public FermetureListener() {}
|
||||
public void windowActivated(WindowEvent evenement) {}
|
||||
public void windowClosed(WindowEvent evenement) {}
|
||||
public void windowDeactivated(WindowEvent evenement) {}
|
||||
public void windowDeiconified(WindowEvent evenement) {}
|
||||
public void windowOpened(WindowEvent evenement) {}
|
||||
|
||||
public void windowClosing(WindowEvent evenement) {
|
||||
if (hasBeenMinimised) {
|
||||
((JFrame)evenement.getSource()).dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void windowIconified(WindowEvent evenement) {
|
||||
hasBeenMinimised = true;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class TileBackground extends JComponent {
|
||||
private Image tile;
|
||||
private int tileScale;
|
||||
|
||||
public TileBackground(int tileScale, String imagePath) {
|
||||
super();
|
||||
this.tile = Toolkit.getDefaultToolkit().getImage(imagePath);
|
||||
this.tileScale = tileScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics brush) {
|
||||
Graphics newBrush = brush.create();
|
||||
|
||||
if (this.isOpaque()) {
|
||||
newBrush.setColor(this.getBackground());
|
||||
newBrush.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
int horizontalReps = this.getWidth() / this.tileScale + 1;
|
||||
int verticalReps = this.getHeight() / this.tileScale + 1;
|
||||
|
||||
for (int x = 0; x < horizontalReps; x++) {
|
||||
for (int y = 0; y < verticalReps; y++) {
|
||||
newBrush.drawImage(this.tile, x * tileScale, y * tileScale, tileScale, tileScale, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
APL2.1/Controle Machine/horville_apl21/Fermeture/tuile.jpg
Normal file
BIN
APL2.1/Controle Machine/horville_apl21/Fermeture/tuile.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
File diff suppressed because it is too large
Load Diff
52
APL2.1/Controle Machine/horville_apl21/Puissance/Grille.java
Normal file
52
APL2.1/Controle Machine/horville_apl21/Puissance/Grille.java
Normal file
@ -0,0 +1,52 @@
|
||||
//HORVILLE Ewen Groupe N°4
|
||||
|
||||
public class Grille {
|
||||
private short[][] Cases = new short[7][6];
|
||||
private int joueurActuel;
|
||||
|
||||
public Grille() {
|
||||
joueurActuel = 0;
|
||||
}
|
||||
|
||||
public void jouer(int colonne) {
|
||||
if (colonne < 1 && colonne > 7) {
|
||||
System.out.println("N° de colonne invalide !");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean placementValide = false;
|
||||
for (int i = 5; i >= 0; i--) {
|
||||
if (Cases[colonne-1][i] == 0) {
|
||||
Cases[colonne-1][i] = (short)(joueurActuel+1);
|
||||
joueurActuel = (joueurActuel + 1) % 2;
|
||||
placementValide = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!placementValide) {
|
||||
System.out.println("Colonne n°" + colonne + " pleine !");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String str = "";
|
||||
|
||||
for (int x = 0; x < 6; x++) {
|
||||
for (int y = 0; y < 7; y++) {
|
||||
str += "│";
|
||||
|
||||
if (Cases[y][x] == 0) str += " ";
|
||||
else if (Cases[y][x] == 1) str += "○";
|
||||
else if (Cases[y][x] == 2) str += "●";
|
||||
}
|
||||
|
||||
str += "│\n";
|
||||
}
|
||||
|
||||
str += "┴─┴─┴─┴─┴─┴─┴─┴";
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
//HORVILLE Ewen Groupe N°4
|
||||
|
||||
public class Puissance {
|
||||
public static void main(String[] args) {
|
||||
Grille g = new Grille();
|
||||
|
||||
g.jouer(3);
|
||||
g.jouer(4);
|
||||
g.jouer(4);
|
||||
g.jouer(6);
|
||||
g.jouer(4);
|
||||
g.jouer(6);
|
||||
System.out.println(g);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
//HORVILLE Ewen Groupe N°4
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class TileBackground extends JComponent {
|
||||
private Image tile;
|
||||
private int tileScale;
|
||||
|
||||
public TileBackground(int tileScale, String imagePath) {
|
||||
super();
|
||||
this.tile = Toolkit.getDefaultToolkit().getImage(imagePath);
|
||||
this.tileScale = tileScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics brush) {
|
||||
Graphics newBrush = brush.create();
|
||||
|
||||
if (this.isOpaque()) {
|
||||
newBrush.setColor(this.getBackground());
|
||||
newBrush.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
int horizontalReps = this.getWidth() / this.tileScale + 1;
|
||||
int verticalReps = this.getHeight() / this.tileScale + 1;
|
||||
|
||||
for (int x = 0; x < horizontalReps; x++) {
|
||||
for (int y = 0; y < verticalReps; y++) {
|
||||
newBrush.drawImage(this.tile, x * tileScale, y * tileScale, tileScale, tileScale, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
APL2.1/Controle Machine/horville_apl21/Tuile/Tuile.java
Normal file
17
APL2.1/Controle Machine/horville_apl21/Tuile/Tuile.java
Normal file
@ -0,0 +1,17 @@
|
||||
//HORVILLE Ewen Groupe N°4
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Tuile {
|
||||
public static void main(String[] args) {
|
||||
JFrame f = new JFrame("Tuile");
|
||||
f.setLocation(150, 150);
|
||||
f.setSize(500, 500);
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f.setVisible(true);
|
||||
|
||||
TileBackground tb = new TileBackground(100, "./tuile.jpg");
|
||||
f.add(tb);
|
||||
}
|
||||
}
|
BIN
APL2.1/Controle Machine/horville_apl21/Tuile/tuile.jpg
Normal file
BIN
APL2.1/Controle Machine/horville_apl21/Tuile/tuile.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
BIN
DEV 2.3/Largest/Largest.class
Normal file
BIN
DEV 2.3/Largest/Largest.class
Normal file
Binary file not shown.
19
DEV 2.3/Largest/Largest.java
Normal file
19
DEV 2.3/Largest/Largest.java
Normal file
@ -0,0 +1,19 @@
|
||||
import java.util.Objects;
|
||||
|
||||
public class Largest {
|
||||
|
||||
/**
|
||||
* Return the largest element in a list.
|
||||
*
|
||||
* @param list A list of integers
|
||||
* @return The largest number in the given list
|
||||
*/
|
||||
public static int largest(int[] list) {
|
||||
Objects.requireNonNull(list);
|
||||
int index, max=Integer.MIN_VALUE;
|
||||
for (index = 0; index < list.length; index++) {
|
||||
max = list[index] > max ? list[index] : max;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
BIN
DEV 2.3/Largest/TestLargest.class
Normal file
BIN
DEV 2.3/Largest/TestLargest.class
Normal file
Binary file not shown.
36
DEV 2.3/Largest/TestLargest.java
Normal file
36
DEV 2.3/Largest/TestLargest.java
Normal file
@ -0,0 +1,36 @@
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestLargest {
|
||||
|
||||
@Test
|
||||
public void testSimple() {
|
||||
assertEquals(9, Largest.largest(new int[] {9,8,7}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoundary() {
|
||||
assertEquals(Integer.MAX_VALUE, Largest.largest(new int[] {1, 28825, Integer.MAX_VALUE}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInverse() {
|
||||
assert(3 != Largest.largest(new int[] {1, 3, 7}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrosscheck() {
|
||||
int[] a = new int[] {3, 1, 7};
|
||||
Arrays.sort(a);
|
||||
assert(Largest.largest(new int[] {3, 1, 7}) == a[a.length-1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testError() {
|
||||
Largest.largest(new int[] {});
|
||||
Largest.largest(null);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user