From 74e421aa7e840b7377e20e6403eb1c0f7614c9ae Mon Sep 17 00:00:00 2001 From: Kilokem Date: Tue, 17 Sep 2024 08:44:32 +0200 Subject: [PATCH] Encapsulation --- .../src/main/java/com/oop/Main.java | 7 ++++- .../src/main/java/com/oop/Pupil.java | 29 ++++++++++++++++++ .../target/classes/com/oop/Main.class | Bin 532 -> 706 bytes .../target/classes/com/oop/Pupil.class | Bin 0 -> 678 bytes 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 more_on_classes/src/main/java/com/oop/Pupil.java create mode 100644 more_on_classes/target/classes/com/oop/Pupil.class diff --git a/more_on_classes/src/main/java/com/oop/Main.java b/more_on_classes/src/main/java/com/oop/Main.java index 486ef65..11d7473 100644 --- a/more_on_classes/src/main/java/com/oop/Main.java +++ b/more_on_classes/src/main/java/com/oop/Main.java @@ -1,7 +1,12 @@ package com.oop; +import java.util.Scanner; public class Main { public static void main(String[] args) { - System.out.println("Hello world!"); + Scanner read = new Scanner(System.in); + int a = read.nextInt(); + + Pupil pupil = new Pupil(); + pupil.setAge(a); } } \ No newline at end of file diff --git a/more_on_classes/src/main/java/com/oop/Pupil.java b/more_on_classes/src/main/java/com/oop/Pupil.java new file mode 100644 index 0000000..ec48f99 --- /dev/null +++ b/more_on_classes/src/main/java/com/oop/Pupil.java @@ -0,0 +1,29 @@ +package com.oop; + // You need a program to manage admissions for an art school. Pupils can be admitted to the school if they are over 6 years of age. + // You're given a program which declares a Pupil class. + // Task + // Complete the setAge method of the Pupil class. If the value of parameter a is over 6, assign it to age attribute and output "Welcome". + // Output "Sorry" otherwise. + // Sample Input + // 7 + // Sample Output + // Welcome + + +public class Pupil { + private int age; + + //complete setter method + public void setAge(int a){ + if (a > 6) { + age = a; + System.out.println("Welcome"); + }else{ + System.out.println("Sorry"); + } + } + + public int getAge(){ + return age; + } +} diff --git a/more_on_classes/target/classes/com/oop/Main.class b/more_on_classes/target/classes/com/oop/Main.class index 652456af62af0b1c30d9ea5963e419cfa1e5b1bc..793f48e238ff5f32168dc4d48b6486ef234f8a57 100644 GIT binary patch delta 447 zcmZut%TB^j5IqCMrlm*`K~x@sFCJpuBMTEYO^6{OF=1J;AvMr8P>8Ph27~|LS{IN= z;=-jLWt_rB6BqZ)otZP|Wae4;49Q>L?;il_xOkFZrXpg5*u60^w6SOPwRYFAZF49g zj)aJ9g1YMU4ZEkcA4i@!P>{q9Az;~rM03@(98I^~vDfy7rZK3=P_e5Zggrv4_%Ee& zupfvxWd@wMIWU1|g}`00d@>x&Vh%|Gh1TWU=Og!wEAh%v-5!coE|qFfRAKS2-z z$Ltbn=M7s6q?(mE_UlXJIt%2ltLZrkugnNQW=ygQu)(S#uPPzM)eL98OL?t?6P$7u c=3^HND6x^shGkS(BE_R;sIn>HoJj#_KfXIttN;K2 delta 265 zcmX@aI)#Pn)W2Q(7#J9A8I&e+E$8555M&T$XAqirL9||kL6nh!Ilr`okwMfaE3qt5 zKQmuHpeQr1B)Fs~H8IzkgF&2;fyW~?CnsN_JijO>MUjg^l0llCL5h(<7>foT1{nrf zMh5l*kQq67Kw~u^=H?{krRxI?&CE-;)(m50U`Z@WFP>b>C^7j8qi+&312@otJPeFL zk`+kv0%=YLJ_dfE2s@B%&cFng+Me zE0|=lOr|o|W?vmT#T&gc=nL{=@~>3!#E3bA0W2yNv_i(Dsm+k<2w2R-fNXmj&^Th-@_iMFTwh_jRS(0=6aHnaj>B* z10kPI=i}kDjzfW3l;!z3gOLm}DrEfjxm;Egy7Ouf2F2W(QMS%w^-P;cnq}Azj5-cD zqRj^pu*{t7Z1&8OwZUD;RdB71exUi8jRl|8Ef3phv-dXuT)`H1ObAz5&E?67vxxc@(~f`<47Z?_UvoBIJMX{Y$+MO4RT#R=ab@ literal 0 HcmV?d00001