From 9f751a6a947deed314c4942fa0ae5d8fdec44766 Mon Sep 17 00:00:00 2001 From: Motodies <39949690+Motodies@users.noreply.github.com> Date: Sat, 29 Mar 2025 01:30:09 +0100 Subject: [PATCH 01/17] First commit --- .idea/lab-java-basics.iml | 9 +++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ .idea/workspace.xml | 41 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 .idea/lab-java-basics.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/lab-java-basics.iml b/.idea/lab-java-basics.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-java-basics.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..31e1ebc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..505d07d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..56fc85d --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + 1743208028728 + + + + \ No newline at end of file From 16fe9a3e2b72f12c6160dcb8086e6248fd6ad0f7 Mon Sep 17 00:00:00 2001 From: Motodies <39949690+Motodies@users.noreply.github.com> Date: Sat, 29 Mar 2025 01:31:31 +0100 Subject: [PATCH 02/17] First commit --- .idea/lab-java-basics.iml | 4 ++- src/Basics.java | 59 +++++++++++++++++++++++++++++++++++++++ src/Company.java | 21 ++++++++++++++ src/Employee.java | 42 ++++++++++++++++++++++++++++ src/Intern.java | 22 +++++++++++++++ 5 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 src/Basics.java create mode 100644 src/Company.java create mode 100644 src/Employee.java create mode 100644 src/Intern.java diff --git a/.idea/lab-java-basics.iml b/.idea/lab-java-basics.iml index d6ebd48..c90834f 100644 --- a/.idea/lab-java-basics.iml +++ b/.idea/lab-java-basics.iml @@ -2,7 +2,9 @@ - + + + diff --git a/src/Basics.java b/src/Basics.java new file mode 100644 index 0000000..de6fe82 --- /dev/null +++ b/src/Basics.java @@ -0,0 +1,59 @@ +public class Basics { + public static void main(String[] args) { + diffLargestAndSmallest(); + firstAndSecondSmallest(); + } + + public static void diffLargestAndSmallest() { + int[] Array = {12, 34, 56, 69, 2, 78}; + int diff = 0; + int smallest = Array[0]; + int largest = Array[0]; + for (int i = 0; i < Array.length; i++) { + if (Array.length > 0) { + if (smallest > Array[i]) { + smallest = Array[i]; + } + if (largest < Array[i]) { + largest = Array[i]; + } + + } + + + } + diff = largest - smallest; + System.out.println("The difference between the smallest (" + smallest + ") and largest (" + largest + ") integer of this array is :" + diff); + } + + public static void firstAndSecondSmallest() { + int[] Array = {12, 34, 56, 69, 2, 78,8}; + int diff = 0; + int firstSmallest = 0; + int secondSmallest = 0; + if (Array.length > 1) { + if (Array[0] > Array[1]) { + firstSmallest = Array[0]; + secondSmallest = Array[1]; + } else { + firstSmallest = Array[1]; + secondSmallest = Array[0]; + } + for (int i : Array) { + if (firstSmallest > i) { + secondSmallest = firstSmallest; + firstSmallest = i; + } + if (secondSmallest > i && firstSmallest < i) { + secondSmallest = i; + } + + } + System.out.println("second smallest " + secondSmallest); + System.out.println("first smallest " + firstSmallest); + + + } + + } +} diff --git a/src/Company.java b/src/Company.java new file mode 100644 index 0000000..52985bb --- /dev/null +++ b/src/Company.java @@ -0,0 +1,21 @@ +public class Company { + public static void main(String[] args) { + Employee[] team = new Employee[10]; + + team[0]=new Intern("Salvatore",18,30000); + team[1]=new Intern("Céline",22,3400); + team[2]=new Intern("Alex",24,4200); + team[3]=new Intern("Elodie",19,6500); + team[4]=new Intern("Rosca",27,1500); + team[5]=new Intern("Ahmad",33,15000); + team[6]=new Intern("Cesar",45,16000); + team[7]=new Intern("Elise",24,2000); + team[8]=new Intern("Tino",50,13000); + team[9]=new Intern("Sébastien",26,10000); + for(Employee member:team){ + + System.out.println(member.toString());; + } + + } +} diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..619810e --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,42 @@ +public class Employee { + private String name; + private int age; + private int salary; + + public Employee(String name, int age, int salary) { + this.name = name; + this.age = age; + this.salary = salary; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + + public int getSalary() { + return salary; + } + + public void setName(String name) { + this.name = name; + } + + public void setAge(int age) { + this.age = age; + } + + public void setSalary(int salary) { + this.salary = salary; + } + public void updateSalary(int newSalary){ + this.salary = newSalary; + } + @Override + public String toString() { + return "Employee Name: " + name +"Age: "+ age + ", Salary: " + salary; + } +} diff --git a/src/Intern.java b/src/Intern.java new file mode 100644 index 0000000..da3e7ff --- /dev/null +++ b/src/Intern.java @@ -0,0 +1,22 @@ +public class Intern extends Employee{ + private static final int maxSalary= 20000; + public Intern(String name,int age,int salary){ + super(name,age,salary); + if(salary>maxSalary){ + throw new IllegalArgumentException("You can not set a salary that exceed "+ maxSalary + " to "+name); + } + + + } + @Override + public void updateSalary(int newSalary) { + if(newSalary<20000){ + super.updateSalary(newSalary); + } + else{ + throw new IllegalArgumentException("You can not set a salary that exceed "+ maxSalary + " to "+super.getName()); + } + } + + +} From 88a6a2e48e92befb75c15311744d63d08b82505f Mon Sep 17 00:00:00 2001 From: Motodies <39949690+Motodies@users.noreply.github.com> Date: Sat, 29 Mar 2025 01:32:47 +0100 Subject: [PATCH 03/17] First commit --- src/Basics.java | 10 +++++----- src/Company.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Basics.java b/src/Basics.java index de6fe82..05e6949 100644 --- a/src/Basics.java +++ b/src/Basics.java @@ -9,13 +9,13 @@ public static void diffLargestAndSmallest() { int diff = 0; int smallest = Array[0]; int largest = Array[0]; - for (int i = 0; i < Array.length; i++) { + for (int j : Array) { if (Array.length > 0) { - if (smallest > Array[i]) { - smallest = Array[i]; + if (smallest > j) { + smallest = j; } - if (largest < Array[i]) { - largest = Array[i]; + if (largest < j) { + largest = j; } } diff --git a/src/Company.java b/src/Company.java index 52985bb..3a6c718 100644 --- a/src/Company.java +++ b/src/Company.java @@ -14,7 +14,7 @@ public static void main(String[] args) { team[9]=new Intern("Sébastien",26,10000); for(Employee member:team){ - System.out.println(member.toString());; + System.out.println(member.toString()); } } From 5be3ef8ae1e9cdf309681c0620f2f14b369c4b67 Mon Sep 17 00:00:00 2001 From: Motodies <39949690+Motodies@users.noreply.github.com> Date: Sat, 29 Mar 2025 01:33:39 +0100 Subject: [PATCH 04/17] First commit --- src/Employee.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Employee.java b/src/Employee.java index 619810e..9b47705 100644 --- a/src/Employee.java +++ b/src/Employee.java @@ -35,8 +35,13 @@ public void setSalary(int salary) { public void updateSalary(int newSalary){ this.salary = newSalary; } + @Override public String toString() { - return "Employee Name: " + name +"Age: "+ age + ", Salary: " + salary; + return "Employee{" + + "name='" + name + '\'' + + ", age=" + age + + ", salary=" + salary + + '}'; } } From 0a19761247e130c26f387adcb391aa372c2823ee Mon Sep 17 00:00:00 2001 From: Motodies <39949690+Motodies@users.noreply.github.com> Date: Sat, 29 Mar 2025 01:37:37 +0100 Subject: [PATCH 05/17] First commit --- src/Employee.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Employee.java b/src/Employee.java index 9b47705..873e7e4 100644 --- a/src/Employee.java +++ b/src/Employee.java @@ -12,26 +12,20 @@ public Employee(String name, int age, int salary) { public String getName() { return name; } - - public int getAge() { - return age; - } - - public int getSalary() { - return salary; - } - public void setName(String name) { this.name = name; } - public void setAge(int age) { - this.age = age; - } + public int getAge() {return age;} + public void setAge(int age) {this.age = age;} + public int getSalary() { + return salary; + } public void setSalary(int salary) { this.salary = salary; } + public void updateSalary(int newSalary){ this.salary = newSalary; } From 1c1e1fe42a35bcb8fa9cb6de289eddd878444046 Mon Sep 17 00:00:00 2001 From: Motodies <39949690+Motodies@users.noreply.github.com> Date: Sat, 29 Mar 2025 01:39:59 +0100 Subject: [PATCH 06/17] First commit --- .idea/workspace.xml | 79 ++++++++++++++++++++++++++++++++++++++++++--- src/Employee.java | 4 --- src/Intern.java | 2 +- 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 56fc85d..c0f60af 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/src/Employee.java b/src/Employee.java index 873e7e4..626c58f 100644 --- a/src/Employee.java +++ b/src/Employee.java @@ -26,10 +26,6 @@ public void setSalary(int salary) { this.salary = salary; } - public void updateSalary(int newSalary){ - this.salary = newSalary; - } - @Override public String toString() { return "Employee{" + diff --git a/src/Intern.java b/src/Intern.java index da3e7ff..0640700 100644 --- a/src/Intern.java +++ b/src/Intern.java @@ -11,7 +11,7 @@ public Intern(String name,int age,int salary){ @Override public void updateSalary(int newSalary) { if(newSalary<20000){ - super.updateSalary(newSalary); + super.setSalary(newSalary); } else{ throw new IllegalArgumentException("You can not set a salary that exceed "+ maxSalary + " to "+super.getName()); From c602e2facf517208abee247c2c597b08359c93a8 Mon Sep 17 00:00:00 2001 From: Motodies <39949690+Motodies@users.noreply.github.com> Date: Sat, 29 Mar 2025 01:40:29 +0100 Subject: [PATCH 07/17] First commit --- src/Intern.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Intern.java b/src/Intern.java index 0640700..9252a25 100644 --- a/src/Intern.java +++ b/src/Intern.java @@ -5,10 +5,8 @@ public Intern(String name,int age,int salary){ if(salary>maxSalary){ throw new IllegalArgumentException("You can not set a salary that exceed "+ maxSalary + " to "+name); } - - } - @Override + public void updateSalary(int newSalary) { if(newSalary<20000){ super.setSalary(newSalary); From 0a443b19896bbc36116ca5ee5a17f8226aec2550 Mon Sep 17 00:00:00 2001 From: Motodies <39949690+Motodies@users.noreply.github.com> Date: Sat, 29 Mar 2025 01:41:49 +0100 Subject: [PATCH 08/17] First commit --- .idea/workspace.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c0f60af..0ff2e11 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,5 +1,8 @@ + + 1743208658212 - diff --git a/out/production/lab-java-basics/Basics.class b/out/production/lab-java-basics/Basics.class deleted file mode 100644 index f8d4611a9c9593c180aa8046ced6d410723781f3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1967 zcmah~T~8xb7=8|&c1kHw3I&mmEiCJnime|kyYf*51i>v^v;@O?` zv>~8Ei6V%QKeUkljFPeSLk> z58&lSZ{66Ni{MoZsThu81fv4IElv+X3~gA`IXLriYRA&_(_jJb$b$Hb{|Qb1WY zD^j34uN(5wQEf+BTiQ;QmU!MQYt?Pd(%p5#s5tvNsfY8v#B=noX*yZ-ryjSW!F|e4 zkKPvB0^)$rx95o5Rq;iA z1-k5O)f9*n%_FNUS9LeD4xfC+6_&MKGEK*JEUmsFoqe-nhcPcu+}f8(mx#2aQI^Ra z>3kujk#uN&K`faPlS$2}BpdX+HLD``q?I&xiPi0-=4O`UWLAX1e(mw8T?L`}eX{T} zXtH*PuoU54_&~*qTgO#_iK}a%8^`9M%=#VUch{;`c1(*R{?ObI4WOUe8p-kkOyo`T z@Tfj_vtUh@YmQqdb=d;mTvPvI&NcUQBg8UqT~T)=n`~!iU_KqlEbz&tXO%(aVkQ`v2_-^_;3@77Dv3~L zMonM*h{SM0Jwqs=E{r79Q+Ja4HYA>0{yj2Wng0dd!y`lINC3ZL&?O!4a-QYa4&?tYgWV(AUBPGjo- zh*gS(VqsUZz(OFGzEI9kr*LT{bA~QYMJ1Daf({y53z}{S>S-As&iQJdAxcA&rhie- zk#pSg)O58yXYSXP{RDkpmMNmrNHY5|YBP>$cF_X$S)_hz?5;c&+9X0}i#`o|ccOtZ|u|@J2{1@qKr{(|v diff --git a/out/production/lab-java-basics/Company.class b/out/production/lab-java-basics/Company.class deleted file mode 100644 index 644f7a52bf4108bf4d13575b0d4ec015f3319fa2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1108 zcmZuvOHUI~7(KV0cBVstnU?oM!51yBDk{pu3f2-a1&t*nhSjA^U~nE}IuO|y7yba3 zuGtut8Uu+BHg1S36WwTB`x{(|-`v3{fyvB$obP_;e&>Ai>G#_`00m5`h#)FMN+O0h zgSN^yc+TR^a_-*Zs!{P7;^U@c`gw+ECOa=fVNiC9-E%d&MVLvFp4`Q!E?ullCpBybkz zWSmdp0(y>!EN@nQ!zOL+I!SE|>oncmeJawYQVnj8sgRLPq8EK6-FHI)3=Ns=aak$` zFeoFJ#6?_UNDJLZ`AG6wz-~Eo;R((JCSMMGaqTtkY?7pcyJRrbm&m2rb$ik9=J=vT zNUG#kxHZo`GuR)3lD}eBsS~Bc{4pZ1xk;BbWfqPXoSi4HZ6jbM%SwMc8)R{BnTXOS zBvH^OXBcW0{?Di_`@HgKhOdcIWaMQ`1buMVy^1kq1|=sCs~QZ9K{tlz_Y0l~sEdfx zc!hR3ni|vkV}2hcSt-; z)o3Ywwrdx)eUOqZ3HAhOln??cBIn!lkzIN3#9`*dy$0Phi#aZ5&lUPit6 Mg$@eerf>wsKiJ6XH~;_u diff --git a/out/production/lab-java-basics/Employee.class b/out/production/lab-java-basics/Employee.class deleted file mode 100644 index 117d8acec3ee8dea0cdaaa49c77cd1e89f5abb2a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1534 zcmaKsTTc@~6vzKV%WkP#p{0P_1O=omNWEVukZ2>ZNyUc}eDG-~ld`bgZFUEe#`rz_ z5I$%kG2y`v;D<7v+1*~Giw`^3Gw1xy`Ooa{KbOA%l(Ct_5Mnyw28N+AjGgdvUbMK~ zD84^D5p~I+ZJD+ycNk*1{J{tk7}1e5a03QI;!U$rx;9dOrF^KdaPk4=i4tag$uG3X5; z_xyyjxyazU*D;ugz{nGXMlN2dYEWG(stVyWo~x+s5!$Z#g`qL+b;b$l1a&2%nsesX z#jdH)QysbuB>*Y;+Hs^OUEX>pFbG{UEK+&__6}Jq$C{7a164m0P^e*~eGij?RToYR;TY~> zDfHD3lKOfDWIPgN87tx8%`V6+m8}O7q>;S_Le)iOe=iaueHCIV5@NLr(W?eQ^vM=f zV}`0Rdku(^MS0U0F=eJT3Vm!u%BYP8Ttl?f{xL*6f70c+H&tF}SkI-bxh MNu#HDj+dDJ3q4sK7XSbN diff --git a/out/production/lab-java-basics/Intern.class b/out/production/lab-java-basics/Intern.class deleted file mode 100644 index 0552cec49e9444dd4574515f325e208d3473cd62..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1265 zcmaKrT~8B16o%hv3)?R!t$c`3T@bJorHJ2xCfY!3QtCxX4e@H&PTHm0*=Bc&@DKb6 zUKM#n zrjTmy%n&VQ+A>91<8e%2l60HAA@a5~xO!u%I$5sbQn?IkBQmZJLqrk5ln0(CsP z@v6HL$24XbBCb$nZgJ)O({z4=CN=N`LRVSsiJLgtHK@AoA(w&s%}!T;iA8VI}|Uw2&v&x z8G^j#HO1{!Fi}?AXdLiXS4_h?!_?*W`(0v)w_8=NL?1jN#k;;8E!%C!5c{Ub7xNJ| zJp~eaY1_(G4sRU@Rky2d7+VavBfG5|T^m_xUb=X*YSr8E0=_(JhdC5cbxn~u+I%;d)@gk*vp=yPx6Y(swLc&qHQX5NoV&+D}E9w8b)I=iu$?trC}CH)hUUlBRl zxIhf(Ao2YRIRtToo~f>Lh{VS*Ng|5~L#OquFG6XTX-0Cmi4{uWS*w)ZLrG(etRQZY zodo+u!66Nrh79u@8HvpFs2b$vg)A))&PT+u3mv3BW7@;Yb};)-vKW!Yk)WYd4xJ=s seW5>OOW5dcher`YATdR$Zj&9r9c Date: Sat, 29 Mar 2025 01:46:41 +0100 Subject: [PATCH 12/17] First commit --- out/production/lab-java-basics/Basics.class | Bin 1967 -> 0 bytes out/production/lab-java-basics/Company.class | Bin 1108 -> 0 bytes out/production/lab-java-basics/Employee.class | Bin 1534 -> 0 bytes out/production/lab-java-basics/Intern.class | Bin 1265 -> 0 bytes 4 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 out/production/lab-java-basics/Basics.class delete mode 100644 out/production/lab-java-basics/Company.class delete mode 100644 out/production/lab-java-basics/Employee.class delete mode 100644 out/production/lab-java-basics/Intern.class diff --git a/out/production/lab-java-basics/Basics.class b/out/production/lab-java-basics/Basics.class deleted file mode 100644 index f8d4611a9c9593c180aa8046ced6d410723781f3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1967 zcmah~T~8xb7=8|&c1kHw3I&mmEiCJnime|kyYf*51i>v^v;@O?` zv>~8Ei6V%QKeUkljFPeSLk> z58&lSZ{66Ni{MoZsThu81fv4IElv+X3~gA`IXLriYRA&_(_jJb$b$Hb{|Qb1WY zD^j34uN(5wQEf+BTiQ;QmU!MQYt?Pd(%p5#s5tvNsfY8v#B=noX*yZ-ryjSW!F|e4 zkKPvB0^)$rx95o5Rq;iA z1-k5O)f9*n%_FNUS9LeD4xfC+6_&MKGEK*JEUmsFoqe-nhcPcu+}f8(mx#2aQI^Ra z>3kujk#uN&K`faPlS$2}BpdX+HLD``q?I&xiPi0-=4O`UWLAX1e(mw8T?L`}eX{T} zXtH*PuoU54_&~*qTgO#_iK}a%8^`9M%=#VUch{;`c1(*R{?ObI4WOUe8p-kkOyo`T z@Tfj_vtUh@YmQqdb=d;mTvPvI&NcUQBg8UqT~T)=n`~!iU_KqlEbz&tXO%(aVkQ`v2_-^_;3@77Dv3~L zMonM*h{SM0Jwqs=E{r79Q+Ja4HYA>0{yj2Wng0dd!y`lINC3ZL&?O!4a-QYa4&?tYgWV(AUBPGjo- zh*gS(VqsUZz(OFGzEI9kr*LT{bA~QYMJ1Daf({y53z}{S>S-As&iQJdAxcA&rhie- zk#pSg)O58yXYSXP{RDkpmMNmrNHY5|YBP>$cF_X$S)_hz?5;c&+9X0}i#`o|ccOtZ|u|@J2{1@qKr{(|v diff --git a/out/production/lab-java-basics/Company.class b/out/production/lab-java-basics/Company.class deleted file mode 100644 index 644f7a52bf4108bf4d13575b0d4ec015f3319fa2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1108 zcmZuvOHUI~7(KV0cBVstnU?oM!51yBDk{pu3f2-a1&t*nhSjA^U~nE}IuO|y7yba3 zuGtut8Uu+BHg1S36WwTB`x{(|-`v3{fyvB$obP_;e&>Ai>G#_`00m5`h#)FMN+O0h zgSN^yc+TR^a_-*Zs!{P7;^U@c`gw+ECOa=fVNiC9-E%d&MVLvFp4`Q!E?ullCpBybkz zWSmdp0(y>!EN@nQ!zOL+I!SE|>oncmeJawYQVnj8sgRLPq8EK6-FHI)3=Ns=aak$` zFeoFJ#6?_UNDJLZ`AG6wz-~Eo;R((JCSMMGaqTtkY?7pcyJRrbm&m2rb$ik9=J=vT zNUG#kxHZo`GuR)3lD}eBsS~Bc{4pZ1xk;BbWfqPXoSi4HZ6jbM%SwMc8)R{BnTXOS zBvH^OXBcW0{?Di_`@HgKhOdcIWaMQ`1buMVy^1kq1|=sCs~QZ9K{tlz_Y0l~sEdfx zc!hR3ni|vkV}2hcSt-; z)o3Ywwrdx)eUOqZ3HAhOln??cBIn!lkzIN3#9`*dy$0Phi#aZ5&lUPit6 Mg$@eerf>wsKiJ6XH~;_u diff --git a/out/production/lab-java-basics/Employee.class b/out/production/lab-java-basics/Employee.class deleted file mode 100644 index 117d8acec3ee8dea0cdaaa49c77cd1e89f5abb2a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1534 zcmaKsTTc@~6vzKV%WkP#p{0P_1O=omNWEVukZ2>ZNyUc}eDG-~ld`bgZFUEe#`rz_ z5I$%kG2y`v;D<7v+1*~Giw`^3Gw1xy`Ooa{KbOA%l(Ct_5Mnyw28N+AjGgdvUbMK~ zD84^D5p~I+ZJD+ycNk*1{J{tk7}1e5a03QI;!U$rx;9dOrF^KdaPk4=i4tag$uG3X5; z_xyyjxyazU*D;ugz{nGXMlN2dYEWG(stVyWo~x+s5!$Z#g`qL+b;b$l1a&2%nsesX z#jdH)QysbuB>*Y;+Hs^OUEX>pFbG{UEK+&__6}Jq$C{7a164m0P^e*~eGij?RToYR;TY~> zDfHD3lKOfDWIPgN87tx8%`V6+m8}O7q>;S_Le)iOe=iaueHCIV5@NLr(W?eQ^vM=f zV}`0Rdku(^MS0U0F=eJT3Vm!u%BYP8Ttl?f{xL*6f70c+H&tF}SkI-bxh MNu#HDj+dDJ3q4sK7XSbN diff --git a/out/production/lab-java-basics/Intern.class b/out/production/lab-java-basics/Intern.class deleted file mode 100644 index 0552cec49e9444dd4574515f325e208d3473cd62..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1265 zcmaKrT~8B16o%hv3)?R!t$c`3T@bJorHJ2xCfY!3QtCxX4e@H&PTHm0*=Bc&@DKb6 zUKM#n zrjTmy%n&VQ+A>91<8e%2l60HAA@a5~xO!u%I$5sbQn?IkBQmZJLqrk5ln0(CsP z@v6HL$24XbBCb$nZgJ)O({z4=CN=N`LRVSsiJLgtHK@AoA(w&s%}!T;iA8VI}|Uw2&v&x z8G^j#HO1{!Fi}?AXdLiXS4_h?!_?*W`(0v)w_8=NL?1jN#k;;8E!%C!5c{Ub7xNJ| zJp~eaY1_(G4sRU@Rky2d7+VavBfG5|T^m_xUb=X*YSr8E0=_(JhdC5cbxn~u+I%;d)@gk*vp=yPx6Y(swLc&qHQX5NoV&+D}E9w8b)I=iu$?trC}CH)hUUlBRl zxIhf(Ao2YRIRtToo~f>Lh{VS*Ng|5~L#OquFG6XTX-0Cmi4{uWS*w)ZLrG(etRQZY zodo+u!66Nrh79u@8HvpFs2b$vg)A))&PT+u3mv3BW7@;Yb};)-vKW!Yk)WYd4xJ=s seW5>OOW5dcher`YATdR$Zj&9r9c Date: Sat, 29 Mar 2025 09:15:59 +0100 Subject: [PATCH 13/17] Some optimisation and commenting --- .idea/workspace.xml | 37 ++++++++++++++++++-- src/Basics.java | 84 +++++++++++++++++++++++++++------------------ src/Company.java | 27 ++++++++------- src/Employee.java | 20 +++++++++-- src/Intern.java | 32 ++++++++++------- 5 files changed, 138 insertions(+), 62 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2bdebfc..dde1643 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,7 +4,13 @@ - + + + + + + + - \ No newline at end of file diff --git a/src/Basics.java b/src/Basics.java index 05e6949..792d569 100644 --- a/src/Basics.java +++ b/src/Basics.java @@ -1,59 +1,77 @@ public class Basics { public static void main(String[] args) { + // Call methods to calculate the difference between the largest and smallest element, + // and to find the two smallest elements in the array. diffLargestAndSmallest(); firstAndSecondSmallest(); } + /** + * Method to calculate the difference between the largest and smallest element in an array. + */ public static void diffLargestAndSmallest() { - int[] Array = {12, 34, 56, 69, 2, 78}; - int diff = 0; - int smallest = Array[0]; - int largest = Array[0]; - for (int j : Array) { - if (Array.length > 0) { + // Initialize the array with values. + int[] array = {12, 34, 56, 69, 2, 78}; + + // Initialize variables to store the smallest and largest elements. + int smallest = array[0]; + int largest = array[0]; + + // Iterate through each element in the array. + if(array.length>0){ + for (int j : array) { + // Update the smallest element if the current element is smaller. if (smallest > j) { smallest = j; } + // Update the largest element if the current element is larger. if (largest < j) { largest = j; } - } - } - diff = largest - smallest; - System.out.println("The difference between the smallest (" + smallest + ") and largest (" + largest + ") integer of this array is :" + diff); + + + // Calculate the difference between the largest and smallest elements. + int diff = largest - smallest; + + // Print the result. + System.out.println("The difference between the smallest (" + smallest + ") and largest (" + largest + ") integer of this array is: " + diff); } + /** + * Method to find the two smallest elements in an array. + */ public static void firstAndSecondSmallest() { - int[] Array = {12, 34, 56, 69, 2, 78,8}; - int diff = 0; - int firstSmallest = 0; - int secondSmallest = 0; - if (Array.length > 1) { - if (Array[0] > Array[1]) { - firstSmallest = Array[0]; - secondSmallest = Array[1]; - } else { - firstSmallest = Array[1]; - secondSmallest = Array[0]; - } - for (int i : Array) { - if (firstSmallest > i) { - secondSmallest = firstSmallest; - firstSmallest = i; - } - if (secondSmallest > i && firstSmallest < i) { - secondSmallest = i; - } + // Initialize the array with values. + int[] array = {12, 34, 56, 69, 2, 78, 8}; - } - System.out.println("second smallest " + secondSmallest); - System.out.println("first smallest " + firstSmallest); + // Check that the array contains at least two elements. + if (array.length < 2) { + System.out.println("Array must have at least two elements."); + return; + } + // Initialize variables to store the two smallest elements. + int firstSmallest = Integer.MAX_VALUE; + int secondSmallest = Integer.MAX_VALUE; + // Iterate through each element in the array. + for (int i : array) { + // Update the first smallest element if the current element is smaller. + if (firstSmallest > i) { + secondSmallest = firstSmallest; + firstSmallest = i; + } + // Update the second smallest element if the current element is smaller than the second smallest but larger than the first smallest. + else if (secondSmallest > i) { + secondSmallest = i; + } } + // Print the two smallest elements. + System.out.println("First smallest: " + firstSmallest); + System.out.println("Second smallest: " + secondSmallest); } } diff --git a/src/Company.java b/src/Company.java index 3b49656..20c1823 100644 --- a/src/Company.java +++ b/src/Company.java @@ -1,21 +1,24 @@ public class Company { public static void main(String[] args) { + // Create an array to hold 10 Employee objects. Employee[] team = new Employee[10]; - team[0]=new Intern("Salvatore",18,20000); - team[1]=new Intern("Céline",22,3400); - team[2]=new Intern("Alex",24,4200); - team[3]=new Intern("Elodie",19,6500); - team[4]=new Intern("Rosca",27,1500); - team[5]=new Intern("Ahmad",33,15000); - team[6]=new Intern("Cesar",45,16000); - team[7]=new Intern("Elise",24,2000); - team[8]=new Intern("Tino",50,13000); - team[9]=new Intern("Sébastien",26,10000); - for(Employee member:team){ + // Initialize each element of the array with an Intern object. + team[0] = new Intern("Salvatore", 18, 20000); + team[1] = new Intern("Céline", 22, 3400); + team[2] = new Intern("Alex", 24, 4200); + team[3] = new Intern("Elodie", 19, 6500); + team[4] = new Intern("Rosca", 27, 1500); + team[5] = new Intern("Ahmad", 33, 15000); + team[6] = new Intern("Cesar", 45, 16000); + team[7] = new Intern("Elise", 24, 2000); + team[8] = new Intern("Tino", 50, 13000); + team[9] = new Intern("Sébastien", 26, 10000); + // Iterate through each Employee in the team array. + for (Employee member : team) { + // Print the string representation of each Employee. System.out.println(member.toString()); } - } } diff --git a/src/Employee.java b/src/Employee.java index 626c58f..74eba49 100644 --- a/src/Employee.java +++ b/src/Employee.java @@ -1,31 +1,47 @@ public class Employee { + // Private fields to store the employee's name, age, and salary. private String name; private int age; private int salary; + // Constructor to initialize the Employee object with name, age, and salary. public Employee(String name, int age, int salary) { this.name = name; this.age = age; this.salary = salary; } + // Getter method for the name field. public String getName() { return name; } + + // Setter method for the name field. public void setName(String name) { this.name = name; } - public int getAge() {return age;} - public void setAge(int age) {this.age = age;} + // Getter method for the age field. + public int getAge() { + return age; + } + + // Setter method for the age field. + public void setAge(int age) { + this.age = age; + } + // Getter method for the salary field. public int getSalary() { return salary; } + + // Setter method for the salary field. public void setSalary(int salary) { this.salary = salary; } + // Override the toString method to provide a string representation of the Employee object. @Override public String toString() { return "Employee{" + diff --git a/src/Intern.java b/src/Intern.java index 9252a25..eadd3d2 100644 --- a/src/Intern.java +++ b/src/Intern.java @@ -1,20 +1,28 @@ -public class Intern extends Employee{ - private static final int maxSalary= 20000; - public Intern(String name,int age,int salary){ - super(name,age,salary); - if(salary>maxSalary){ - throw new IllegalArgumentException("You can not set a salary that exceed "+ maxSalary + " to "+name); +public class Intern extends Employee { + // Define a constant for the maximum salary an intern can have. + private static final int maxSalary = 20000; + + // Constructor for the Intern class. + public Intern(String name, int age, int salary) { + // Call the constructor of the superclass (Employee) with the provided name, age, and salary. + super(name, age, salary); + + // Check if the provided salary exceeds the maximum allowed salary. + if (salary > maxSalary) { + // Throw an IllegalArgumentException if the salary is too high. + throw new IllegalArgumentException("You cannot set a salary that exceeds " + maxSalary + " for " + name); } } + // Method to update the salary of the intern. public void updateSalary(int newSalary) { - if(newSalary<20000){ + // Check if the new salary is less than the maximum allowed salary. + if (newSalary < 20000) { + // Update the salary using the superclass's setSalary method. super.setSalary(newSalary); - } - else{ - throw new IllegalArgumentException("You can not set a salary that exceed "+ maxSalary + " to "+super.getName()); + } else { + // Throw an IllegalArgumentException if the new salary is too high. + throw new IllegalArgumentException("You cannot set a salary that exceeds " + maxSalary + " for " + super.getName()); } } - - } From b7619684b7c33868871b7094a273d209550eb3a7 Mon Sep 17 00:00:00 2001 From: Motodies <39949690+Motodies@users.noreply.github.com> Date: Sat, 29 Mar 2025 09:26:42 +0100 Subject: [PATCH 14/17] Some optimisation and commenting --- .idea/workspace.xml | 14 ++++++++++---- src/Basics.java | 26 ++++++++++++-------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index dde1643..4f6f2fd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,9 +7,6 @@ - - -