From 80c743cb158925e35356251f3c026886e961a90a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Mon, 29 Nov 2021 20:20:20 +0100 Subject: [PATCH] lab 7 - partie 1 --- .vscode/launch.json | 7 ++++ src/lab7_Classe_et_tableaux/Rectangle.java | 37 ++++++++++++++++++++ src/lab7_Classe_et_tableaux/Task1Runner.java | 18 ++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/lab7_Classe_et_tableaux/Rectangle.java create mode 100644 src/lab7_Classe_et_tableaux/Task1Runner.java diff --git a/.vscode/launch.json b/.vscode/launch.json index 2f9a2b1..8f9a687 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,13 @@ // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "type": "java", + "name": "Launch Task1Runner", + "request": "launch", + "mainClass": "lab7_Classe_et_tableaux.Task1Runner", + "projectName": "Labo_6a2f7ad1" + }, { "type": "java", "name": "Launch Main", diff --git a/src/lab7_Classe_et_tableaux/Rectangle.java b/src/lab7_Classe_et_tableaux/Rectangle.java new file mode 100644 index 0000000..349f4a5 --- /dev/null +++ b/src/lab7_Classe_et_tableaux/Rectangle.java @@ -0,0 +1,37 @@ +package lab7_Classe_et_tableaux; + +import java.awt.Color; + +/** + * @author RĂ©mi Heredero + * @Klagarge + */ +public class Rectangle { + private double width; + private double height; + private Color color; + + public Rectangle(double width, double height){ + this.width = width; + this.height = height; + color = Color.RED; + } + + public String toString(){ + String s = "Rectangle size : "; + s += this.width; + s += " x "; + s += this.height; + s += "\n Color: "; + s += this.color; + return s; + } + + public void changeColor(Color c) { + this.color = c; + } + + public double area() { + return this.width * this.height; + } +} diff --git a/src/lab7_Classe_et_tableaux/Task1Runner.java b/src/lab7_Classe_et_tableaux/Task1Runner.java new file mode 100644 index 0000000..faa71dc --- /dev/null +++ b/src/lab7_Classe_et_tableaux/Task1Runner.java @@ -0,0 +1,18 @@ +package lab7_Classe_et_tableaux; + +import java.awt.Color; + +public class Task1Runner { + public static void main(String[] args) { + + Rectangle r1 = new Rectangle (10, 5); + Rectangle r2 = new Rectangle (3, 4); + Rectangle r3 = new Rectangle (100, 100); + + System.out.println(r1.area()); + System.out.println(r2); + r3.changeColor(Color.GRAY); + System.out.println(r3); + + } +}