aoc-2015/jour02/Box.java

59 lines
1.4 KiB
Java
Raw Normal View History

2021-03-06 16:53:49 +00:00
public class Box {
private int l, w, h;
2021-03-06 18:02:54 +00:00
/**
* Constructeur de boite
*
* @param l longueur
* @param w largeur
* @param h hauteur
*/
2021-03-06 16:53:49 +00:00
public Box (int l, int w, int h) {
this.l = l;
this.w = w;
this.h = h;
}
2021-03-06 18:02:54 +00:00
/**
* Calcule la surface de la boite.
*
* @return la surface de la boite
*/
2021-03-06 16:53:49 +00:00
public int getSurface() {
return 2*(this.l*this.w + this.w*this.h + this.h*this.l);
}
2021-03-06 18:02:54 +00:00
/**
* Trouve et renvoi la plus petite surface de la boite
*
* @return la plus petite surface de la boite
*/
2021-03-06 16:53:49 +00:00
public int areaSmallSurface() {
2021-03-06 18:02:54 +00:00
// pour faire + jolie
2021-03-06 16:53:49 +00:00
int wl = this.w * this.l;
int wh = this.w * this.h;
int lh = this.l * this.h;
int ret = wl >= wh ? wh : wl;
if (ret > lh)
ret = lh;
return ret;
}
2021-03-06 18:02:54 +00:00
public int calculateRibbon() {
int wl = 2 * (this.w + this.l);
int wh = 2 * (this.w + this.h);
int lh = 2 * (this.h + this.l);
int ret = wl >= wh ? wh : wl;
if (ret > lh)
ret = lh;
ret += this.w * this.l * this.h;
return ret;
}
2021-03-06 16:53:49 +00:00
}