lab 7 - partie 1
This commit is contained in:
parent
b76b39490c
commit
80c743cb15
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
@ -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",
|
||||
|
37
src/lab7_Classe_et_tableaux/Rectangle.java
Normal file
37
src/lab7_Classe_et_tableaux/Rectangle.java
Normal 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;
|
||||
}
|
||||
}
|
18
src/lab7_Classe_et_tableaux/Task1Runner.java
Normal file
18
src/lab7_Classe_et_tableaux/Task1Runner.java
Normal 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);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user