DEV 3.2 ; TP01

This commit is contained in:
HORVILLE 2022-10-05 11:07:41 +02:00
parent 8f86f3798f
commit 9bca200351
30 changed files with 383 additions and 1 deletions

View File

@ -101,4 +101,4 @@ public class Tableau {
System.err.println("Unable to close connection."); System.err.println("Unable to close connection.");
} }
} }
} }

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -0,0 +1,49 @@
package fr.iutfbleau.galerie;
import javax.swing.*;
import java.awt.*;
import java.io.InputStream;
import javax.imageio.ImageIO;
public class Galerie {
static ClassLoader loader = Thread.currentThread().getContextClassLoader();
private static String[] paths = {
"house", "info", "ok", "mail", "whatsapp"
};
private static int count = -1;
private static JLabel lb;
private static JFrame window;
public static void update(boolean increment) {
count += increment ? 1 : -1;
if (count == -1) {
count = paths.length-1;
}
count %= paths.length;
if (lb != null) window.remove(lb);
try {
InputStream is = loader.getResourceAsStream("images/" + paths[count] + ".png");
lb = new JLabel(new ImageIcon(ImageIO.read(is)));
lb.addMouseListener(new GalleryListener());
window.add(lb, BorderLayout.CENTER);
window.revalidate();
} catch (Exception e) {
System.out.println("E");
}
}
public static void main(String[] args) {
window = new JFrame("Galerie");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(650, 650);
window.setLocation(200, 200);
window.setVisible(true);
Galerie.update(true);
}
}

View File

@ -0,0 +1,41 @@
package fr.iutfbleau.galerie;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GalleryListener implements MouseListener {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
JLabel source = (JLabel)e.getSource();
int x = e.getX();
Galerie.update(x > source.getWidth() / 2);
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
}

60
DEV 3.1/TP4/quiz/Makefile Normal file
View File

