diff --git a/Week 3/Equipment.java b/Week 3/Equipment.java new file mode 100644 index 0000000..b54b13b --- /dev/null +++ b/Week 3/Equipment.java @@ -0,0 +1,42 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * This class simulates an Equipment + * + * @author Bhaskar Tejaswi + */ +import java.util.*; + +public class Equipment { + + public String id; + public String description; + + public Equipment(String eqId,String desc){ + + id = eqId; + description = desc; + } + + public String getId() + {/*return id and description to IFSC manager, then, IFSC manager initialises the id and description + by these returned values*/ + Scanner sc = new Scanner(System.in); + String idEq = sc.next(); + return idEq; + } + + public String getDesc(){ + + Scanner sc = new Scanner(System.in); + String desc = sc.next(); + return desc; + } + + + +} diff --git a/Week 3/IFCSManager.java b/Week 3/IFCSManager.java new file mode 100644 index 0000000..eafb66c --- /dev/null +++ b/Week 3/IFCSManager.java @@ -0,0 +1,209 @@ +/** + *This class simulates an IFCS Manager + * It allows user to add, remove or search equipments.. + * User can also get a list of all Equipments in the Lab + * @author Bhaskar Tejaswi + */ +import java.io.*; +import java.util.*; +public class IFCSManager { + + Equipment equip[] = new Equipment[100]; + int pointer=0;/* we want all instances of manager to have same content of pointer*/ + /** + * Add an Equipment by this function + */ + public void add() + { + Scanner sc = new Scanner(System.in); + + int flag=0; + + System.out.println("Enter Id :"); + String idEq = equip[pointer].getId(); + + System.out.println("Enter Description :"); + String desc = equip[pointer].getDesc(); + + int f=0,choice; + for(int i=0;i0) + System.out.println("Our first Triangle is bigger.."); + else if(Double.compare(myTriangle1.getArea(), myTriangle2.getArea())<0) + System.out.println("The second Triangle is bigger.."); + else + System.out.println("Both have same area.."); + } + } + } + /** + * Main function + * @param args-string args[] + */ + public static void main(String[]args){ + + Triangle myTriangle1 = new Triangle(0,0); + Triangle myTriangle2 = new Triangle(0,0); + Scanner sc = new Scanner(System.in); + int choice=0; + do { System.out.println("Enter your choice :"); + System.out.println("1: Initialize first Triangle"); + System.out.println("2. Calculate Area"); + System.out.println("3: Compare with another Triangle"); + System.out.println("4: Show dimensions of first triangle "); + System.out.println("5: quit"); + choice = sc.nextInt(); + switch (choice) + { + case 1: /*initialize first triangle*/ + System.out.println("enter the base :"); + int myBase1=sc.nextInt(); + System.out.println("enter the height :"); + int myHeight1 = sc.nextInt(); + if(myBase1<=0 ||myHeight1<=0) + System.out.println("Please enter only positive integers for base and height "); + else + { + myTriangle1= new Triangle(myBase1,myHeight1); + System.out.println("Triangle inilialized successfully.."); + } + break; + + case 2: /*calculate area*/ + if(myTriangle1.base==0 && myTriangle1.height==0 ) + System.out.println("The Triangle 1 has not been initialized"); + else + System.out.println("Area is "+myTriangle1.getArea()+" sq units"); + break; + + case 3: /*compare */ + myTriangle1.compare(myTriangle1,myTriangle2); + break; + case 4: if(myTriangle1.base==0 && myTriangle1.height==0) + System.out.println("The first triangle has not been initialized"); + else + { + myTriangle1.show(); + } + break; + + case 5: System.out.println("Program terminated."); + break; + default: System.out.println("Wrong choice"); + break; + } + } while (choice != 5); + +System.out.println("Thank You!"); + } +} \ No newline at end of file diff --git a/Week 4/CSEStudent.java b/Week 4/CSEStudent.java new file mode 100644 index 0000000..3a4b7f9 --- /dev/null +++ b/Week 4/CSEStudent.java @@ -0,0 +1,26 @@ +/** + * + * @author Bhaskar Tejaswi + */ +public class CSEStudent extends Student{ + + public final String hobby= "Hacking"; + + CSEStudent(String name) + { + super(name); + } + + public void introduce(){ + System.out.println("Hello my name is "+retName() +" and my hobby is "+hobby); + } + public void onFacebook(){ + super.introduce(); + } + public void isHacker(){ + introduce(); + } + public void isReader(){ + super.isReader(); + } +} \ No newline at end of file diff --git a/Week 4/Circle.java b/Week 4/Circle.java new file mode 100644 index 0000000..8c9b409 --- /dev/null +++ b/Week 4/Circle.java @@ -0,0 +1,25 @@ + + +/** + * + * @author Bhaskar Tejaswi + */ +public class Circle extends Shape { + + private double radius; + + Circle(double radius) + { + + super("Circle"); + this.radius = radius; + + System.out.println("Constructor of Circle with parameter "+radius); + } + void printDescription(){ + name = "Rectangle"; + System.out.println("Radius = "+radius); + System.out.println("Area = " +3.14*radius*radius+" sq units"); + + } +} \ No newline at end of file diff --git a/Week 4/Person.java b/Week 4/Person.java new file mode 100644 index 0000000..99f1bc8 --- /dev/null +++ b/Week 4/Person.java @@ -0,0 +1,29 @@ +/** + * + * @author Bhaskar Tejaswi + */ +import java.util.*; +public class Person { + Scanner sc = new Scanner(System.in); + public final String hobby = "Reading"; + private String name; + public Person(String name) + { + this.name = getName(); + } + public String getName(){ + System.out.println("Enter name:"); + name = sc.next(); + return name; + } + public String retName(){ + return name; + } + + /** + * + */ + public void introduce(){ + System.out.println("Hello my name is "+name +" and my hobby is "+hobby); + } +} diff --git a/Week 4/Questions.docx b/Week 4/Questions.docx new file mode 100644 index 0000000..e01991b Binary files /dev/null and b/Week 4/Questions.docx differ diff --git a/Week 4/Rectangle.java b/Week 4/Rectangle.java new file mode 100644 index 0000000..3eee6c2 --- /dev/null +++ b/Week 4/Rectangle.java @@ -0,0 +1,29 @@ + +/** + * + * @author Bhaskar Tejaswi + */ +public class Rectangle extends Shape { + + double length; + double breadth; + + Rectangle(double length, double breadth){ + super("Rectangle"); + this.length = length; + this.breadth = breadth; + System.out.println("Constructor of Rectangle with parameters "+length+" and "+breadth); + } + void printDescription(){ + + System.out.println("Length = "+length); + System.out.println("Length = "+breadth); + System.out.println("Area = " +areaOf()+" sq units"); + } + double areaOf(){ + return length*breadth; + } + + + +} diff --git a/Week 4/Shape.java b/Week 4/Shape.java new file mode 100644 index 0000000..b3faaa1 --- /dev/null +++ b/Week 4/Shape.java @@ -0,0 +1,17 @@ +/** + * + * @author Bhaskar Tejaswi + */ +public class Shape { + String name=""; + + Shape(String name) + { + this.name = name; + System.out.println("Constructor of Shape"); + } + void printDescription(){ + System.out.println("I am a shape and my name is "+name); + } +} + diff --git a/Week 4/ShapeManager.java b/Week 4/ShapeManager.java new file mode 100644 index 0000000..a8f7ef0 --- /dev/null +++ b/Week 4/ShapeManager.java @@ -0,0 +1,74 @@ +/** + * + * @author Bhaskar Tejaswi + */ +import java.util.Scanner; +public class ShapeManager { + + public static void main(String[]args){ + int choice; + Scanner sc = new Scanner(System.in); + ShapeManager myShapeManager = new ShapeManager(); + + do { + System.out.println("Select a Shape"); + System.out.println("1.Rectangle"); + System.out.println("2.Square"); + System.out.println("3.Circle"); + System.out.println("4.Exit"); + choice = sc.nextInt(); + + switch (choice) + { + case 1: + System.out.println("Enter the length :"); + double len=sc.nextDouble(); + System.out.println("Enter the breadth :"); + double bd=sc.nextDouble(); + if(len<=0 || bd<=0) + System.out.println("Invalid Entry"); + else + { + Rectangle myRect = new Rectangle(len,bd); + myShapeManager.manageShape(myRect); + } + break; + + case 2: System.out.println("Enter the side length :"); + double side=sc.nextDouble(); + if(side<=0) + System.out.println("Side must be positive"); + else + { + Square mysq = new Square(side); + Rectangle myRect = (Rectangle)mysq; + myRect.printDescription(); + } + break; + + case 3: System.out.println("Enter the radius :"); + double radius=sc.nextDouble(); + if(radius<=0) + System.out.println("Invalid Entry"); + else + { + Circle myCircle = new Circle(radius); + myShapeManager.manageShape(myCircle); + } + break; + + case 4: System.out.println("Program terminated."); + break; + + default: System.out.println("Invalid entry !"); + break; + } + } while (choice != 4); + System.out.println("Thank You!"); + } + void manageShape(Shape myShape) + { + myShape.printDescription(); + +} +} \ No newline at end of file diff --git a/Week 4/Square.java b/Week 4/Square.java new file mode 100644 index 0000000..a209d3d --- /dev/null +++ b/Week 4/Square.java @@ -0,0 +1,19 @@ + + +/** + * + * @author Bhaskar Tejaswi + */ +public class Square extends Rectangle { + + Square(double side) + { + super(side, side); + System.out.println("Constructor of Square with parameters "+side); + } + + void printDescription(){ + System.out.println("Side = "+length); + System.out.println("Area = " +areaOf()+" sq units"); + } +} diff --git a/Week 4/Student.java b/Week 4/Student.java new file mode 100644 index 0000000..cb12017 --- /dev/null +++ b/Week 4/Student.java @@ -0,0 +1,17 @@ +/** + * + * @author Bhaskar Tejaswi + */ +public class Student extends Person{ + public final String hobby= "surfing Facebook"; + Student(String name) + { + super(name); + } + public void introduce(){ + System.out.println("Hello my name is "+retName() +" and my hobby is "+hobby); + } + public void isReader(){ + super.introduce(); + } +} diff --git a/Week 4/StudentManager.java b/Week 4/StudentManager.java new file mode 100644 index 0000000..a1ce050 --- /dev/null +++ b/Week 4/StudentManager.java @@ -0,0 +1,35 @@ +/** + * + * @author Bhaskar Tejaswi + */ +import java.util.*; +public class StudentManager { + public static void main(String[] args){ + Scanner sc = new Scanner(System.in); + int choice; + CSEStudent Arif = new CSEStudent("Arif"); + do { + System.out.println("Where is "+Arif.retName()+" ?"); + System.out.println("1: At a get-together for student leaders"); + System.out.println("2: At a closed-door Hacker Society meeting"); + System.out.println("3: At his cousin's birthday party"); + System.out.println("4: Quit"); + choice = sc.nextInt(); + + switch (choice) + { + case 1: Arif.onFacebook(); + break; + case 2: Arif.isHacker(); + break; + case 3: Arif.isReader(); + break; + case 4: System.out.println("Program terminated"); + break; + default: System.out.println("Invalid choice");/* add error handling */ + break; + } + } while (choice != 4); + System.out.println("Thank You!"); + } +}