lab 7 - partie 1

This commit is contained in:
Rémi Heredero 2021-11-29 20:20:20 +01:00
parent b76b39490c
commit 80c743cb15
3 changed files with 62 additions and 0 deletions

7
.vscode/launch.json vendored
View File

@ -4,6 +4,13 @@
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387 // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"type": "java",
"name": "Launch Task1Runner",
"request": "launch",
"mainClass": "lab7_Classe_et_tableaux.Task1Runner",
"projectName": "Labo_6a2f7ad1"
},
{ {
"type": "java", "type": "java",
"name": "Launch Main", "name": "Launch Main",

View File

@ -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;
}
}

View File

@ -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);
}
}