@ -0,0 +1,60 @@
JAVAC_OPTIONS = -implicit:none -d build -classpath build -sourcepath "src:tmp"
JAVA_OPTIONS = -classpath build
PROJECT_PATH = fr/iutfbleau/quiz
JAR_NAME = quiz.jar
JAR_OPTIONS = cvfe $(JAR_NAME) $(PROJECT_PATH).Startup -C build fr
jar : build/$(PROJECT_PATH)/Startup.class
jar $(JAR_OPTIONS)
exec : build/$(PROJECT_PATH)/Startup.class
java $(JAVA_OPTIONS) $(PROJECT_PATH)/Startup
rm :
rm -rf build/*
build/$(PROJECT_PATH)/Startup.class : view controller model
javac $(JAVAC_OPTIONS) src/$(PROJECT_PATH)/Startup.java
view : build/$(PROJECT_PATH)/view/ChoiceConfirm.class \
build/$(PROJECT_PATH)/view/QuestionShower.class \
build/$(PROJECT_PATH)/view/Window.class
build/$(PROJECT_PATH)/view/ChoiceConfirm.class : src/$(PROJECT_PATH)/view/ChoiceConfirm.java
javac $(JAVAC_OPTIONS) src/$(PROJECT_PATH)/view/ChoiceConfirm.java
build/$(PROJECT_PATH)/view/QuestionShower.class : src/$(PROJECT_PATH)/view/QuestionShower.java
javac $(JAVAC_OPTIONS) src/$(PROJECT_PATH)/view/QuestionShower.java
build/$(PROJECT_PATH)/view/Window.class : src/$(PROJECT_PATH)/view/Window.java
javac $(JAVAC_OPTIONS) src/$(PROJECT_PATH)/view/Window.java
controller : build/$(PROJECT_PATH)/controller/ChoiceValidation.class \
build/$(PROJECT_PATH)/controller/Navigation.class
build/$(PROJECT_PATH)/controller/ChoiceValidation.class : src/$(PROJECT_PATH)/controller/ChoiceValidation.java
javac $(JAVAC_OPTIONS) src/$(PROJECT_PATH)/controller/ChoiceValidation.java
build/$(PROJECT_PATH)/controller/Navigation.class : src/$(PROJECT_PATH)/controller/Navigation.java
javac $(JAVAC_OPTIONS) src/$(PROJECT_PATH)/controller/Navigation.java
model : build/$(PROJECT_PATH)/model/QuestionSource.class \
build/$(PROJECT_PATH)/model/Question.class \
build/$(PROJECT_PATH)/model/Choice.class
build/$(PROJECT_PATH)/model/QuestionSource.class : src/$(PROJECT_PATH)/model/QuestionSource.java
javac $(JAVAC_OPTIONS) src/$(PROJECT_PATH)/model/QuestionSource.java
build/$(PROJECT_PATH)/model/Question.class : src/$(PROJECT_PATH)/model/Question.java
javac $(JAVAC_OPTIONS) src/$(PROJECT_PATH)/model/Question.java
build/$(PROJECT_PATH)/model/Choice.class : src/$(PROJECT_PATH)/model/Choice.java
javac $(JAVAC_OPTIONS) src/$(PROJECT_PATH)/model/Choice.java

BIN
DEV 3.1/TP4/quiz/quiz.jar Normal file

Binary file not shown.

View File

@ -0,0 +1,12 @@
package fr.iutfbleau.quiz;
import fr.iutfbleau.quiz.view.Window;
import fr.iutfbleau.quiz.controller.Navigation;
public class Startup {
public static void main(String[] args) {
Window mainWindow = new Window(100, 100, 450, 300);
mainWindow.add(new Navigation());
mainWindow.setVisible(true);
}
}

View File

@ -0,0 +1,5 @@
package fr.iutfbleau.quiz.controller;
public class ChoiceValidation {
}

View File

@ -0,0 +1,9 @@
package fr.iutfbleau.quiz.controller;
import java.awt.*;
public class Navigation extends CardLayout implements ActionListener {
public Navigation() {
super();
}
}

View File

@ -0,0 +1,5 @@
package fr.iutfbleau.quiz.model;
public class Choice {
}

View File

@ -0,0 +1,5 @@
package fr.iutfbleau.quiz.model;
public class Question {
}

View File

@ -0,0 +1,5 @@
package fr.iutfbleau.quiz.model;
public class QuestionSource {
}

View File

@ -0,0 +1,5 @@
package fr.iutfbleau.quiz.view;
public class ChoiceConfirm {
}

View File

@ -0,0 +1,5 @@
package fr.iutfbleau.quiz.view;
public class QuestionShower {
}

View File

@ -0,0 +1,11 @@
package fr.iutfbleau.quiz.view;
import javax.swing.JFrame;
public class Window extends JFrame {
public Window(int x, int y, int w, int h) {
super();
setLocation(x, y);
setSize(w, h);
}
}

View File

@ -0,0 +1,31 @@
public class Association<T> {
private T element;
private int frequency;
public Association(T e, int f) {
this.element = e;
this.frequency = f;
}
public void setElement(T e) {
this.element = e;
}
public T getElement() {
return this.element;
}
public void setFrequency(int f) {
this.frequency = f;
}
public int getFrequency() {
return this.frequency;
}
@Override
public String toString() {
return "[" + this.element + ", " + this.frequency + "]";
}
}

View File

@ -0,0 +1,34 @@
import java.util.Collections;
import java.util.Hashtable;
import java.util.Map;
import java.util.function.BiConsumer;
public class Frequence<T> {
public T mostFrequent(T[] tab) {
Hashtable<T, Integer> indexList = new Hashtable<T, Integer>();
for (T element : tab) {
indexList.put(element, indexList.get(element) == null ? 1 : ((Integer)indexList.get(element)) + 1);
}
T element = tab[0];
Integer count = indexList.get(tab[0]);
for(Map.Entry<T, Integer> entry : indexList.entrySet()) {
if (entry.getValue() > count) {
element = entry.getKey();
count = entry.getValue();
}
}
return element;
}
public static void main(String[] args) {
Frequence<String> f = new Frequence<String>();
String[] tab = {"test", "test", "test", "12", "12", "12", "12"};
System.out.println(f.mostFrequent(tab));
}
}

View File

@ -0,0 +1,35 @@
public class Association<T> {
private T element;
private int frequency;
public Association(T e, int f) {
this.element = e;
this.frequency = f;
}
public void setElement(T e) {
this.element = e;
}
public T getElement() {
return this.element;
}
public void setFrequency(int f) {
this.frequency = f;
}
public int getFrequency() {
return this.frequency;
}
public Association suivant() {
}
@Override
public String toString() {
return "[" + this.element + ", " + this.frequency + "]";
}
}

View File

View File

@ -0,0 +1,20 @@
import java.util.ArrayList;
public class Listes {
public static void main(String[] args) {
ArrayList<Integer> l1 = new ArrayList<Integer>();
ArrayList<Float> l2 = new ArrayList<Float>();
ArrayList<Number> l3 = new ArrayList<Number>();
l1.add(new Integer(22));
l3.add(new Integer(32));
l2.add(new Float(52.3f));
l3.add(new Float(32.3f));
l3.add(new Long(5225922L));
l3.addAll(l1);
l3.addAll(l2);
}
}

View File

@ -0,0 +1,10 @@
import java.util.Comparator;
public class Sorter implements Comparator<String> {
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
}

View File

@ -0,0 +1,10 @@
import java.util.Arrays;
public class Tableaux {
public static void main(String[] args) {
String[] args2 = Arrays.copyOf(args, 5);
Arrays.sort(args2, new Sorter());
System.out.println(Arrays.toString(args2));
}
}

15
Fun/NewMalloc/newmem.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "newmem.h"
void* newmalloc(size_t size) {
void* start = sbrk(0);
void* finish = sbrk(size);
printf("%d\n", finish);
if (start == finish) return NULL;
return finish;
}

6
Fun/NewMalloc/newmem.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef NEWMEM
#define NEWMEM
void* newmalloc(size_t size);
#endif

9
Fun/NewMalloc/test.c Normal file
View File

@ -0,0 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include "newmem.h"
int main(void) {
char* t = (char*)newmalloc(15);
printf("%d", t != NULL);
}