diff --git a/APL2.1/Controle Machine/horville_apl21/Aléatoire/Aléatoire.java b/APL2.1/Controle Machine/horville_apl21/Aléatoire/Aléatoire.java new file mode 100644 index 0000000..13eed29 --- /dev/null +++ b/APL2.1/Controle Machine/horville_apl21/Aléatoire/Aléatoire.java @@ -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()); + } +} \ No newline at end of file diff --git a/APL2.1/Controle Machine/horville_apl21/Fermeture/Fermeture.java b/APL2.1/Controle Machine/horville_apl21/Fermeture/Fermeture.java new file mode 100644 index 0000000..9bda8fd --- /dev/null +++ b/APL2.1/Controle Machine/horville_apl21/Fermeture/Fermeture.java @@ -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); + } +} \ No newline at end of file diff --git a/APL2.1/Controle Machine/horville_apl21/Fermeture/FermetureListener.java b/APL2.1/Controle Machine/horville_apl21/Fermeture/FermetureListener.java new file mode 100644 index 0000000..a58b6e0 --- /dev/null +++ b/APL2.1/Controle Machine/horville_apl21/Fermeture/FermetureListener.java @@ -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; + } +} \ No newline at end of file diff --git a/APL2.1/Controle Machine/horville_apl21/Fermeture/TileBackground.java b/APL2.1/Controle Machine/horville_apl21/Fermeture/TileBackground.java new file mode 100644 index 0000000..b3c149f --- /dev/null +++ b/APL2.1/Controle Machine/horville_apl21/Fermeture/TileBackground.java @@ -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); + } + } + } +} \ No newline at end of file diff --git a/APL2.1/Controle Machine/horville_apl21/Fermeture/tuile.jpg b/APL2.1/Controle Machine/horville_apl21/Fermeture/tuile.jpg new file mode 100644 index 0000000..55612e6 Binary files /dev/null and b/APL2.1/Controle Machine/horville_apl21/Fermeture/tuile.jpg differ diff --git a/APL2.1/Controle Machine/horville_apl21/Modélisation/Modélisation.mdj b/APL2.1/Controle Machine/horville_apl21/Modélisation/Modélisation.mdj new file mode 100644 index 0000000..4ce6886 --- /dev/null +++ b/APL2.1/Controle Machine/horville_apl21/Modélisation/Modélisation.mdj @@ -0,0 +1,557 @@ +{ + "_type": "Project", + "_id": "AAAAAAFF+h6SjaM2Hec=", + "name": "Untitled", + "ownedElements": [ + { + "_type": "UMLModel", + "_id": "AAAAAAFF+qBWK6M3Z8Y=", + "_parent": { + "$ref": "AAAAAAFF+h6SjaM2Hec=" + }, + "name": "Model", + "ownedElements": [ + { + "_type": "UMLClassDiagram", + "_id": "AAAAAAFF+qBtyKM79qY=", + "_parent": { + "$ref": "AAAAAAFF+qBWK6M3Z8Y=" + }, + "name": "Main", + "defaultDiagram": true, + "ownedViews": [ + { + "_type": "UMLClassView", + "_id": "AAAAAAGAQbmqUae/eU4=", + "_parent": { + "$ref": "AAAAAAFF+qBtyKM79qY=" + }, + "model": { + "$ref": "AAAAAAGAQbmqT6e9eOw=" + }, + "subViews": [ + { + "_type": "UMLNameCompartmentView", + "_id": "AAAAAAGAQbmqUafAlBY=", + "_parent": { + "$ref": "AAAAAAGAQbmqUae/eU4=" + }, + "model": { + "$ref": "AAAAAAGAQbmqT6e9eOw=" + }, + "subViews": [ + { + "_type": "LabelView", + "_id": "AAAAAAGAQbmqUafB+ek=", + "_parent": { + "$ref": "AAAAAAGAQbmqUafAlBY=" + }, + "visible": false, + "font": "Arial;13;0", + "left": 224, + "top": 304, + "height": 13 + }, + { + "_type": "LabelView", + "_id": "AAAAAAGAQbmqUafC9dg=", + "_parent": { + "$ref": "AAAAAAGAQbmqUafAlBY=" + }, + "font": "Arial;13;1", + "left": 549, + "top": 327, + "width": 135.4970703125, + "height": 13, + "text": "Grille" + }, + { + "_type": "LabelView", + "_id": "AAAAAAGAQbmqUqfDnuk=", + "_parent": { + "$ref": "AAAAAAGAQbmqUafAlBY=" + }, + "visible": false, + "font": "Arial;13;0", + "left": 224, + "top": 304, + "width": 73.67724609375, + "height": 13, + "text": "(from Model)" + }, + { + "_type": "LabelView", + "_id": "AAAAAAGAQbmqUqfEy+o=", + "_parent": { + "$ref": "AAAAAAGAQbmqUafAlBY=" + }, + "visible": false, + "font": "Arial;13;0", + "left": 224, + "top": 304, + "height": 13, + "horizontalAlignment": 1 + } + ], + "font": "Arial;13;0", + "left": 544, + "top": 320, + "width": 145.4970703125, + "height": 25, + "stereotypeLabel": { + "$ref": "AAAAAAGAQbmqUafB+ek=" + }, + "nameLabel": { + "$ref": "AAAAAAGAQbmqUafC9dg=" + }, + "namespaceLabel": { + "$ref": "AAAAAAGAQbmqUqfDnuk=" + }, + "propertyLabel": { + "$ref": "AAAAAAGAQbmqUqfEy+o=" + } + }, + { + "_type": "UMLAttributeCompartmentView", + "_id": "AAAAAAGAQbmqUqfFNho=", + "_parent": { + "$ref": "AAAAAAGAQbmqUae/eU4=" + }, + "model": { + "$ref": "AAAAAAGAQbmqT6e9eOw=" + }, + "subViews": [ + { + "_type": "UMLAttributeView", + "_id": "AAAAAAGAQboV46frWRg=", + "_parent": { + "$ref": "AAAAAAGAQbmqUqfFNho=" + }, + "model": { + "$ref": "AAAAAAGAQboV2KfoKgU=" + }, + "font": "Arial;13;0", + "left": 549, + "top": 350, + "width": 135.4970703125, + "height": 13, + "text": "-short[][] Cases", + "horizontalAlignment": 0 + }, + { + "_type": "UMLAttributeView", + "_id": "AAAAAAGAQbqsc6fzE9Q=", + "_parent": { + "$ref": "AAAAAAGAQbmqUqfFNho=" + }, + "model": { + "$ref": "AAAAAAGAQbqsbqfw1J0=" + }, + "font": "Arial;13;0", + "left": 549, + "top": 365, + "width": 135.4970703125, + "height": 13, + "text": "-int joueurActuel", + "horizontalAlignment": 0 + } + ], + "font": "Arial;13;0", + "left": 544, + "top": 345, + "width": 145.4970703125, + "height": 38 + }, + { + "_type": "UMLOperationCompartmentView", + "_id": "AAAAAAGAQbmqUqfGs3M=", + "_parent": { + "$ref": "AAAAAAGAQbmqUae/eU4=" + }, + "model": { + "$ref": "AAAAAAGAQbmqT6e9eOw=" + }, + "subViews": [ + { + "_type": "UMLOperationView", + "_id": "AAAAAAGAQbr0NKf7Rkg=", + "_parent": { + "$ref": "AAAAAAGAQbmqUqfGs3M=" + }, + "model": { + "$ref": "AAAAAAGAQbr0L6f4b9I=" + }, + "font": "Arial;13;0", + "left": 549, + "top": 388, + "width": 135.4970703125, + "height": 13, + "text": "+void jouer(int colonne)", + "horizontalAlignment": 0 + }, + { + "_type": "UMLOperationView", + "_id": "AAAAAAGAQbt7tqgCEMk=", + "_parent": { + "$ref": "AAAAAAGAQbmqUqfGs3M=" + }, + "model": { + "$ref": "AAAAAAGAQbt7saf/ho0=" + }, + "font": "Arial;13;0", + "left": 549, + "top": 403, + "width": 135.4970703125, + "height": 13, + "text": "+String toString()", + "horizontalAlignment": 0 + } + ], + "font": "Arial;13;0", + "left": 544, + "top": 383, + "width": 145.4970703125, + "height": 38 + }, + { + "_type": "UMLReceptionCompartmentView", + "_id": "AAAAAAGAQbmqUqfH22s=", + "_parent": { + "$ref": "AAAAAAGAQbmqUae/eU4=" + }, + "model": { + "$ref": "AAAAAAGAQbmqT6e9eOw=" + }, + "visible": false, + "font": "Arial;13;0", + "left": 112, + "top": 152, + "width": 10, + "height": 10 + }, + { + "_type": "UMLTemplateParameterCompartmentView", + "_id": "AAAAAAGAQbmqUqfInbI=", + "_parent": { + "$ref": "AAAAAAGAQbmqUae/eU4=" + }, + "model": { + "$ref": "AAAAAAGAQbmqT6e9eOw=" + }, + "visible": false, + "font": "Arial;13;0", + "left": 112, + "top": 152, + "width": 10, + "height": 10 + } + ], + "font": "Arial;13;0", + "containerChangeable": true, + "left": 544, + "top": 320, + "width": 145.4970703125, + "height": 101, + "nameCompartment": { + "$ref": "AAAAAAGAQbmqUafAlBY=" + }, + "attributeCompartment": { + "$ref": "AAAAAAGAQbmqUqfFNho=" + }, + "operationCompartment": { + "$ref": "AAAAAAGAQbmqUqfGs3M=" + }, + "receptionCompartment": { + "$ref": "AAAAAAGAQbmqUqfH22s=" + }, + "templateParameterCompartment": { + "$ref": "AAAAAAGAQbmqUqfInbI=" + } + }, + { + "_type": "UMLClassView", + "_id": "AAAAAAGAQb2Y1qgNzok=", + "_parent": { + "$ref": "AAAAAAFF+qBtyKM79qY=" + }, + "model": { + "$ref": "AAAAAAGAQb2Y1agLYCI=" + }, + "subViews": [ + { + "_type": "UMLNameCompartmentView", + "_id": "AAAAAAGAQb2Y1qgOWEU=", + "_parent": { + "$ref": "AAAAAAGAQb2Y1qgNzok=" + }, + "model": { + "$ref": "AAAAAAGAQb2Y1agLYCI=" + }, + "subViews": [ + { + "_type": "LabelView", + "_id": "AAAAAAGAQb2Y1qgPBUM=", + "_parent": { + "$ref": "AAAAAAGAQb2Y1qgOWEU=" + }, + "visible": false, + "font": "Arial;13;0", + "left": 848, + "top": 448, + "height": 13 + }, + { + "_type": "LabelView", + "_id": "AAAAAAGAQb2Y1qgQmHI=", + "_parent": { + "$ref": "AAAAAAGAQb2Y1qgOWEU=" + }, + "font": "Arial;13;1", + "left": 733, + "top": 343, + "width": 141.9716796875, + "height": 13, + "text": "Puissance" + }, + { + "_type": "LabelView", + "_id": "AAAAAAGAQb2Y1qgRI5Q=", + "_parent": { + "$ref": "AAAAAAGAQb2Y1qgOWEU=" + }, + "visible": false, + "font": "Arial;13;0", + "left": 848, + "top": 448, + "width": 73.67724609375, + "height": 13, + "text": "(from Model)" + }, + { + "_type": "LabelView", + "_id": "AAAAAAGAQb2Y1qgS4x0=", + "_parent": { + "$ref": "AAAAAAGAQb2Y1qgOWEU=" + }, + "visible": false, + "font": "Arial;13;0", + "left": 848, + "top": 448, + "height": 13, + "horizontalAlignment": 1 + } + ], + "font": "Arial;13;0", + "left": 728, + "top": 336, + "width": 151.9716796875, + "height": 25, + "stereotypeLabel": { + "$ref": "AAAAAAGAQb2Y1qgPBUM=" + }, + "nameLabel": { + "$ref": "AAAAAAGAQb2Y1qgQmHI=" + }, + "namespaceLabel": { + "$ref": "AAAAAAGAQb2Y1qgRI5Q=" + }, + "propertyLabel": { + "$ref": "AAAAAAGAQb2Y1qgS4x0=" + } + }, + { + "_type": "UMLAttributeCompartmentView", + "_id": "AAAAAAGAQb2Y1qgTZio=", + "_parent": { + "$ref": "AAAAAAGAQb2Y1qgNzok=" + }, + "model": { + "$ref": "AAAAAAGAQb2Y1agLYCI=" + }, + "font": "Arial;13;0", + "left": 728, + "top": 361, + "width": 151.9716796875, + "height": 10 + }, + { + "_type": "UMLOperationCompartmentView", + "_id": "AAAAAAGAQb2Y1qgU+G8=", + "_parent": { + "$ref": "AAAAAAGAQb2Y1qgNzok=" + }, + "model": { + "$ref": "AAAAAAGAQb2Y1agLYCI=" + }, + "subViews": [ + { + "_type": "UMLOperationView", + "_id": "AAAAAAGAQb2znag4OPI=", + "_parent": { + "$ref": "AAAAAAGAQb2Y1qgU+G8=" + }, + "model": { + "$ref": "AAAAAAGAQb2zkqg1cC4=" + }, + "font": "Arial;13;0", + "left": 733, + "top": 376, + "width": 141.9716796875, + "height": 13, + "text": "+void main(String[] args)", + "horizontalAlignment": 0 + } + ], + "font": "Arial;13;0", + "left": 728, + "top": 371, + "width": 151.9716796875, + "height": 23 + }, + { + "_type": "UMLReceptionCompartmentView", + "_id": "AAAAAAGAQb2Y16gVdAA=", + "_parent": { + "$ref": "AAAAAAGAQb2Y1qgNzok=" + }, + "model": { + "$ref": "AAAAAAGAQb2Y1agLYCI=" + }, + "visible": false, + "font": "Arial;13;0", + "left": 424, + "top": 224, + "width": 10, + "height": 10 + }, + { + "_type": "UMLTemplateParameterCompartmentView", + "_id": "AAAAAAGAQb2Y16gW0+g=", + "_parent": { + "$ref": "AAAAAAGAQb2Y1qgNzok=" + }, + "model": { + "$ref": "AAAAAAGAQb2Y1agLYCI=" + }, + "visible": false, + "font": "Arial;13;0", + "left": 424, + "top": 224, + "width": 10, + "height": 10 + } + ], + "font": "Arial;13;0", + "containerChangeable": true, + "left": 728, + "top": 336, + "width": 151.9716796875, + "height": 58, + "nameCompartment": { + "$ref": "AAAAAAGAQb2Y1qgOWEU=" + }, + "attributeCompartment": { + "$ref": "AAAAAAGAQb2Y1qgTZio=" + }, + "operationCompartment": { + "$ref": "AAAAAAGAQb2Y1qgU+G8=" + }, + "receptionCompartment": { + "$ref": "AAAAAAGAQb2Y16gVdAA=" + }, + "templateParameterCompartment": { + "$ref": "AAAAAAGAQb2Y16gW0+g=" + } + } + ] + }, + { + "_type": "UMLClass", + "_id": "AAAAAAGAQbmqT6e9eOw=", + "_parent": { + "$ref": "AAAAAAFF+qBWK6M3Z8Y=" + }, + "name": "Grille", + "attributes": [ + { + "_type": "UMLAttribute", + "_id": "AAAAAAGAQboV2KfoKgU=", + "_parent": { + "$ref": "AAAAAAGAQbmqT6e9eOw=" + }, + "name": "short[][] Cases", + "visibility": "private" + }, + { + "_type": "UMLAttribute", + "_id": "AAAAAAGAQbqsbqfw1J0=", + "_parent": { + "$ref": "AAAAAAGAQbmqT6e9eOw=" + }, + "name": "int joueurActuel", + "visibility": "private" + } + ], + "operations": [ + { + "_type": "UMLOperation", + "_id": "AAAAAAGAQbr0L6f4b9I=", + "_parent": { + "$ref": "AAAAAAGAQbmqT6e9eOw=" + }, + "name": "void jouer", + "parameters": [ + { + "_type": "UMLParameter", + "_id": "AAAAAAGAQbujh6gHSNE=", + "_parent": { + "$ref": "AAAAAAGAQbr0L6f4b9I=" + }, + "name": "int colonne", + "type": "" + } + ] + }, + { + "_type": "UMLOperation", + "_id": "AAAAAAGAQbt7saf/ho0=", + "_parent": { + "$ref": "AAAAAAGAQbmqT6e9eOw=" + }, + "name": "String toString" + } + ] + }, + { + "_type": "UMLClass", + "_id": "AAAAAAGAQb2Y1agLYCI=", + "_parent": { + "$ref": "AAAAAAFF+qBWK6M3Z8Y=" + }, + "name": "Puissance", + "operations": [ + { + "_type": "UMLOperation", + "_id": "AAAAAAGAQb2zkqg1cC4=", + "_parent": { + "$ref": "AAAAAAGAQb2Y1agLYCI=" + }, + "name": "void main", + "parameters": [ + { + "_type": "UMLParameter", + "_id": "AAAAAAGAQb3L3Kg8tz0=", + "_parent": { + "$ref": "AAAAAAGAQb2zkqg1cC4=" + }, + "name": "String[] args", + "type": "" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/APL2.1/Controle Machine/horville_apl21/Puissance/Grille.java b/APL2.1/Controle Machine/horville_apl21/Puissance/Grille.java new file mode 100644 index 0000000..939b397 --- /dev/null +++ b/APL2.1/Controle Machine/horville_apl21/Puissance/Grille.java @@ -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; + } +} \ No newline at end of file diff --git a/APL2.1/Controle Machine/horville_apl21/Puissance/Puissance.java b/APL2.1/Controle Machine/horville_apl21/Puissance/Puissance.java new file mode 100644 index 0000000..05d7816 --- /dev/null +++ b/APL2.1/Controle Machine/horville_apl21/Puissance/Puissance.java @@ -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); + } +} \ No newline at end of file diff --git a/APL2.1/Controle Machine/horville_apl21/Tuile/TileBackground.java b/APL2.1/Controle Machine/horville_apl21/Tuile/TileBackground.java new file mode 100644 index 0000000..f285657 --- /dev/null +++ b/APL2.1/Controle Machine/horville_apl21/Tuile/TileBackground.java @@ -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); + } + } + } +} \ No newline at end of file diff --git a/APL2.1/Controle Machine/horville_apl21/Tuile/Tuile.java b/APL2.1/Controle Machine/horville_apl21/Tuile/Tuile.java new file mode 100644 index 0000000..da6b41c --- /dev/null +++ b/APL2.1/Controle Machine/horville_apl21/Tuile/Tuile.java @@ -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); + } +} \ No newline at end of file diff --git a/APL2.1/Controle Machine/horville_apl21/Tuile/tuile.jpg b/APL2.1/Controle Machine/horville_apl21/Tuile/tuile.jpg new file mode 100644 index 0000000..55612e6 Binary files /dev/null and b/APL2.1/Controle Machine/horville_apl21/Tuile/tuile.jpg differ diff --git a/DEV 2.3/Largest/Largest.class b/DEV 2.3/Largest/Largest.class new file mode 100644 index 0000000..9d0de60 Binary files /dev/null and b/DEV 2.3/Largest/Largest.class differ diff --git a/DEV 2.3/Largest/Largest.java b/DEV 2.3/Largest/Largest.java new file mode 100644 index 0000000..6f04a56 --- /dev/null +++ b/DEV 2.3/Largest/Largest.java @@ -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; + } + } \ No newline at end of file diff --git a/DEV 2.3/Largest/TestLargest.class b/DEV 2.3/Largest/TestLargest.class new file mode 100644 index 0000000..ab0a951 Binary files /dev/null and b/DEV 2.3/Largest/TestLargest.class differ diff --git a/DEV 2.3/Largest/TestLargest.java b/DEV 2.3/Largest/TestLargest.java new file mode 100644 index 0000000..6050a99 --- /dev/null +++ b/DEV 2.3/Largest/TestLargest.java @@ -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); + } +} \ No newline at end of file