From fa1a7f60cb17628d67b24d9d509bf1f35a4ad41e Mon Sep 17 00:00:00 2001 From: vinayak Date: Tue, 30 Aug 2022 13:54:37 +0530 Subject: [PATCH 1/7] problem statement 2(java core) --- .idea/vcs.xml | 6 + .../Assignment1/com/company/Circle.class | Bin 0 -> 618 bytes .../Assignment1/com/company/Cylinder.class | Bin 0 -> 774 bytes .../Assignment1/com/company/Main.class | Bin 0 -> 3412 bytes .../Assignment1/com/company/Rectangle.class | Bin 0 -> 626 bytes .../Assignment1/com/company/Sphere.class | Bin 0 -> 747 bytes .../Assignment1/com/company/Square.class | Bin 0 -> 584 bytes .../Assignment1/com/company/Triangle.class | Bin 0 -> 800 bytes src/com/company/Main.java | 178 +++++++++++++++++- 9 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 .idea/vcs.xml create mode 100644 out/production/Assignment1/com/company/Circle.class create mode 100644 out/production/Assignment1/com/company/Cylinder.class create mode 100644 out/production/Assignment1/com/company/Main.class create mode 100644 out/production/Assignment1/com/company/Rectangle.class create mode 100644 out/production/Assignment1/com/company/Sphere.class create mode 100644 out/production/Assignment1/com/company/Square.class create mode 100644 out/production/Assignment1/com/company/Triangle.class diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Assignment1/com/company/Circle.class b/out/production/Assignment1/com/company/Circle.class new file mode 100644 index 0000000000000000000000000000000000000000..74d95bd49fa80186a57f812fbcb75222427d6d73 GIT binary patch literal 618 zcmZvY+fKqj5QhH+X{EM;f_N5>iF#pgywe~aqY0jZ;eM$bUG0ICV&VfBpGPm$c;N&1 zD!zkpwh+{4)9KFqGxN=C-#=g90IXucKpG=yjABeHr>9;{KkkYK#xbFlN86E(NgY!R z+Pd^*RANXjF4Y)%wu5uQkf}&t9JRc<2+w%kC1tP@INYuAP^!2i_C%Mm$&jx&foGF7 zxPNPJ%g}Mf8iPd*PRr$y*bD_H_TqsW!9ubFB6ia!B9xwp1SO1W&(m#B9mW)<4?T~-!3*eAT6l4Rm0wRCovd|p-B-)u~*(qmx&DQAF}M4^Z^Xd z0~cVt@Bw@k-+_2$w;46*CTHi&nR9;UJ2SuTfBXdS8m@&ZR;pOVV`FD|?fcR1Z*2=} zXd64#VrQabVx7U*mXS=~GL+ozkfFRAp9qFpUq<3%7LG)6%trx57W%QzgCS3(+E0Sz z^i*ClH2Z!WdSn+o8hg9rKt?AbdBZSAC4Lt0RJ=RGO;$Tt-`G{42L%Vb;WkjVE|&;+c(2JZET3)5TC% zC0@XzFW$lEO!(=4p~3hv6(Lg2ia*0diPqK) zW*R81T%E68ofi)I{w*qhi58Io7t848)J{>UsVz8Y0bFp0 A1poj5 literal 0 HcmV?d00001 diff --git a/out/production/Assignment1/com/company/Main.class b/out/production/Assignment1/com/company/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..8694f857452529fc4f632b2c964f2bd113d3b922 GIT binary patch literal 3412 zcmb7GTW}NS89o16(yoQTSjJ$WZ4^j}AO?pv5iJl%VnU6t)&HNS6Qt9 zhmhdhNk|+5386qBS0#|<0*Tz#oxWuHkiN8eVkR$n=w$lPhd%VBbf%%_-<9O+bf%u! z%l}=@cRTx8fBN=!e*kbBejCOn~of2v^=p8uo{A00&hJhcO2^ z4G(KLq~Q^1e^{D4s^KxIIwEf)8Xnj1goYlK3|fz;~HL8aUzVkl%Le_ihQL@T&iA`&r=#+Q*kPQ&Xe&a1c}5ZY*3rn^a?A-=LtAkb;24S}XE(=xV|@`Hx6OCQWp z678~6dah4*OnI&f18&wVN?pp%ckn9c)^JC+Zdx0Nl;=}mVf_BCz50H=Bd1%Lj$YR> zt;_})DU>zLOx6_;Ng5C8MFtT%uR&fZUQ{id0=$c{txV1!c%xk~9Njf-Mu^VDr?(@p zXo~kvBjwiIMNVMB6m9QACEbz8Q$uzR=S(YYI8=!2be~SsNqN}__Fx)ZA!~SWN|B|s z_!*X5GuP3Z(k;sa3>LF`fkg*&CqsaiS^6X}x7XEE`?~dl*KrjCWTlEX$UqW_gdsOL zdrn#)+-sMdl(E&6<7$*sSR)%B!Dig4;>`%&!rKD#?y+3MiFvVO>tib3iQrw71)9An zP0lfb_wc@SzZk(Kd?284dR_~eK?J|Xhb(*Y^ zUoFBh^fYsl6@Dsn{|s07NfbR6lG2m$d}@*kzN^f>>Nh6+#yFQ$m8R3?QDbjC5l2s( zrJ~pTYHHQ4%hW=BcCM5+BKVD$OUh&Sv|N13)3(X55RkvUC(Capqg0<^8_MA*p+Z+TkAL8h}HzH%lm(>FNXTrruk zY{%&I_T8)r>=p=mDKb?Fn6!w=?aVbfH)FV4$Zo61&BvV)j3<*a@LaCuR4J#s#$7C3 zPNjC{HGL&dT1%Yt{`!6Fj2DR&!3bgL_Xk!K8(>OMc zIsIdZY?Fp_X(+Yp1B(OEd7l0jDQ~J^KIP4cpgcuur_k!wU~8y?memz3phv6cu}<17 z^pUC_i)yEk)V0-4s^{OTRX&Fh+@76rMJib>uh3eVPt7ddV z8Ljn%=2V5TvN+Qoz0nKOJ&t7zvV4{xH`QQ+b=U|ID)@dGEp^aFPqd;e?ro3W>_Ix? zh!b+GUD|Re$>@|DQmnKwNg6D_)B~A)>__oa_Zzmpj79Cy4PKN`8S`X6HnJb( z|MW|WH-Hou7VhW!Pf6gPp#@!NLpQ&YZCHsO{>Ivlb=X0Y??e*4lTBe(u~u}5}Z+P!dYb%URPG*ypq5LWfR^|w&G2t3vVgA@V2rW?mmbb-9e;~&=Uf8p>JHAPm$EO2?8~m=cFswn ze1n^P6n1hm?e0SZdnu<%Uv_i3Z^z!H8KaNd5#D|6D6^AO53+;nIcw&}K5eGmFKBnI zhQeMg_wCr3o#exAG_W^Yd=z#k;cL;NoFq#g;L2=MMp^R?ZeXrVvSon$+r#SuYral) z1XbuN234d~q}8$`_Wc(qnJQHP literal 0 HcmV?d00001 diff --git a/out/production/Assignment1/com/company/Rectangle.class b/out/production/Assignment1/com/company/Rectangle.class new file mode 100644 index 0000000000000000000000000000000000000000..bbb22d764fccd53bef757da8b811615ff3a30447 GIT binary patch literal 626 zcmZvZOH0E*6ot>Ujj^#tt=3oTb5&iKjXOmUK`2BmR$M!cgB{63Vk-1!=|aJUKfoU) zo~b1&bl_%gZq9u7%+2T5`v-u1Y&)<}D`OE$4wkWEW7S4oVB%26Iy(|5Hg~QCN+-#! z5}5IItj_yUSEX078?sXMlR$>oGS%jNR4ipZ{V1^H2T9~H9%MZ5E>)1p_%2ij0@FMb z^h24c<5WojtJ!LqHX>xS7+sQcOovj3|sbu_kXs8zs)ytRjOZAu!3z<1V;cyKfNBObRFu1*W(NhtJB708`A&nua?% z>=R~i&I=0lM(-8HUxGst_#?|$8B#WXlsU!03}%O92XoAfx|);Qv}?#N$yU8*HF`H= X=yiH&{Gq!!-OcIlh|WQgSHQwIPbqA< literal 0 HcmV?d00001 diff --git a/out/production/Assignment1/com/company/Sphere.class b/out/production/Assignment1/com/company/Sphere.class new file mode 100644 index 0000000000000000000000000000000000000000..2bee392df38206427ece40353c18820737f04bec GIT binary patch literal 747 zcmZvZ+fLg+5QhH^iA^lKNg)tUmH zgeRaE1#!Ux@B)1Zu6v7^bu5>vvAnyp|IBC0%7VW3uTGvr?fUj##`DSh!V_BtZ` z%sVbAL(Rb9ZkvZv?Nc!y?aO0^O4A8En?{%WCw8m5FG8`wU{Qh-yF3!xq2R=>?Whtg zq_IQ9%)KW<>4`{?qm+s5z>PgBY_x(nbi_NUx+s3&(qBH{-?)hfDCt-*v4|%+o|>qk zuAu*Q!cbNTw#)sm_HO4uIMF{+>*P2R9$i2XlVhZr1k1qQ3#A{mB5K{E!wmP48T76S za(#8UH}y8%xk*ouoAJ3?7Q>v9vwf@K#)Yj@f rq?IA93^|b@cT;3FK@RpBrMUv5U%zXVxPA{_&EVA(&M-;m&SB~fejSIw literal 0 HcmV?d00001 diff --git a/out/production/Assignment1/com/company/Square.class b/out/production/Assignment1/com/company/Square.class new file mode 100644 index 0000000000000000000000000000000000000000..c5904975f53a2f32087e8ed4ab0b8b1005901463 GIT binary patch literal 584 zcmaKoOH0E*5Xb-9S8Pll+J}#7t>~e8Fc)u%pn_0{T8Q+%jf>rqM@C5PhA>BUcF=Q@- zd%;k$q%Uq_uP?$o-gik^wE~B`JswJRpNW}hAjb?<%LzP_Y{dPEX+Oq16ekP?DsW<# zN8&sboY?J-YQbEx4iV?!t_YB~@71*XgW2lKW+6i)O@vM1w6c=X&Lra;X~l4W3aL+M9$M1y)XdS!vkpp8_L z>!XDX{ia%JG8zpGOXQh!GCH$|Z(z^lq>xV%l-Pt$yD?3`GI?qhP@ENC5G+NC{(@Aa sF?dD#hoC2s7SVPSN`0C+r|2l5oRC)*^0bA#J>u>E%cC!*iBhP11F1x3MF0Q* literal 0 HcmV?d00001 diff --git a/out/production/Assignment1/com/company/Triangle.class b/out/production/Assignment1/com/company/Triangle.class new file mode 100644 index 0000000000000000000000000000000000000000..c572a3e3d5318868bdce3cbe64c638625a2aa0f0 GIT binary patch literal 800 zcmZvZ%Wl&^7=_Q|X6y`2NYZji3Wah>4Z<6CAOr#-MG8=qs$$uRJBp`r?81CCRboCOE8B$HUb6u3Uo`Fk_f$;_k)jn)2OV7rKjW6X0#hVxkE`fa8a zn-t&sI%8d~GZM0BSw)8k1-wx@&qDpdST6UYGRgB3^-W3CAtkQCmGIy?cr5V*eFu9I zKAsA6)=>&HZE+BjIruz2(IMaGiZnW#<$B8JN#{J+94^cz4fZpWgXO$HF>0%SF`A(q2T>(IJzKuVa%tOS@IDy`kHl zwSJ)DpR>U^%274`iRxt+Z&A}ATJs8QtLShOw^p!UnP%@Unbz$cZ6B@4X_KR~$nlrn WB1hu(ic}V)5_hOs#x8S9==}!?e19zf literal 0 HcmV?d00001 diff --git a/src/com/company/Main.java b/src/com/company/Main.java index d9d1a8b..6afe9e8 100644 --- a/src/com/company/Main.java +++ b/src/com/company/Main.java @@ -1,8 +1,184 @@ package com.company; +import java.util.*; + +class Triangle{ + int height; + int base; + + void getDimensions(int h , int b){ + height = h; + base = b; + } + + void calculateArea(){ + System.out.println((height*base)/2); + } + + void calculatePerimeter(int a , int b , int c){ + System.out.println(a+b+c); + } +} +class Rectangle{ + void calculateArea(int l , int b){ + System.out.println(l*b); + } + void calculatePerimeter(int l , int b){ + System.out.println(2*l + 2*b); + } +} +class Square{ + void calculateArea(int l ){ + System.out.println(l*l); + } + void calculatePerimeter(int l){ + System.out.println(4*l); + } +} +class Cylinder{ + void calculateArea(int r, int h ){ + System.out.println(2*3.14*r*h+ 2*3.14*r*r); + } + void calculatePerimeter(int r ){ + System.out.println((2*3.14*r*r)); + } + void calculateVolume(int r , int h ){ + System.out.println(3.14 * r*r*h); + } +} +class Sphere{ + void calculateArea(int r ){ + System.out.println(4*3.14*r*r); + } + void calculatePerimeter(int r ){ + System.out.println((2*3.14*r)); + } + void calculateVolume(int r ){ + System.out.println(3.14 * r*r*r * 1.34); + } +} +class Circle{ + void calculateArea(int r){ + System.out.println(3.14*r*r); + } + void calculatePerimeter(int r){ + System.out.println((2*3.14*r)); + } +} public class Main { public static void main(String[] args) { - // write your code here + // write your code here + while (true) + { + System.out.println("Enter shape : "); + Scanner sc = new Scanner(System.in); + String shape = sc.next(); + if (shape.equalsIgnoreCase( "triangle")){ + Triangle t = new Triangle(); + System.out.println("Enter Operation to be performed : "); + String operation = sc.next(); + if (operation.equalsIgnoreCase("area")){ + System.out.print("Enter height of Triangle : "); + int height = sc.nextInt(); + System.out.print("Enter base of Triangle : "); + int base = sc.nextInt(); + t.getDimensions(height, base); + t.calculateArea(); + } + if (operation.equalsIgnoreCase("perimeter")){ + System.out.println("Enter length of first side"); + int a = sc.nextInt(); + System.out.println("Enter length of second side"); + int b = sc.nextInt(); + System.out.println("Enter length of third side"); + int c = sc.nextInt(); + t.calculatePerimeter(a,b,c); + } + + } + else if (shape.equalsIgnoreCase("rectangle")){ + Rectangle r = new Rectangle(); + System.out.println("Enter Operation to be performed : "); + String operation = sc.next(); + System.out.println("Enter length : "); + int l = sc.nextInt(); + System.out.println("Enter breadth : "); + int b = sc.nextInt(); + if (operation.equalsIgnoreCase("area")){ + r.calculateArea(l,b); + } + else if (operation.equalsIgnoreCase("perimeter")){ + r.calculatePerimeter(l,b); + } + } + else if (shape.equalsIgnoreCase("square")){ + Square r = new Square(); + System.out.println("Enter Operation to be performed : "); + String operation = sc.next(); + System.out.println("Enter side : "); + int l = sc.nextInt(); + if (operation.equalsIgnoreCase("area")){ + r.calculateArea(l); + } + else if (operation.equalsIgnoreCase("perimeter")){ + r.calculatePerimeter(l); + } + } + else if (shape.equalsIgnoreCase("cylinder")){ + Cylinder c = new Cylinder(); + System.out.println("Enter Operation to be performed : "); + String operation = sc.next(); + System.out.println("Enter radius : "); + int r = sc.nextInt(); + System.out.println("Enter height : "); + int h = sc.nextInt(); + if (operation.equalsIgnoreCase("area")){ + c.calculateArea(r,h); + } + else if (operation.equalsIgnoreCase("perimeter")){ + c.calculatePerimeter(r); + } + else if (operation.equalsIgnoreCase("Volume")){ + c.calculateVolume(r,h); + } + } + else if (shape.equalsIgnoreCase("circle")){ + Circle c = new Circle(); + System.out.println("Enter Operation to be performed : "); + String operation = sc.next(); + System.out.println("Enter radius : "); + int r = sc.nextInt(); + if (operation.equalsIgnoreCase("area")){ + c.calculateArea(r); + } + else if (operation.equalsIgnoreCase("perimeter")) { + c.calculatePerimeter(r); + } + } + else if (shape.equalsIgnoreCase("Sphere")){ + Sphere s = new Sphere(); + System.out.println("Enter Operation to be performed : "); + String operation = sc.next(); + System.out.println("Enter radius : "); + int r = sc.nextInt(); + if (operation.equalsIgnoreCase("area")){ + s.calculateArea(r); + } + else if (operation.equalsIgnoreCase("perimeter")) { + s.calculatePerimeter(r); + } + else if (operation.equalsIgnoreCase("Volume")) { + s.calculateVolume(r); + } + } + else if (shape.equalsIgnoreCase("done")){ + break; + } + else{ + System.out.println("shape not found"); + } + + } } } From 2545336a53f99b097e56b627e9fd2c2d531edb71 Mon Sep 17 00:00:00 2001 From: vinayak Date: Thu, 1 Sep 2022 15:10:16 +0530 Subject: [PATCH 2/7] derived path remaining --- .../com/company/Problem_statement_1.class | Bin 0 -> 2531 bytes src/com/company/Problem_statement_1.java | 49 ++++++++++++++++++ url.txt | 1 + words.txt | 3 ++ 4 files changed, 53 insertions(+) create mode 100644 out/production/Assignment1/com/company/Problem_statement_1.class create mode 100644 src/com/company/Problem_statement_1.java create mode 100644 url.txt create mode 100644 words.txt diff --git a/out/production/Assignment1/com/company/Problem_statement_1.class b/out/production/Assignment1/com/company/Problem_statement_1.class new file mode 100644 index 0000000000000000000000000000000000000000..9d43ffbd9373ed8893e95c07a9bde0bab137349f GIT binary patch literal 2531 zcmah~TW}Lq82(Ok*>t<%4&=j=~+ zzqtcoH*TodfpG;B3QqX&vI-Ys3Qnr<;*<}s$oHfiPAiyFQ74tt3UoQ0QBjY$3O^EZ zFnpNxVNOL2&d4EIi+P+?kW$f#aUat1ZTeuzcgBZT%P4sT=TvONc?Am! zE(mz{CC#M0U%=JTIU(RaWF-uNhQXw14Cm7`Ms`e}Nl_9QwBmYdLeD1Ux+HYlXOcOA zErW3@9p;nK%?sh9S&J6wshq9bM%pm#ss6omoYs@3KugD|!Fm0h9!}}zTzJ&ZCe69M zGO#ym>N>Ru7U(NvJn5Mt;f#}=@|!R z1p}lGDdTWx%Ap4nRY$FSHg3qYSYQ><`y`GU+R-7<_#mbNnj!_@j7p16S<=0Yj|D58@OC{RzjU!F8jV8Zh=r)F(6TA`wcx^Y=wq5@s^D7 zwjAEka7Fr6_MJMtf3l18godlQrr}+@r{KDV_wj+iddFP_l@8{UDfX3wIl(mBG<=AU z*u=Iodalii$MadX-jRMx`n1`}w2{;B2`(%6RKsVusNr)7SM$9zR~x6{3#r=tKUBXD z>yepxBTm`|JBn1O$kZWyQ%PQ?mplk{%yrmUC{dE9@}z*zyeC-K(Ye+a*uSJCg^b(0swy20DfO{KiQ?%{vqmPR$BhH2l)#=U6|K#yYO0=GCY2;8 z?NwZKRy`Ay?7fiVrNZ0F%1c~}Az9{8UL++xu}rU?Ash*T-fA({x(!xlWo4}$#FfFPiQV<%T(zDaX< zx|SerJL)cuUPq{)n{%ybfFAU6Rf|4n6F0l&;Xwcpv)*q}Gq?;_EZ|;(XJ{GTSkDra zVMpYnDC(B75VcCwwfq%1*;`j+93 zEu%gb@)gjqgvKQ_MQdG=I#)zA&Anmb7K@?q5V=>mqzZJq2vP%|3XGEo10QqxgZV~T%{9i} zORb6p{7#R%SluQ3hNn4`7yqx=&zT<$Vi?chSrWQc9L51w>cTb=#UaYv%q)!ODD$9S z^x!aec$u#oNANs%kh4T(farNBeUUSPm$>>8%8E=(!JzXWQZTGQjyxnSE6l&Xib}zV of};wKL9jBcVC>;$v@aQ6{f|&9Jb^XENDvB+yP4l8^Q*zwzs{CLU;qFB literal 0 HcmV?d00001 diff --git a/src/com/company/Problem_statement_1.java b/src/com/company/Problem_statement_1.java new file mode 100644 index 0000000..d050579 --- /dev/null +++ b/src/com/company/Problem_statement_1.java @@ -0,0 +1,49 @@ +package com.company; +import java.io.*; +import java.util.Scanner; +import java.net.*; + + +public class Problem_statement_1 { + public static void main(String[] args) { + String[] a = new String[3]; + try { + File obj1 = new File("url.txt"); + Scanner r = new Scanner(obj1); + File f = new File("words.txt"); + Scanner sc = new Scanner(f); + int j=0; + while (sc.hasNextLine()){ +// System.out.println(sc.nextLine()); + a[j] = sc.nextLine(); + j+=1; + } + while (r.hasNextLine()) { + String data = r.nextLine(); + URL x = new URL(data); + BufferedReader in = new BufferedReader(new InputStreamReader(x.openStream())); + String inputLine; + + int v=0,w=0,y=0; + while ((inputLine = in.readLine()) != null) { + String result = inputLine.replaceAll("<[^>]*>", ""); + int count = (result.split(a[0]).length) - 1; + int count1 = (result.split(a[1]).length) - 1; + int count2 = (result.split(a[2]).length) - 1; + v += count; + w += count1; + y += count2; + } + System.out.println("Word "+a[0]+" has occurred "+v+" times"); + System.out.println("Word "+a[1]+" has occurred "+w+" times"); + System.out.println("Word "+a[2]+" has occurred "+y+" times"); + + in.close(); + } + r.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/url.txt b/url.txt new file mode 100644 index 0000000..f4c4ce9 --- /dev/null +++ b/url.txt @@ -0,0 +1 @@ +https://docs.oracle.com/en/java/ diff --git a/words.txt b/words.txt new file mode 100644 index 0000000..7a5aaf4 --- /dev/null +++ b/words.txt @@ -0,0 +1,3 @@ +Java +Oracle +information From ffb6c1c452c6c49c06c486896a7a0eb81b1d68e6 Mon Sep 17 00:00:00 2001 From: vinayak Date: Thu, 1 Sep 2022 15:28:07 +0530 Subject: [PATCH 3/7] Completed but doubtful --- .../Problem_statement_4_OverdrawnDemo.java | 39 ++++++++++++++++ ...Problem_statement_4_OverdrawnSafeDemo.java | 46 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/com/company/Problem_statement_4_OverdrawnDemo.java create mode 100644 src/com/company/Problem_statement_4_OverdrawnSafeDemo.java diff --git a/src/com/company/Problem_statement_4_OverdrawnDemo.java b/src/com/company/Problem_statement_4_OverdrawnDemo.java new file mode 100644 index 0000000..ce847a5 --- /dev/null +++ b/src/com/company/Problem_statement_4_OverdrawnDemo.java @@ -0,0 +1,39 @@ +package com.company; + +class Accountt extends Thread { + String name; + int balance = 1000; + int getBalance(){ + return balance; + } + public void run(){ + int i =0; + while(i<5){ + balance = balance - 100; + System.out.println("b"+balance); + i+=1; + } + + } +} + +class AccountOverdrawDemo1 { + public void main() { + Accountt boy1 = new Accountt(); + boy1.name = "vin"; + boy1.run(); + boy1.start(); + + for(int i =0 ; i<5;i++){ + boy1.balance = boy1.balance-100; + System.out.println("a"+boy1.balance); + } + } +} +public class Problem_statement_4_OverdrawnDemo { + public static void main(String[] args) { + AccountOverdrawDemo1 acc = new AccountOverdrawDemo1(); +// AccountOverdrawDemo1 acc = new AccountOverdrawDemo1(); + acc.main(); + } +} diff --git a/src/com/company/Problem_statement_4_OverdrawnSafeDemo.java b/src/com/company/Problem_statement_4_OverdrawnSafeDemo.java new file mode 100644 index 0000000..79de589 --- /dev/null +++ b/src/com/company/Problem_statement_4_OverdrawnSafeDemo.java @@ -0,0 +1,46 @@ +package com.company; + +class Account{ + int balance = 1000; + void withdraw(String s , int b){ + if (balance >= b){ + balance = balance - b; + System.out.println(s +" withdrew "+b+" amount of money"); + System.out.println("New balance " + balance); + } + else{ + System.out.println("Not enough money"); + } + } +} + +class AccountOverdrawSafeDemo extends Thread{ + Account ac; + String name; + int balance; + AccountOverdrawSafeDemo(Account ob, String n, int b) + { + ac = ob; + name = n; + balance = b; + } + + public void run(){ + ac.withdraw(name, balance); + } +} + +public class Problem_statement_4_OverdrawnSafeDemo { + public static void main(String[] args) { + Account acc = new Account(); + for (int i =0 ;i<5;i++){ + AccountOverdrawSafeDemo a = new AccountOverdrawSafeDemo(acc, "a", 100); + a.start(); + } + for (int i =0 ;i<5;i++){ + AccountOverdrawSafeDemo b = new AccountOverdrawSafeDemo(acc, "b", 100); + b.start(); + } + } + +} From 4b3064e7b50970e58f8b64eed6675d1af929a5af Mon Sep 17 00:00:00 2001 From: vinayak Date: Fri, 2 Sep 2022 12:53:17 +0530 Subject: [PATCH 4/7] completed serialisation deserialisation --- src/com/company/Problem_statement_5.java | 76 ++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/com/company/Problem_statement_5.java diff --git a/src/com/company/Problem_statement_5.java b/src/com/company/Problem_statement_5.java new file mode 100644 index 0000000..fcb8922 --- /dev/null +++ b/src/com/company/Problem_statement_5.java @@ -0,0 +1,76 @@ +package com.company; + +import java.io.*; + +class Student implements Serializable { + String firstname; + String dob; + Address address; + public Student(String firstname, String dob,Address address) { + this.firstname = firstname; + this.address = address; + this.dob = dob; + } + @Override + public String toString() { + return " Student First Name = " +firstname + "\n DOB = " + dob + "\n Address =" + address + "\n\n" ; + } +} + +class Address implements Serializable { + String city; + String state; + int pincode; + String country; + + + public Address(String city, String state, int pincode, String country) { + this.city = city; + this.state = state; + this.pincode = pincode; + this.country = country; + } +} +public class Problem_statement_5 { + public static void main(String[] args) { + String fileName = "output1.ser"; + Address add = new Address("Indore", "up", 123456,"India"); + Student stu = new Student("veennayak","12/12/2000",add); + serializeObject(fileName,stu); + deserializeObject(fileName); + Student stu1 = new Student("vinayak","12/12/2000",add); + serializeObject(fileName,stu1); + deserializeObject(fileName); + Student stu2 = new Student("yak","12/12/2000",add); + serializeObject(fileName,stu2); + deserializeObject(fileName); + Student stu3 = new Student("vina","12/12/2000",add); + serializeObject(fileName,stu3); + deserializeObject(fileName); + } + + private static void deserializeObject(String fileName) { + try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName))) { + Object object = ois.readObject(); + Student st=(Student) object; + System.out.println(st); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void serializeObject(String fileName ,Student stu) { + +// Address ad = new Address("Indore", "up", 123456,"India"); +// Student st = new Student("vinayak","123",ad); +// Address add = new Address("Indore", "up", 123456,"India"); +// Student stu = new Student("vinayak","123",ad); + try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName))) { + oos.writeObject(stu); +// oos.writeObject(stu); +// System.out.println("serialized"); + } catch (Exception e) { + e.printStackTrace(); + } + } +} From edfd10a639332bcf128d335197065cf77083d0ee Mon Sep 17 00:00:00 2001 From: vinayak Date: Fri, 2 Sep 2022 13:54:00 +0530 Subject: [PATCH 5/7] add and search an employee completed --- src/com/company/problem_statement_3.java | 93 ++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/com/company/problem_statement_3.java diff --git a/src/com/company/problem_statement_3.java b/src/com/company/problem_statement_3.java new file mode 100644 index 0000000..bdbfae9 --- /dev/null +++ b/src/com/company/problem_statement_3.java @@ -0,0 +1,93 @@ +package com.company; +import java.io.*; +import java.util.Scanner; + +class Employee{ + String name; + String email; + int age; + String dob; + + void add(String n, String e, int a, String d){ + name = n; + email = e; + age = a; + dob = d; + + try{ + int count=0; + FileWriter mw = new FileWriter("employee.txt",true); + File obj = new File("employee.txt"); + Scanner reader = new Scanner(obj); + BufferedWriter out = new BufferedWriter(mw); + while(reader.hasNextLine()) { + String data = reader.nextLine(); + count = (data.split("," + e + ",").length) - 1; + } + if (count<1){ + out.write(name+","+email+","+age+","+dob+"\n"); + System.out.println("written"); + } + + else{ + System.out.println("email already exists."); + } + out.close(); + + + } + catch (IOException er){ + System.out.println("some errr occurred"); + er.printStackTrace(); + } + } + void SearchRec(String e){ + email =e; + try { + File obj = new File("employee.txt"); + Scanner reader = new Scanner(obj); + int i =0; + while(reader.hasNextLine()){ + String data = reader.nextLine(); + int count = (data.split(","+e+",").length) - 1; + if (count>0) + System.out.println(data + "at line number : "+ i); + i+=1; + } + reader.close(); + } + catch (FileNotFoundException er){ + System.out.println("error found"); + er.printStackTrace(); + } + } + void DeleteRec(String e){ + email = e; + try { + FileWriter mw = new FileWriter("employee1.txt",true); + File obj = new File("employee.txt"); + BufferedWriter out = new BufferedWriter(mw); + Scanner reader = new Scanner(obj); + while(reader.hasNextLine()){ + String data = reader.nextLine(); + out.write(data); + System.out.println(data); + } + + reader.close(); + + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } +} + +public class problem_statement_3 { + public static void main(String[] args) { + Employee eobj2 = new Employee(); + + eobj2.add("vina","vin@vinay",12,"123"); + eobj2.SearchRec("vin@vin");eobj2.SearchRec("vin@vin"); +// eobj2.DeleteRec("vin@vin"); + } +} From f3f351871c13127d8e152aecc94321d43b460a93 Mon Sep 17 00:00:00 2001 From: vinayak Date: Fri, 2 Sep 2022 16:35:45 +0530 Subject: [PATCH 6/7] problem 3 completed --- src/com/company/problem_statement_3.java | 145 +++++++++++++++-------- 1 file changed, 98 insertions(+), 47 deletions(-) diff --git a/src/com/company/problem_statement_3.java b/src/com/company/problem_statement_3.java index bdbfae9..27ae8bd 100644 --- a/src/com/company/problem_statement_3.java +++ b/src/com/company/problem_statement_3.java @@ -2,92 +2,143 @@ import java.io.*; import java.util.Scanner; -class Employee{ - String name; - String email; - int age; - String dob; +class Employee { + private String name; + private String email; + private int age; + private String dob; - void add(String n, String e, int a, String d){ + void add(String n, String e, int a, String d) { name = n; email = e; age = a; dob = d; - try{ - int count=0; - FileWriter mw = new FileWriter("employee.txt",true); + try { + int count = 0; + FileWriter mw = new FileWriter("employee.txt", true); File obj = new File("employee.txt"); Scanner reader = new Scanner(obj); BufferedWriter out = new BufferedWriter(mw); - while(reader.hasNextLine()) { + while (reader.hasNextLine()) { String data = reader.nextLine(); count = (data.split("," + e + ",").length) - 1; } - if (count<1){ - out.write(name+","+email+","+age+","+dob+"\n"); + if (count < 1) { + out.write(name + "," + email + "," + age + "," + dob + "\n"); System.out.println("written"); - } - - else{ + } else { System.out.println("email already exists."); } out.close(); - } - catch (IOException er){ + } catch (IOException er) { System.out.println("some errr occurred"); er.printStackTrace(); } } - void SearchRec(String e){ - email =e; + + void SearchRec(String e) { +// email =e; try { File obj = new File("employee.txt"); Scanner reader = new Scanner(obj); - int i =0; - while(reader.hasNextLine()){ + int i = 0; + int flag = 0; + while (reader.hasNextLine()) { String data = reader.nextLine(); - int count = (data.split(","+e+",").length) - 1; - if (count>0) - System.out.println(data + "at line number : "+ i); - i+=1; + int count = (data.split("," + e + ",").length) - 1; + if (count > 0) { + flag = 1; + } + i += 1; } reader.close(); - } - catch (FileNotFoundException er){ + if (flag == 1) { + System.out.println("Found at line " + i); + + } else { + System.out.println("Not Found"); + } + } catch (FileNotFoundException er) { System.out.println("error found"); er.printStackTrace(); } } - void DeleteRec(String e){ - email = e; + + void DeleteRec(String e) { + String tempFile = "employee1.txt"; + File oldf = new File("employee.txt"); + File newf = new File("employee1.txt"); + + String current; try { - FileWriter mw = new FileWriter("employee1.txt",true); - File obj = new File("employee.txt"); - BufferedWriter out = new BufferedWriter(mw); - Scanner reader = new Scanner(obj); - while(reader.hasNextLine()){ - String data = reader.nextLine(); - out.write(data); - System.out.println(data); + FileWriter fw = new FileWriter(tempFile, true); + BufferedWriter bw = new BufferedWriter(fw); + PrintWriter pw = new PrintWriter(bw); + + FileReader fr = new FileReader("employee.txt"); + BufferedReader br = new BufferedReader(fr); +// int count = (data.split("," + e + ",").length) - 1; + while ((current = br.readLine()) == null) { + if (current.split("," + e + ",").length != 1) { + pw.println(current); + } + } + pw.flush(); + pw.close(); + fr.close(); + br.close(); + bw.close(); + fw.close(); - reader.close(); + oldf.delete(); + File dump = new File("employee.txt"); + newf.renameTo(dump); + } catch (Exception em) { - } catch (IOException ioException) { - ioException.printStackTrace(); } } + } + public class problem_statement_3 { + public static void main(String[] args) { + Employee eobj2 = new Employee(); + Scanner sc = new Scanner(System.in); + System.out.println("Enter a to add \nEnter s to search \nEnter d to delete a record "); + String operation = sc.next(); -public class problem_statement_3 { - public static void main(String[] args) { - Employee eobj2 = new Employee(); + switch (operation){ + case "a": + System.out.print("Enter name :"); + String name = sc.next(); + System.out.print("Enter email :"); + String email = sc.next(); + System.out.print("Enter age :"); + int age = sc.nextInt(); + System.out.print("Enter dob :"); + String dob = sc.next(); + eobj2.add(name, email,age,dob); + break; - eobj2.add("vina","vin@vinay",12,"123"); - eobj2.SearchRec("vin@vin");eobj2.SearchRec("vin@vin"); -// eobj2.DeleteRec("vin@vin"); + case "s": + System.out.print("Enter email :"); + String email1 = sc.next(); + eobj2.SearchRec(email1); + break; + case "d": + System.out.println("Eter email : "); + String email2 = sc.next(); + eobj2.DeleteRec(email2); + break; + } +// eobj2.add("vina","vin@vinay",12,"123"); +// eobj2.add("vina","vin@vi",12,"123"); +// eobj2.add("vina","vin@vina",12,"123"); +// eobj2.SearchRec("vin@vinay"); +// eobj2.DeleteRec("vin@vina"); + } } -} + From f9a7e705d85c5345f72c714de0d73002649432b8 Mon Sep 17 00:00:00 2001 From: vinayak Date: Thu, 8 Sep 2022 10:34:14 +0530 Subject: [PATCH 7/7] Handled sorting(order by) and direction --- src/com/{company => Hotwax/www}/Main.java | 0 .../www}/Problem_statement_1.java | 0 .../Problem_statement_4_OverdrawnDemo.java | 0 ...Problem_statement_4_OverdrawnSafeDemo.java | 0 .../www}/Problem_statement_5.java | 0 src/com/Hotwax/www/problem_statement_3.java | 322 ++++++++++++++++++ src/com/company/problem_statement_3.java | 144 -------- 7 files changed, 322 insertions(+), 144 deletions(-) rename src/com/{company => Hotwax/www}/Main.java (100%) rename src/com/{company => Hotwax/www}/Problem_statement_1.java (100%) rename src/com/{company => Hotwax/www}/Problem_statement_4_OverdrawnDemo.java (100%) rename src/com/{company => Hotwax/www}/Problem_statement_4_OverdrawnSafeDemo.java (100%) rename src/com/{company => Hotwax/www}/Problem_statement_5.java (100%) create mode 100644 src/com/Hotwax/www/problem_statement_3.java delete mode 100644 src/com/company/problem_statement_3.java diff --git a/src/com/company/Main.java b/src/com/Hotwax/www/Main.java similarity index 100% rename from src/com/company/Main.java rename to src/com/Hotwax/www/Main.java diff --git a/src/com/company/Problem_statement_1.java b/src/com/Hotwax/www/Problem_statement_1.java similarity index 100% rename from src/com/company/Problem_statement_1.java rename to src/com/Hotwax/www/Problem_statement_1.java diff --git a/src/com/company/Problem_statement_4_OverdrawnDemo.java b/src/com/Hotwax/www/Problem_statement_4_OverdrawnDemo.java similarity index 100% rename from src/com/company/Problem_statement_4_OverdrawnDemo.java rename to src/com/Hotwax/www/Problem_statement_4_OverdrawnDemo.java diff --git a/src/com/company/Problem_statement_4_OverdrawnSafeDemo.java b/src/com/Hotwax/www/Problem_statement_4_OverdrawnSafeDemo.java similarity index 100% rename from src/com/company/Problem_statement_4_OverdrawnSafeDemo.java rename to src/com/Hotwax/www/Problem_statement_4_OverdrawnSafeDemo.java diff --git a/src/com/company/Problem_statement_5.java b/src/com/Hotwax/www/Problem_statement_5.java similarity index 100% rename from src/com/company/Problem_statement_5.java rename to src/com/Hotwax/www/Problem_statement_5.java diff --git a/src/com/Hotwax/www/problem_statement_3.java b/src/com/Hotwax/www/problem_statement_3.java new file mode 100644 index 0000000..6dd05a8 --- /dev/null +++ b/src/com/Hotwax/www/problem_statement_3.java @@ -0,0 +1,322 @@ +package com.Hotwax.www; +import java.io.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Scanner; + + +class NameComparator implements Comparator { + public int compare(Employee emp1, Employee emp2){ + return emp1.getName().compareTo(emp2.getName()); + } +} +class NameComparatorDesc implements Comparator { + public int compare(Employee emp1, Employee emp2){ + return emp2.getName().compareTo(emp1.getName()); + } +} +class AgeComparator implements Comparator { + public int compare(Employee emp1, Employee emp2){ + return emp1.getAge().compareTo(emp2.getAge()); + } +} +class AgeComparatorDesc implements Comparator { + public int compare(Employee emp1, Employee emp2){ + return emp2.getAge().compareTo(emp1.getAge()); + } +} +class EmailComparator implements Comparator { + public int compare(Employee emp1, Employee emp2){ + return emp1.getEmail().compareTo(emp2.getEmail()); + } +} +class EmailComparatorDesc implements Comparator { + public int compare(Employee emp1, Employee emp2){ + return emp1.getEmail().compareTo(emp2.getEmail()); + } +} +class DobComparator implements Comparator { + public int compare(Employee emp1, Employee emp2){ + return emp1.getDob().compareTo(emp2.getDob()); + } +} +class DobComparatorDesc implements Comparator { + public int compare(Employee emp1, Employee emp2){ + return emp1.getDob().compareTo(emp2.getDob()); + } +} +class Employee implements Comparable { + private String name; + private String email; + private String age; + private String dob; + + Employee(String n, String e, String a, String d){ + name = n; + email = e; + age= a; + dob = d; + } + public String toString(){ + return name+","+email+","+age+","+dob; + } + + public int compareTo(Employee e){ + return name.compareTo(e.getName()); + } + + public String getName(){ + return name; + } + public String getEmail(){ + return email; + } + public String getDob(){ + return dob; + + } + public String getAge(){ + return age; + } + + + + void add(String n, String e, String a, String d) { + name = n; + email = e; + age = a; + dob = d; + + try { + int count = 0; + FileWriter mw = new FileWriter("employee.txt", true); + File obj = new File("employee.txt"); + Scanner reader = new Scanner(obj); + BufferedWriter out = new BufferedWriter(mw); + while (reader.hasNextLine()) { + String data = reader.nextLine(); + count = (data.split("," + e + ",").length) - 1; + } + if (count < 1) { + out.write(name + "," + email + "," + age + "," + dob + "\n"); + System.out.println("written"); + } else { + System.out.println("email already exists."); + } + out.close(); + + + } catch (IOException er) { + System.out.println("some error occurred"); + er.printStackTrace(); + } + } + + void SearchRec(String e) { + try { + File obj = new File("employee.txt"); + Scanner reader = new Scanner(obj); + int i = 0; + int flag = 0; + while (reader.hasNextLine()) { + String data = reader.nextLine(); + int count = (data.split("," + e + ",").length) - 1; + if (count > 0) { + flag = 1; + } + i += 1; + } + reader.close(); + if (flag == 1) { + System.out.println("Found at line " + i); + + } else { + System.out.println("Not Found"); + } + } catch (FileNotFoundException er) { + System.out.println("error found"); + er.printStackTrace(); + } + } + + void DeleteRec(String e) { + String tempFile = "employee1.txt"; + File oldFile = new File("employee.txt"); + File newFile = new File("employee1.txt"); + + String current; + try { + FileWriter fw = new FileWriter(tempFile, true); + BufferedWriter bw = new BufferedWriter(fw); + PrintWriter pw = new PrintWriter(bw); + + FileReader fr = new FileReader("employee.txt"); + BufferedReader br = new BufferedReader(fr); +// int count = (data.split("," + e + ",").length) - 1; + while ((current = br.readLine()) == null) { + try { + if (current.split("," + e + ",").length != 1) { + pw.println(current); + } + } + catch (NullPointerException error){ + System.out.println(error); + } + + + } + pw.flush(); + pw.close(); + fr.close(); + br.close(); + bw.close(); + fw.close(); + + oldFile.delete(); + File dump = new File("employee.txt"); + newFile.renameTo(dump); + } catch (Exception em) { + System.out.println("Handled"); + } + } + + public void sortIt(String orderBy) { + ArrayList employees = new ArrayList<>(); + try { + File obj = new File("employee.txt"); + Scanner reader = new Scanner(obj); + int flag = 0; + String[] emp=null; + while (reader.hasNextLine()) { + String data = reader.nextLine(); +// System.out.println(data); + emp = data.split(","); + Employee employee = new Employee(emp[0],emp[1],emp[2],emp[3]); + employees.add(employee); + } + System.out.println("Enter A for Ascending and D for Descending :"); + Scanner sc = new Scanner(System.in); + String order = sc.next(); + if (orderBy.equalsIgnoreCase("name")){ + if (order.equalsIgnoreCase("A")) + Collections.sort(employees,new NameComparator()); + else if (order.equalsIgnoreCase("D")){ + Collections.sort(employees,new NameComparatorDesc()); + } + else { + System.out.println("Invalid Input"); + } + } + else if (orderBy.equalsIgnoreCase("Age")){ + if (order.equalsIgnoreCase("A")){ + Collections.sort(employees,new AgeComparator()); + } + + else if(order.equalsIgnoreCase("D")){ + Collections.sort(employees,new AgeComparatorDesc()); + } + else { + System.out.println("Invalid input"); + } + } + else if (orderBy.equalsIgnoreCase("Email")){ + if (order.equalsIgnoreCase("A")){ + Collections.sort(employees,new EmailComparator()); + } + + else if(order.equalsIgnoreCase("D")){ + Collections.sort(employees,new EmailComparatorDesc()); + } + else { + System.out.println("Invalid input"); + } + } + else if(orderBy.equalsIgnoreCase("Dob")){ + if (order.equalsIgnoreCase("A")){ + Collections.sort(employees,new DobComparator()); + } + + else if(order.equalsIgnoreCase("D")){ + Collections.sort(employees,new DobComparatorDesc()); + } + else { + System.out.println("Invalid input"); + } + + } + else { + System.out.println("Invalid input"); + } +// +// + + int k; + for(k=0;k 0) { - flag = 1; - } - i += 1; - } - reader.close(); - if (flag == 1) { - System.out.println("Found at line " + i); - - } else { - System.out.println("Not Found"); - } - } catch (FileNotFoundException er) { - System.out.println("error found"); - er.printStackTrace(); - } - } - - void DeleteRec(String e) { - String tempFile = "employee1.txt"; - File oldf = new File("employee.txt"); - File newf = new File("employee1.txt"); - - String current; - try { - FileWriter fw = new FileWriter(tempFile, true); - BufferedWriter bw = new BufferedWriter(fw); - PrintWriter pw = new PrintWriter(bw); - - FileReader fr = new FileReader("employee.txt"); - BufferedReader br = new BufferedReader(fr); -// int count = (data.split("," + e + ",").length) - 1; - while ((current = br.readLine()) == null) { - if (current.split("," + e + ",").length != 1) { - pw.println(current); - } - - } - pw.flush(); - pw.close(); - fr.close(); - br.close(); - bw.close(); - fw.close(); - - oldf.delete(); - File dump = new File("employee.txt"); - newf.renameTo(dump); - } catch (Exception em) { - - } - } - -} - public class problem_statement_3 { - public static void main(String[] args) { - Employee eobj2 = new Employee(); - Scanner sc = new Scanner(System.in); - System.out.println("Enter a to add \nEnter s to search \nEnter d to delete a record "); - String operation = sc.next(); - - switch (operation){ - case "a": - System.out.print("Enter name :"); - String name = sc.next(); - System.out.print("Enter email :"); - String email = sc.next(); - System.out.print("Enter age :"); - int age = sc.nextInt(); - System.out.print("Enter dob :"); - String dob = sc.next(); - eobj2.add(name, email,age,dob); - break; - - case "s": - System.out.print("Enter email :"); - String email1 = sc.next(); - eobj2.SearchRec(email1); - break; - case "d": - System.out.println("Eter email : "); - String email2 = sc.next(); - eobj2.DeleteRec(email2); - break; - } -// eobj2.add("vina","vin@vinay",12,"123"); -// eobj2.add("vina","vin@vi",12,"123"); -// eobj2.add("vina","vin@vina",12,"123"); -// eobj2.SearchRec("vin@vinay"); -// eobj2.DeleteRec("vin@vina"); - } - } -