From 9749119587561f5848349b7a1b9e7d9342944f0d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 8 Jan 2019 13:21:01 +0100 Subject: [PATCH] Basic classes structure that deal with Person attributes. --- .idea/description.html | 2 +- src/Eye.java | 17 ++++++++++++++ src/Firstname.java | 11 +++++++++ src/Origin.java | 15 ++++++++++++ src/Person.java | 53 ++++++++++++++++++++++++++++++++++++++++++ src/Size.java | 24 +++++++++++++++++++ src/Weight.java | 21 +++++++++++++++++ 7 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 src/Eye.java create mode 100644 src/Firstname.java create mode 100644 src/Origin.java create mode 100644 src/Person.java create mode 100644 src/Size.java create mode 100644 src/Weight.java diff --git a/.idea/description.html b/.idea/description.html index db5f129..05a1fec 100644 --- a/.idea/description.html +++ b/.idea/description.html @@ -1 +1 @@ -Simple Java application that includes a class with main() method \ No newline at end of file +Persons Comparator Java application that includes a class with main() method \ No newline at end of file diff --git a/src/Eye.java b/src/Eye.java new file mode 100644 index 0000000..b02dbfc --- /dev/null +++ b/src/Eye.java @@ -0,0 +1,17 @@ +import java.awt.Color; + +public class Eye { + private Color color; + + Eye(Color color) { + setColor(color); + } + + public Color getColor() { + return color; + } + + public void setColor(Color color) { + this.color = color; + } +} diff --git a/src/Firstname.java b/src/Firstname.java new file mode 100644 index 0000000..2535c0e --- /dev/null +++ b/src/Firstname.java @@ -0,0 +1,11 @@ +public class Firstname { + private String firstname; + + public String getFirstname() { + return firstname; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } +} diff --git a/src/Origin.java b/src/Origin.java new file mode 100644 index 0000000..72ecd83 --- /dev/null +++ b/src/Origin.java @@ -0,0 +1,15 @@ +public class Origin { + private String country; + + Origin(String country) { + setCountry(country); + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } +} diff --git a/src/Person.java b/src/Person.java new file mode 100644 index 0000000..56a02a8 --- /dev/null +++ b/src/Person.java @@ -0,0 +1,53 @@ +import javax.swing.*; + +public class Person extends JPanel { + private Firstname firstname; + private Origin origin; + private Size size; + private Weight weight; + private Eye eye; + + Person(Firstname firstname) { + setFirstname(firstname); + } + + public void setFirstname(Firstname firstname) { + this.firstname = firstname; + } + + public Firstname getFirstname() { + return firstname; + } + + public void setOrigin(Origin origin) { + this.origin = origin; + } + + public Origin getOrigin() { + return origin; + } + + public void setPersonSize(Size size) { + this.size = size; + } + + public Size getPersonSize() { + return size; + } + + public void setWeight(Weight weight) { + this.weight = weight; + } + + public Weight getWeight() { + return weight; + } + + public void setEye(Eye eye) { + this.eye = eye; + } + + public Eye getEye() { + return eye; + } +} diff --git a/src/Size.java b/src/Size.java new file mode 100644 index 0000000..0cecada --- /dev/null +++ b/src/Size.java @@ -0,0 +1,24 @@ + +public class Size { + private int max = 240; + private int min = 20; + private int size; + + Size(int size) { + setSize(size); + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + if (validateSize(size)) { + this.size = size; + } /* FIXME: raise an error */ + } + + private boolean validateSize(int size) { + return (size > max || size < min); + } +} diff --git a/src/Weight.java b/src/Weight.java new file mode 100644 index 0000000..3f2a829 --- /dev/null +++ b/src/Weight.java @@ -0,0 +1,21 @@ +public class Weight { + private int weight; + + Weight(int weight) { + setWeight(weight); + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + if (validateWeight(weight)) { + this.weight = weight; + } /* FIXME: raise an error */ + } + + private boolean validateWeight(int weight) { + return (weight > 0); + } +} -- 2.34.1