From 8161b381319b493fe3be541ef71f7e611be4e8c6 Mon Sep 17 00:00:00 2001 From: AlvaroGA99 <55707621+AlvaroGA99@users.noreply.github.com> Date: Wed, 2 Apr 2025 17:12:53 +0200 Subject: [PATCH] Lab commit --- .idea/.gitignore | 3 ++ .idea/encodings.xml | 7 ++++ .idea/indexLayout.xml | 8 ++++ .idea/misc.xml | 14 +++++++ .idea/projectSettingsUpdater.xml | 7 ++++ .idea/vcs.xml | 7 ++++ employees.txt | 10 +++++ pom.xml | 17 ++++++++ src/main/java/Employee.java | 64 +++++++++++++++++++++++++++++++ src/main/java/Intern.java | 26 +++++++++++++ src/main/java/Main.java | 26 +++++++++++++ target/classes/Employee.class | Bin 0 -> 1911 bytes target/classes/Intern.class | Bin 0 -> 879 bytes target/classes/Main.class | Bin 0 -> 1581 bytes 14 files changed, 189 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/indexLayout.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/projectSettingsUpdater.xml create mode 100644 .idea/vcs.xml create mode 100644 employees.txt create mode 100644 pom.xml create mode 100644 src/main/java/Employee.java create mode 100644 src/main/java/Intern.java create mode 100644 src/main/java/Main.java create mode 100644 target/classes/Employee.class create mode 100644 target/classes/Intern.class create mode 100644 target/classes/Main.class diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/indexLayout.xml b/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..fdc35ea --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/projectSettingsUpdater.xml b/.idea/projectSettingsUpdater.xml new file mode 100644 index 0000000..64af657 --- /dev/null +++ b/.idea/projectSettingsUpdater.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..288b36b --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/employees.txt b/employees.txt new file mode 100644 index 0000000..7a2179c --- /dev/null +++ b/employees.txt @@ -0,0 +1,10 @@ +Employee{name='Employee0', email='employee0@example.com', age=25, salary=50000} +Employee{name='Employee1', email='employee1@example.com', age=26, salary=51000} +Employee{name='Employee2', email='employee2@example.com', age=0, salary=52000} +Employee{name='Employee3', email='employee3@example.com', age=28, salary=53000} +Employee{name='Employee4', email='employee4@example.com', age=29, salary=0} +Employee{name='Intern1', email='intern1@example.com', age=30, salary=12000} +Employee{name='Intern2', email='intern2@example.com', age=31, salary=20000} +Employee{name='Intern3', email='intern3@example.com', age=32, salary=17000} +Employee{name='Intern4', email='intern4@example.com', age=33, salary=58000} +Employee{name='Intern5', email='intern5example.com', age=34, salary=59000} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b4114fe --- /dev/null +++ b/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + lab-java-standard-input-and-classes + 1.0-SNAPSHOT + + + 21 + 21 + UTF-8 + + + \ No newline at end of file diff --git a/src/main/java/Employee.java b/src/main/java/Employee.java new file mode 100644 index 0000000..78de644 --- /dev/null +++ b/src/main/java/Employee.java @@ -0,0 +1,64 @@ +public class Employee { + private String name; + private String email; + private int age; + protected int salary; + + public Employee(String name, String email, int age, int salary) { + setName(name); + setEmail(email); + setSalary(salary); + setAge(age); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + if(age < 0){ + this.age = 0; + }else{ + this.age = age; + } + + } + + public int getSalary() { + return salary; + } + + public void setSalary(int salary) { + if(salary < 0){ + this.salary = 0; + }else{ + this.salary = salary; + } + } + + @Override + public String toString() { + return "Employee{" + + "name='" + name + '\'' + + ", email='" + email + '\'' + + ", age=" + age + + ", salary=" + salary + + '}' + "\n"; + } +} diff --git a/src/main/java/Intern.java b/src/main/java/Intern.java new file mode 100644 index 0000000..a2982e2 --- /dev/null +++ b/src/main/java/Intern.java @@ -0,0 +1,26 @@ +import java.sql.SQLOutput; + +public class Intern extends Employee { + + private final int MAX_SALARY = 20000; + + public Intern(String name, String email, int age, int salary) { + + super(name, email, age, salary); + if(salary > MAX_SALARY){ + System.out.println("Intern salary cannot exceed " + MAX_SALARY); + this.salary = MAX_SALARY; + } + } + + @Override + public void setSalary(int salary) { + + if (salary > MAX_SALARY){ + System.out.println("Intern salary cannot exceed " + MAX_SALARY); + this.salary = MAX_SALARY; + } else { + super.setSalary(salary); + } + } +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..9ff9122 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,26 @@ +import java.io.FileWriter; +import java.io.IOException; + +public class Main { + public static void main(String[] args) throws IOException { + try { + FileWriter writer = new FileWriter("employees.txt"); + + //generate 10 employees without for loop + writer.write(new Employee("Employee0", "employee0@example.com", 25, 50000).toString()); + writer.write(new Employee("Employee1", "employee1@example.com", 26, 51000).toString()); + writer.write(new Employee("Employee2", "employee2@example.com", -9, 52000).toString()); + writer.write(new Employee("Employee3", "employee3@example.com", 28, 53000).toString()); + writer.write(new Employee("Employee4", "employee4@example.com", 29, -100).toString()); + writer.write(new Intern("Intern1", "intern1@example.com", 30, 12000).toString()); + writer.write(new Intern("Intern2", "intern2@example.com", 31, 56000).toString()); + writer.write(new Intern("Intern3", "intern3@example.com", 32, 17000).toString()); + writer.write(new Employee("Intern4", "intern4@example.com", 33, 58000).toString()); + writer.write(new Employee("Intern5", "intern5example.com", 34, 59000).toString()); + + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/target/classes/Employee.class b/target/classes/Employee.class new file mode 100644 index 0000000000000000000000000000000000000000..bbad3639dbce083792d93e6fc776cd16a421fee4 GIT binary patch literal 1911 zcma)-U2hXd6o%iio%IJB0wy0#3?YO-oQ=VJl(rBO2yRj=8MrVC7wyf&SvgDAyOwu@ z6jhb_GkVec-t?lCN-A;DAJ89F^_|&uV(bk<*6z%nIWy;(^PU<1``?Fu0BquU0V$-j z$e0*|A#mZXd?%}}^xD-|yKn7QC}2ExJSW@`NS9Z33dkX!MZv^5m;$-2PS^F1Y+E23 z*x^grVQ;G3I9;U~_8hOh7R@|wVnR=&?^Z`Tu3GM*i6Slu1 zMdswDiDi@pW;*h~uK8X|hHsp3pS>WIUKj{GO4#2hM7_Q;Y7|)c+{ruKVa?wo>O{lw z?3ag~UAy;M?z*%T8-7c=JF@4f@7S0L_Z`v|8huUHC`!98%49haCr1aZ1arVHQ>=Ba z3ye2I**bV3yYcdQ4)^8Bg?^+f!!`ZGUd!Hg6xVn^^leoDtfpta9|mDhc3;@xzP}gb zK&Wcp>qn*F`m$KAENGRYF6CJlm4!%=b@5YS!oYd~8+ek%Qzg!(z|v`fIo><}z^+C- zkzU)f75b`-ei=-5>==z-%#YOV|dJILZ&fg2-xN~6^YP2#iID;)X_v*_Y_Zt<5k>=X{v0M|Csd` zX8vF&3T$ZOgbrdx4sj5nZYNsQRyOFZLKxQSd(50-tBVh~M7T-4!gSkA3v>|*UHZV5#V62OYU4MI328JTp~Q$G`pHb`1XuS#U@`K4O!TWJ z+Qbk30DqKvcDK=1-N($mcjlgR=HB`KHD^4 z2M+|Ajs7e7Mz$U4P1?g?W_y#)zmZwL; zA6V+`SgBL%@PJPa6|C#nFtCX&fpSE08A?E(hQJObn*TXue4wiawxiR;Tw%d#1}xMC zvU3#-BLxClg9Q-CANk%qkX|s7&O#-DfyK2W|CALi^leWK7Ve3fJ(VX8Bc;ASmd;4d z?9e|CYQal;&Q|o}Gj^EoNjKVkp;B=l1X9YCw!@Oi3Af~jfgHa+meUAJNBeSlqa^lY z=r3kt^~er2ti&|?AvWslV1hS;(!w5czD6&B>-@=uG{+l^e4w4;+-U9YZJXK|L~C_m zeTHsooZq4J3Heg_3(PoN{m8vZ+~l}L3?R!lg(7m;Adf|++q@LFxN*wQ3~N{7d9}WLniT s?EDd1iNutl6TASES7{wP97Ca%80xpsS|mk8QZytsHIg21Ujlc30Ru#)EdT%j literal 0 HcmV?d00001 diff --git a/target/classes/Main.class b/target/classes/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..ab28847ba3a831340b6ab23f358d70e4ae493fd8 GIT binary patch literal 1581 zcmZuxOLG%P5dOxNy`x3O>oIothq zzyW>$SBkSQR#luzQk4T$R3J$6CtnBqlMyj3J>HhlbZ+d$6>3=`} z3g8k}bTpt*LnMYKG&2}0=4~@wH0`DIWPU{!Jcj18mTh_G85$GGISrga_#n$kU$KgE z-nBgGa_9^#vb0)s?n=3q^2(kL4KYRA!qAb(?h?;TcJPN@<2V@k(qYZ#_u%-D2JHpeJ~R(+=pe8$jj`HmX-I)>1xh8~VH0iJenF2L98 zfA%}a#Q;j`#{y`Lc8)Is6p6kPplT%35x;oAkqMxq9N$pqRke=RHp4$Ut?J-C2bqv00~J7UxXYQtNGF#9Ox3=rpn_m`WQd z`6Qi*g}n`!Bni!acXWcDGb-$^{l+=`}82T_z-wX9?096{zH0EfPrkT;)bi4w#;k$pJQMrK#7HEuB z0r(NuXcfhE+#nJPX7}ju6zRJyXgLwBU|+U>3;T1z5W?sY2P){;ME52RR;@=wpV2Em ztg{{y9~*B(qRyHW{l-CYqRyHU1I8iaVc0s96C>iJakwq@yn<7k_`I5q%%{a!;F4uQFP3pZt%|hF>7?H`?(pI`9(R#L$V?=)zm{_*IV+ upN