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 0000000..74d95bd Binary files /dev/null and b/out/production/Assignment1/com/company/Circle.class differ diff --git a/out/production/Assignment1/com/company/Cylinder.class b/out/production/Assignment1/com/company/Cylinder.class new file mode 100644 index 0000000..194df0f Binary files /dev/null and b/out/production/Assignment1/com/company/Cylinder.class differ diff --git a/out/production/Assignment1/com/company/Main.class b/out/production/Assignment1/com/company/Main.class new file mode 100644 index 0000000..8694f85 Binary files /dev/null and b/out/production/Assignment1/com/company/Main.class differ 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 0000000..9d43ffb Binary files /dev/null and b/out/production/Assignment1/com/company/Problem_statement_1.class differ diff --git a/out/production/Assignment1/com/company/Rectangle.class b/out/production/Assignment1/com/company/Rectangle.class new file mode 100644 index 0000000..bbb22d7 Binary files /dev/null and b/out/production/Assignment1/com/company/Rectangle.class differ diff --git a/out/production/Assignment1/com/company/Sphere.class b/out/production/Assignment1/com/company/Sphere.class new file mode 100644 index 0000000..2bee392 Binary files /dev/null and b/out/production/Assignment1/com/company/Sphere.class differ diff --git a/out/production/Assignment1/com/company/Square.class b/out/production/Assignment1/com/company/Square.class new file mode 100644 index 0000000..c590497 Binary files /dev/null and b/out/production/Assignment1/com/company/Square.class differ diff --git a/out/production/Assignment1/com/company/Triangle.class b/out/production/Assignment1/com/company/Triangle.class new file mode 100644 index 0000000..c572a3e Binary files /dev/null and b/out/production/Assignment1/com/company/Triangle.class differ 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"); + } + + } } } 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/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(); + } + } + +} 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