├── LAB 10 ├── Sample.avi ├── bin │ ├── CircleIcon.class │ ├── LeftThread.class │ ├── OnlineMain$1.class │ ├── OnlineMain$2.class │ ├── OnlineMain$3.class │ ├── OnlineMain$4.class │ ├── OnlineMain$5.class │ ├── OnlineMain.class │ ├── RightThread.class │ ├── ScaleDownThread.class │ └── ScaleUpThread.class └── src │ └── OnlineMain.java ├── LAB 2 ├── bin │ ├── Car.class │ ├── Customer.class │ ├── Item.class │ ├── RaceTrack.class │ ├── TaxOnSalary.class │ ├── TestStore.class │ └── TestTax.class └── src │ ├── RaceTrack.java │ ├── TestStore.java │ └── TestTax.java ├── LAB 3 ├── bin │ ├── BOX.class │ ├── BOXTest.class │ ├── Circle.class │ ├── ConstructorBlockExample.class │ ├── MyStatic.class │ ├── Point.class │ ├── PointTest.class │ ├── StaticBlock.class │ ├── StaticDemo.class │ ├── StaticExample.class │ ├── Test1.class │ └── TestCircle.class └── src │ ├── BOXTest.java │ ├── ConstructorBlockExample.java │ ├── PointTest.java │ ├── StaticBlock.java │ ├── StaticDemo.java │ ├── StaticExample.java │ ├── Test1.java │ └── TestCircle.java ├── LAB 4 ├── bin │ ├── Address.class │ ├── AddressList.class │ ├── Item.class │ ├── Name.class │ ├── Pokeball.class │ ├── Pokemon.class │ ├── RetailStore.class │ ├── RetailStore2.class │ ├── RetailStoreExample.class │ ├── Student.class │ ├── StudentList.class │ ├── Test.class │ ├── Test2.class │ ├── Test3.class │ └── Trainer.class └── src │ ├── RetailStore2.java │ ├── RetailStoreExample.java │ ├── Test.java │ ├── Test2.java │ └── Test3.java ├── LAB 5 ├── bin │ ├── A.class │ ├── B.class │ ├── C.class │ ├── Circle.class │ ├── Country.class │ ├── Cylinder.class │ ├── D.class │ ├── DRIVERCODE.class │ ├── E.class │ ├── Employee.class │ ├── FulltimeWorker.class │ ├── HourlyWorker.class │ ├── Manager.class │ ├── OverloadConstructors.class │ ├── Rectangle.class │ ├── Room.class │ ├── Shape.class │ ├── Test.class │ ├── TestCylinder.class │ ├── TestShape.class │ ├── TestWorker.class │ ├── Triangle.class │ └── worker.class └── src │ ├── Country.java │ ├── DRIVERCODE.java │ ├── OverloadConstructors.java │ ├── Test.java │ ├── TestCylinder.java │ ├── TestShape.java │ └── TestWorker.java ├── LAB 6 ├── bin │ ├── BinaryInterface.class │ ├── BinaryTest.class │ ├── CompareByBoth.class │ ├── CompareByCenter.class │ ├── CompareByRadius.class │ ├── Movable.class │ ├── MovableCircle.class │ ├── MovablePoint.class │ ├── OneComplement.class │ ├── Package2 │ │ ├── Movable.class │ │ ├── MovablePoint.class │ │ ├── Outer$Inner.class │ │ ├── Outer.class │ │ └── TestMovable.class │ ├── SignedMagnitude.class │ ├── TestMovableSecond.class │ └── TwoComplement.class └── src │ ├── BinaryTest.java │ ├── Package2 │ ├── Outer.java │ └── TestMovable.java │ └── TestMovableSecond.java ├── LAB 7 ├── bin │ ├── Account.class │ ├── ArrayListDemo.class │ ├── Bank.class │ ├── DriverCode.class │ ├── Movie$1.class │ ├── Movie$1EnglishMovie.class │ ├── Movie$Bookable.class │ ├── Movie.class │ ├── Student.class │ └── TestStudentList.class └── src │ ├── ArrayListDemo.java │ ├── DriverCode.java │ ├── Movie.java │ └── TestStudentList.java ├── LAB 8 ├── bin │ └── test_bank │ │ ├── Bank.class │ │ ├── BankAccount.class │ │ ├── BankApp.class │ │ └── InsufficientFundsException.class └── src │ └── test_bank │ ├── Bank.java │ ├── BankAccount.java │ ├── BankApp.java │ ├── InsufficientFundsException.java │ ├── ThermostatDriver.java │ ├── accounts.txt │ └── badinput.txt ├── LAB TEST ├── bin │ ├── ComputeThread.class │ ├── CreateThread.class │ ├── OnlineMain$1.class │ ├── OnlineMain$2.class │ ├── OnlineMain$3.class │ ├── OnlineMain$4.class │ ├── OnlineMain$5.class │ ├── OnlineMain.class │ ├── QuadraticEquation.class │ └── QuadraticEquationQueue.class └── src │ └── OnlineMain.java ├── LAB_01.pdf ├── LAB_02.pdf ├── LAB_03.pdf ├── LAB_04.pdf ├── LAB_05.pdf ├── LAB_06.pdf ├── LAB_07.pdf ├── LAB_08.pdf ├── LAB_09.pdf ├── LAB_10.pdf ├── LAB_11.pdf ├── Lab 11 └── Washing Machine.rar └── README.md /LAB 10/Sample.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/Sample.avi -------------------------------------------------------------------------------- /LAB 10/bin/CircleIcon.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/bin/CircleIcon.class -------------------------------------------------------------------------------- /LAB 10/bin/LeftThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/bin/LeftThread.class -------------------------------------------------------------------------------- /LAB 10/bin/OnlineMain$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/bin/OnlineMain$1.class -------------------------------------------------------------------------------- /LAB 10/bin/OnlineMain$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/bin/OnlineMain$2.class -------------------------------------------------------------------------------- /LAB 10/bin/OnlineMain$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/bin/OnlineMain$3.class -------------------------------------------------------------------------------- /LAB 10/bin/OnlineMain$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/bin/OnlineMain$4.class -------------------------------------------------------------------------------- /LAB 10/bin/OnlineMain$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/bin/OnlineMain$5.class -------------------------------------------------------------------------------- /LAB 10/bin/OnlineMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/bin/OnlineMain.class -------------------------------------------------------------------------------- /LAB 10/bin/RightThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/bin/RightThread.class -------------------------------------------------------------------------------- /LAB 10/bin/ScaleDownThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/bin/ScaleDownThread.class -------------------------------------------------------------------------------- /LAB 10/bin/ScaleUpThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 10/bin/ScaleUpThread.class -------------------------------------------------------------------------------- /LAB 10/src/OnlineMain.java: -------------------------------------------------------------------------------- 1 | import java.awt.event.*; 2 | 3 | import javax.swing.*; 4 | 5 | import java.awt.*; 6 | import java.awt.geom.*; 7 | 8 | // class implementing the icon 9 | class CircleIcon implements Icon 10 | { 11 | private double radius; // radius of the circle icon 12 | private int X_position; // x-position of circle icon 13 | private int Y_position; // y-position of circle icon 14 | // Constructor Method 15 | CircleIcon(double radius) 16 | { 17 | this.radius = radius; 18 | this.X_position = 300; // current x-position is 300 19 | this.Y_position = 0; // current y-position is 0 20 | } 21 | 22 | // Methods for getting icon height and width 23 | public int getIconWidth() { return (int)radius; } 24 | public int getIconHeight() { return (int)radius; } 25 | 26 | // Method for painting icon 27 | public void paintIcon(Component C,Graphics g, int x,int y) 28 | { 29 | Graphics2D g2 = (Graphics2D)g; 30 | Ellipse2D.Double circle = new Ellipse2D.Double(x+X_position,y+Y_position,radius,radius); 31 | g2.draw(circle); 32 | g2.setColor(Color.red); 33 | g2.fill(circle); 34 | } 35 | 36 | // ADD ANY OTHER METHOD(s) THAT YOU THINK IS/ARE REQUIRED FOR THIS PROBLEM. DO NOT REMOVE 37 | // THESE COMMENTS JUST WRITE YOUR CODE AFTER THESE COMMENTS 38 | 39 | //Accessor and mutator methods 40 | 41 | public double getRadius(){ 42 | return radius; 43 | } 44 | public int getX(){ 45 | return X_position; 46 | } 47 | public int getY(){ 48 | return Y_position; 49 | } 50 | public void setRadius(double radius){ 51 | this.radius= radius; 52 | } 53 | public void setX(int X_position){ 54 | this.X_position = X_position; 55 | } 56 | public void setY(int Y_position){ 57 | this.Y_position = Y_position; 58 | } 59 | 60 | }// End of class CircleIcon 61 | 62 | 63 | //-----------------------------------------FOUR THREAD CLASSES ------------------------- 64 | 65 | class LeftThread extends Thread 66 | { 67 | CircleIcon circleIcon; 68 | boolean suspendLeftThread = true; 69 | JFrame frame; 70 | 71 | public LeftThread(CircleIcon circleIcon, JFrame frame){ 72 | this.circleIcon = circleIcon; 73 | this.frame = frame; 74 | } 75 | 76 | public void run(){ 77 | synchronized(circleIcon){ 78 | try{ 79 | while(true){ 80 | while(suspendLeftThread){ 81 | circleIcon.wait(); 82 | } 83 | if(circleIcon.getX()!=0){ 84 | System.out.println("Moving Left"); 85 | circleIcon.setX(circleIcon.getX()-10); 86 | frame.repaint(); 87 | Thread.sleep(100); 88 | } 89 | else{ 90 | circleIcon.wait(); 91 | suspendLeftThread = true; 92 | } 93 | } 94 | } 95 | catch(InterruptedException e){ 96 | System.out.println("Child thread Interrupted"); 97 | } 98 | } 99 | } 100 | } 101 | 102 | class RightThread extends Thread 103 | { 104 | CircleIcon circleIcon; 105 | boolean suspendRightThread = true; 106 | JFrame frame; 107 | 108 | public RightThread(CircleIcon circleIcon, JFrame frame){ 109 | this.circleIcon = circleIcon; 110 | this.frame = frame; 111 | } 112 | 113 | public void run(){ 114 | synchronized(circleIcon){ 115 | try{ 116 | while(true){ 117 | while(suspendRightThread){ 118 | circleIcon.wait(); 119 | } 120 | if(circleIcon.getX()!=600){ 121 | System.out.println("Moving Right"); 122 | circleIcon.setX(circleIcon.getX()+10); 123 | frame.repaint(); 124 | Thread.sleep(100); 125 | } 126 | else{ 127 | circleIcon.wait(); 128 | suspendRightThread = true; 129 | } 130 | } 131 | } 132 | catch(InterruptedException e){ 133 | System.out.println("Child thread Interrupted"); 134 | } 135 | } 136 | } 137 | } 138 | 139 | class ScaleUpThread extends Thread 140 | { 141 | CircleIcon circleIcon; 142 | boolean suspendScaleUpThread = true; 143 | JFrame frame; 144 | 145 | public ScaleUpThread(CircleIcon circleIcon, JFrame frame){ 146 | this.circleIcon = circleIcon; 147 | this.frame = frame; 148 | } 149 | 150 | public void run(){ 151 | synchronized(circleIcon){ 152 | try{ 153 | while(true){ 154 | while(suspendScaleUpThread){ 155 | circleIcon.wait(); 156 | } 157 | if(circleIcon.getRadius()!=50){ 158 | System.out.println("Scaling Up"); 159 | circleIcon.setRadius(circleIcon.getRadius()+1); 160 | frame.repaint(); 161 | Thread.sleep(100); 162 | } 163 | else{ 164 | suspendScaleUpThread = true; 165 | circleIcon.wait(); 166 | } 167 | } 168 | } 169 | catch(InterruptedException e){ 170 | System.out.println("Child thread Interrupted"); 171 | } 172 | } 173 | } 174 | } 175 | class ScaleDownThread extends Thread 176 | { 177 | CircleIcon circleIcon; 178 | boolean suspendScaleDownThread = true; 179 | JFrame frame; 180 | 181 | public ScaleDownThread(CircleIcon circleIcon, JFrame frame){ 182 | this.circleIcon = circleIcon; 183 | this.frame = frame; 184 | } 185 | 186 | public void run(){ 187 | synchronized(circleIcon){ 188 | try{ 189 | while(true){ 190 | while(suspendScaleDownThread){ 191 | circleIcon.wait(); 192 | } 193 | if(circleIcon.getRadius()!=5){ 194 | System.out.println("Scaling Down"); 195 | circleIcon.setRadius(circleIcon.getRadius()-1); 196 | frame.repaint(); 197 | Thread.sleep(100); 198 | } 199 | else{ 200 | suspendScaleDownThread = true; 201 | circleIcon.wait(); 202 | } 203 | } 204 | } 205 | catch(InterruptedException e){ 206 | System.out.println("Child thread Interrupted"); 207 | } 208 | } 209 | } 210 | } 211 | 212 | //----------------------------------------THREAD CLASSES ENDS HERE------------------------ 213 | 214 | 215 | 216 | 217 | // Driver class 218 | class OnlineMain 219 | { 220 | // The following four boolean class variables can be used to determine whether the thread has started or not 221 | // While starting any thread just make the corresponding flag as true. Initially no thread is started. 222 | public static boolean leftThreadStarted = false; //leftThread not started initially 223 | public static boolean rightThreadStarted = false; //rightThread not started initially 224 | public static boolean scaleUpThreadStarted = false; //scaleUpThread not started initially 225 | public static boolean scaleDownThreadStarted = false; //scaleDownThread not started initially 226 | 227 | // The following four boolean class variables can be used to determine which thread is currently running 228 | // Only one of the following 4 variables will be true at a time and rest other are false. 229 | // Initially no thread is running 230 | public static boolean leftThreadRunning = false; //leftThread is not running initially 231 | public static boolean rightThreadRunning = false; //rightThread is not running initially 232 | public static boolean scaleUpThreadRunning = false; //scaleUpThread is not running initially 233 | public static boolean scaleDownThreadRunning = false; //scaleDownThread is not running initially 234 | 235 | // Driver main() Method 236 | public static void main(String args[]) 237 | { 238 | 239 | JFrame frame = new JFrame("Main Frame"); // original frame 240 | frame.setSize(600,600); // size 600 * 600 241 | frame.setLayout(new BorderLayout()); // layout BorderLayout 242 | 243 | // Create a CircleIcon instance circleIcon with initial radius 10 244 | CircleIcon circleIcon = new CircleIcon(10); 245 | 246 | // Create a JLabel instance named iconLabel which can hold above circleIcon 247 | final JLabel iconLabel = new JLabel(); 248 | iconLabel.setIcon(circleIcon); // setting icon for iconLabel 249 | 250 | // Create a JPanel for holding iconLabel 251 | JPanel centrePanel = new JPanel(new BorderLayout()); 252 | centrePanel.add(iconLabel,BorderLayout.CENTER); // Adding iconLabel in the center of centrePanel 253 | 254 | // Create Buttons with labels as mentioned in the Question 255 | JButton leftButton = new JButton("LEFT"); // left button 256 | JButton rightButton = new JButton("RIGHT"); // right button 257 | JButton scaleUpButton = new JButton("SCALE UP"); // scaleUp button 258 | JButton scaleDownButton = new JButton("SCALE DOWN"); // scaleDown button 259 | JButton stopButton = new JButton("STOP"); // stop button 260 | 261 | // Create a buttonPanel for holding buttons 262 | JPanel buttonPanel = new JPanel(); 263 | 264 | // Add buttons to buttonPanel 265 | buttonPanel.add(leftButton); 266 | buttonPanel.add(rightButton); 267 | buttonPanel.add(scaleUpButton); 268 | buttonPanel.add(scaleDownButton); 269 | buttonPanel.add(stopButton); 270 | 271 | 272 | // Add centrePanel to center of frame 273 | frame.add(centrePanel,BorderLayout.CENTER); 274 | 275 | // Add buttonPanel to south portion of frame 276 | frame.add(buttonPanel,BorderLayout.SOUTH); 277 | 278 | // Display Frame 279 | frame.setVisible(true); 280 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Default close operation 281 | 282 | //---------------------------------------- WRITE YOUR CODE FROM HERE--------------------------- 283 | 284 | // Complete the following thread creating statement(s) after removing the comments 285 | 286 | final LeftThread leftThread = new LeftThread(circleIcon,frame); 287 | final RightThread rightThread = new RightThread(circleIcon,frame); 288 | final ScaleUpThread scaleUpThread = new ScaleUpThread(circleIcon,frame); 289 | final ScaleDownThread scaleDownThread = new ScaleDownThread(circleIcon,frame); 290 | 291 | 292 | // WRITE JAVA CODE FOR ACTIONLISTENERS FOR VARIOUS BUTTONS. USE ONLY INNER CLASSES FOR THE SAME 293 | 294 | leftButton.addActionListener(new ActionListener() 295 | { 296 | public void actionPerformed(ActionEvent ae) 297 | { 298 | leftThread.suspendLeftThread= true; 299 | rightThread.suspendRightThread= true; 300 | scaleUpThread.suspendScaleUpThread= true; 301 | scaleDownThread.suspendScaleDownThread= true; 302 | if(leftThreadStarted == false){ 303 | leftThreadStarted = true; 304 | leftThread.suspendLeftThread= false; 305 | leftThread.start(); 306 | } 307 | else{ 308 | synchronized(circleIcon) { 309 | leftThread.suspendLeftThread= false; 310 | circleIcon.notifyAll(); 311 | } 312 | } 313 | } 314 | }); 315 | 316 | rightButton.addActionListener(new ActionListener() 317 | { 318 | public void actionPerformed(ActionEvent ae) 319 | { 320 | leftThread.suspendLeftThread= true; 321 | rightThread.suspendRightThread= true; 322 | scaleUpThread.suspendScaleUpThread= true; 323 | scaleDownThread.suspendScaleDownThread= true; 324 | if(rightThreadStarted == false){ 325 | rightThreadStarted = true; 326 | rightThread.suspendRightThread= false; 327 | rightThread.start(); 328 | } 329 | else{ 330 | synchronized(circleIcon) { 331 | rightThread.suspendRightThread= false; 332 | circleIcon.notifyAll(); 333 | } 334 | } 335 | } 336 | }); 337 | 338 | scaleUpButton.addActionListener(new ActionListener() 339 | { 340 | public void actionPerformed(ActionEvent ae) 341 | { 342 | leftThread.suspendLeftThread= true; 343 | rightThread.suspendRightThread= true; 344 | scaleUpThread.suspendScaleUpThread= true; 345 | scaleDownThread.suspendScaleDownThread= true; 346 | if(scaleUpThreadStarted == false){ 347 | scaleUpThreadStarted = true; 348 | scaleUpThread.suspendScaleUpThread= false; 349 | scaleUpThread.start(); 350 | } 351 | else{ 352 | synchronized(circleIcon) { 353 | scaleUpThread.suspendScaleUpThread= false; 354 | circleIcon.notifyAll(); 355 | } 356 | } 357 | } 358 | }); 359 | 360 | scaleDownButton.addActionListener(new ActionListener() 361 | { 362 | public void actionPerformed(ActionEvent ae) 363 | { 364 | leftThread.suspendLeftThread= true; 365 | rightThread.suspendRightThread= true; 366 | scaleUpThread.suspendScaleUpThread= true; 367 | scaleDownThread.suspendScaleDownThread= true; 368 | if(scaleDownThreadStarted == false){ 369 | scaleDownThreadStarted = true; 370 | scaleDownThread.suspendScaleDownThread= false; 371 | scaleDownThread.start(); 372 | } 373 | else{ 374 | synchronized(circleIcon) { 375 | scaleDownThread.suspendScaleDownThread= false; 376 | circleIcon.notifyAll(); 377 | } 378 | } 379 | } 380 | }); 381 | 382 | stopButton.addActionListener(new ActionListener() 383 | { 384 | public void actionPerformed(ActionEvent ae) 385 | { 386 | leftThread.suspendLeftThread= true; 387 | rightThread.suspendRightThread= true; 388 | scaleUpThread.suspendScaleUpThread= true; 389 | scaleDownThread.suspendScaleDownThread= true; 390 | 391 | } 392 | }); 393 | 394 | } // End of main() Method 395 | }// End of class OnlineMain -------------------------------------------------------------------------------- /LAB 2/bin/Car.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 2/bin/Car.class -------------------------------------------------------------------------------- /LAB 2/bin/Customer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 2/bin/Customer.class -------------------------------------------------------------------------------- /LAB 2/bin/Item.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 2/bin/Item.class -------------------------------------------------------------------------------- /LAB 2/bin/RaceTrack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 2/bin/RaceTrack.class -------------------------------------------------------------------------------- /LAB 2/bin/TaxOnSalary.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 2/bin/TaxOnSalary.class -------------------------------------------------------------------------------- /LAB 2/bin/TestStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 2/bin/TestStore.class -------------------------------------------------------------------------------- /LAB 2/bin/TestTax.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 2/bin/TestTax.class -------------------------------------------------------------------------------- /LAB 2/src/RaceTrack.java: -------------------------------------------------------------------------------- 1 | public class RaceTrack { 2 | 3 | public static void main(String args[]){ 4 | Car c1= new Car(1943,"TATA",32.65); 5 | System.out.println("Year "+c1.getYear()); 6 | System.out.println("Make "+c1.getMake()); 7 | System.out.println("Speed "+c1.getSpeed()); 8 | 9 | c1.Accelerate(); 10 | System.out.println("Speed "+c1.getSpeed()); 11 | 12 | c1.Accelerate(10); 13 | System.out.println("Speed "+c1.getSpeed()); 14 | 15 | c1.Break(4); 16 | System.out.println("Speed "+c1.getSpeed()); 17 | 18 | /* this is not gonna work as the default constructor is now overridden 19 | Car c2= new Car(); 20 | System.out.println("Year "+c2.getYear()); 21 | System.out.println("Make "+c2.getMake()); 22 | System.out.println("Speed "+c2.getSpeed()); 23 | 24 | c1.Accelerate(); 25 | System.out.println("Speed "+c2.getSpeed()); 26 | 27 | c1.Accelerate(10); 28 | System.out.println("Speed "+c2.getSpeed()); 29 | 30 | c1.Break(2); 31 | System.out.println("Speed "+c2.getSpeed()); 32 | */ 33 | } 34 | } 35 | 36 | class Car{ 37 | private int year; 38 | private String make; 39 | private double speed; 40 | 41 | //Constructor 42 | Car(int year, String make, double speed){ 43 | this.year=year; 44 | this.make=make; 45 | this.speed=speed; 46 | } 47 | 48 | //Accessors 49 | public int getYear(){ 50 | return year; 51 | } 52 | public String getMake(){ 53 | return make; 54 | } 55 | public double getSpeed(){ 56 | return speed; 57 | } 58 | 59 | //Methods 60 | public void Accelerate(){ 61 | speed+=1; 62 | } 63 | public void Accelerate(int increment){ 64 | speed+=increment; 65 | } 66 | public void Break(int b){ 67 | speed-=Math.sqrt(b); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /LAB 2/src/TestStore.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Item { 4 | private String itemName; 5 | private String itemidNo; 6 | private int itemQuantity; 7 | private double itemPrice; 8 | 9 | Item(String name, String id, int quantity, double price){ 10 | itemName= name; 11 | itemidNo= id; 12 | itemQuantity= quantity; 13 | itemPrice= price; 14 | } 15 | Item(String name, String id, int quantity){ 16 | itemName= name; 17 | itemidNo= id; 18 | itemQuantity= quantity; 19 | itemPrice= 500; 20 | } 21 | 22 | Item(String name, String id){ 23 | itemName= name; 24 | itemidNo= id; 25 | itemQuantity= 1; 26 | itemPrice= 500; 27 | } 28 | /**Mutators**/ 29 | public void set_itemName(String name){ 30 | itemName= name; 31 | } 32 | public void set_itemidNo(String id){ 33 | itemidNo= id; 34 | } 35 | public void set_itemQuantity(int quantity){ 36 | itemQuantity= quantity; 37 | } 38 | public void set_itemPrice(double price){ 39 | itemPrice= price; 40 | } 41 | 42 | /**Accessors**/ 43 | public String get_itemName(){ 44 | return itemName; 45 | } 46 | public String get_itemidNo(){ 47 | return itemidNo; 48 | } 49 | public int get_itemQuantity(){ 50 | return itemQuantity; 51 | } 52 | public double get_itemPrice(){ 53 | return itemPrice; 54 | } 55 | 56 | } 57 | 58 | 59 | class Customer{ 60 | private String name; 61 | private String idNo; 62 | private double balance; 63 | private Item item; 64 | 65 | Customer(String name, String id, double balance){ 66 | this.name= name; 67 | idNo= id; 68 | this.balance=balance; 69 | } 70 | 71 | Customer(String name, String id){ 72 | this.name= name; 73 | idNo= id; 74 | this.balance=5000; 75 | } 76 | /**Mutators**/ 77 | public void set_name(String name){ 78 | this.name= name; 79 | } 80 | public void set_idNo(String id){ 81 | this.idNo= id; 82 | } 83 | 84 | /**Accessors**/ 85 | 86 | public String get_name(){ 87 | return name; 88 | } 89 | public String get_idNo(){ 90 | return idNo; 91 | } 92 | public double get_balance(){ 93 | return balance; 94 | } 95 | public Item get_item_details(){ 96 | return item; 97 | } 98 | 99 | public void print_item_details(){ 100 | System.out.println("Details:"); 101 | System.out.println("Item Name- "+item.get_itemName()); 102 | System.out.println("Item ID- "+item.get_itemidNo()); 103 | System.out.println("Item Quantity- "+item.get_itemQuantity()); 104 | System.out.println("Item Price- "+item.get_itemPrice()); 105 | } 106 | 107 | public void buyItem(Item brought_item){ 108 | if(balance<(brought_item.get_itemPrice()*brought_item.get_itemQuantity())){ 109 | System.out.println("Insufficient balance"); 110 | return; 111 | } 112 | else if(brought_item.get_itemQuantity()<2){ 113 | System.out.println("Order not valid"); 114 | } 115 | else{ 116 | item=brought_item; 117 | this.balance-=((brought_item.get_itemQuantity())*(brought_item.get_itemPrice())); 118 | print_item_details(); 119 | System.out.println("Current Balance- "+this.balance); 120 | } 121 | } 122 | } 123 | 124 | 125 | 126 | public class TestStore { 127 | public static void main(String[] args){ 128 | Scanner in = new Scanner(System.in); 129 | System.out.println("Enter the Customer name:"); 130 | String name=in.nextLine(); 131 | System.out.println("Enter the Customer id:"); 132 | String id=in.nextLine(); 133 | System.out.println("Enter the Customer Balance:"); 134 | double balance=in.nextDouble(); 135 | 136 | Customer c1= new Customer(name,id,balance); 137 | 138 | System.out.println("Item1:"); 139 | System.out.println("Enter the Item name:"); 140 | in.nextLine(); 141 | name=in.nextLine(); 142 | System.out.println("Enter the Item id:"); 143 | id=in.nextLine(); 144 | System.out.println("Enter the Item Quantity:"); 145 | int quantity=in.nextInt(); 146 | System.out.println("Enter the Item Price:"); 147 | double price=in.nextDouble(); 148 | 149 | Item item1=new Item(name,id,quantity,price); 150 | 151 | System.out.println("Item2:"); 152 | System.out.println("Enter the Item name:"); 153 | in.nextLine(); 154 | name=in.nextLine(); 155 | System.out.println("Enter the Item id:"); 156 | id=in.nextLine(); 157 | System.out.println("Enter the Item Quantity:"); 158 | quantity=in.nextInt(); 159 | System.out.println("Enter the Item Price:"); 160 | price=in.nextDouble(); 161 | 162 | Item item2=new Item(name,id,quantity,price); 163 | 164 | c1.buyItem(item1); 165 | c1.buyItem(item2); 166 | } 167 | } -------------------------------------------------------------------------------- /LAB 2/src/TestTax.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class TestTax { 4 | public static void main(String args[]){ 5 | TaxOnSalary tax1 = new TaxOnSalary(true); 6 | TaxOnSalary tax2 = new TaxOnSalary(); 7 | tax1.inputSalary(); 8 | tax2.inputSalary(); 9 | System.out.println("Tax1 "+tax1.caculateTax()); 10 | System.out.println("Tax2 "+tax2.caculateTax()); 11 | } 12 | } 13 | 14 | class TaxOnSalary{ 15 | private double salary; 16 | private boolean isPANsubmitted; 17 | 18 | //Constructors 19 | TaxOnSalary(boolean isPANsubmitted){ 20 | this.isPANsubmitted=isPANsubmitted; 21 | this.salary=1000.00; 22 | } 23 | TaxOnSalary(){ 24 | } 25 | 26 | //Accessors 27 | public double getSalary(){ 28 | return salary; 29 | } 30 | public boolean getIsPANsubmitted(){ 31 | return isPANsubmitted; 32 | } 33 | public void inputSalary(){ 34 | Scanner in = new Scanner(System.in); 35 | salary=in.nextDouble(); 36 | } 37 | 38 | public double caculateTax(){ 39 | if(salary < 180000 && isPANsubmitted == true){ 40 | return 0; 41 | } 42 | else if(salary < 180000 && isPANsubmitted == false){ 43 | return 0.05*salary; 44 | } 45 | else if( salary < 500000){ 46 | return 0.1*salary; 47 | } 48 | else if( salary < 1000000){ 49 | return 0.2*salary; 50 | } 51 | else{ 52 | return 0.3*salary; 53 | } 54 | } 55 | 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /LAB 3/bin/BOX.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/BOX.class -------------------------------------------------------------------------------- /LAB 3/bin/BOXTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/BOXTest.class -------------------------------------------------------------------------------- /LAB 3/bin/Circle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/Circle.class -------------------------------------------------------------------------------- /LAB 3/bin/ConstructorBlockExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/ConstructorBlockExample.class -------------------------------------------------------------------------------- /LAB 3/bin/MyStatic.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/MyStatic.class -------------------------------------------------------------------------------- /LAB 3/bin/Point.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/Point.class -------------------------------------------------------------------------------- /LAB 3/bin/PointTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/PointTest.class -------------------------------------------------------------------------------- /LAB 3/bin/StaticBlock.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/StaticBlock.class -------------------------------------------------------------------------------- /LAB 3/bin/StaticDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/StaticDemo.class -------------------------------------------------------------------------------- /LAB 3/bin/StaticExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/StaticExample.class -------------------------------------------------------------------------------- /LAB 3/bin/Test1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/Test1.class -------------------------------------------------------------------------------- /LAB 3/bin/TestCircle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 3/bin/TestCircle.class -------------------------------------------------------------------------------- /LAB 3/src/BOXTest.java: -------------------------------------------------------------------------------- 1 | 2 | /*public class BOXTest { 3 | public static void main(String args[]){ 4 | BOX b1 = new BOX(10,40,60); 5 | BOX b2 = new BOX(20,30,80); 6 | System.out.println(b1); 7 | System.out.println(b2); 8 | BOX.swapBoxes(b1,b2); 9 | System.out.println(b1); 10 | System.out.println(b2); 11 | } 12 | } 13 | */ 14 | /*In this the changes are not reflected in the main method because the swapping of variables is for the othe other method variables*/ 15 | 16 | public class BOXTest{ 17 | public static void main(String args[]){ 18 | BOX b1 = new BOX(10,40,60); 19 | BOX b2 = new BOX(20,30,80); 20 | System.out.println(b1); 21 | System.out.println(b2); 22 | BOX.swapBoxes(b1, b2); 23 | System.out.println(b1); 24 | System.out.println(b2); 25 | BOX temp = b1; 26 | b1 = b2; 27 | b2 = temp; 28 | System.out.println(b1); 29 | System.out.println(b2); 30 | } 31 | }//End of Main 32 | 33 | 34 | class BOX { 35 | private double length, width, height; // Instance Fields 36 | 37 | BOX(double l,double b,double h){ // Constructor Method 38 | length = l; width = b; height =h; 39 | } 40 | 41 | 42 | // Mutator methods for Length, Width and Height 43 | public void setLength(double l) { length = l;} 44 | public void setWidth(double b) { width = b;} 45 | public void setHeight(double h) { height = h;} 46 | 47 | 48 | // Accessor Methods for Length, Width and Height 49 | public double getLength() { return length;} 50 | public double getWidth() { return width; } 51 | public double getHeight() { return height;} 52 | 53 | public String toString() { 54 | return "Length:"+length+" Width:"+width+" Height:"+height; 55 | } 56 | 57 | public double area() { 58 | return 2 * (length * width + width*height + height*length); 59 | } 60 | 61 | public double volume() { 62 | return length*width*height; 63 | } 64 | 65 | public static void swapBoxes(BOX b1, BOX b2) { 66 | BOX temp = b1; b1 = b2; b2 = temp; 67 | } 68 | }// End of BOX -------------------------------------------------------------------------------- /LAB 3/src/ConstructorBlockExample.java: -------------------------------------------------------------------------------- 1 | public class ConstructorBlockExample { 2 | { 3 | System.out.println("This is first constructor block"); 4 | } 5 | public ConstructorBlockExample(){ 6 | System.out.println("This is no parameter constructor"); 7 | } 8 | 9 | public ConstructorBlockExample(String param1){ 10 | System.out.println("This is single parameter constructor"); 11 | } 12 | 13 | { 14 | System.out.println("This is second constructor block"); 15 | } 16 | 17 | public static void main(String[] args){ 18 | ConstructorBlockExample constrBlockEx = new ConstructorBlockExample(); 19 | ConstructorBlockExample constrBlockEx1 = new ConstructorBlockExample("param1"); 20 | } 21 | } 22 | 23 | //The blocks here will be implemented every time the object is instantiated, even before the actual constructor method. These are called constructor blocks and all such blocks 24 | //will have their one copy in each constructor method, so they will be implemented whenever a constructor is called 25 | -------------------------------------------------------------------------------- /LAB 3/src/PointTest.java: -------------------------------------------------------------------------------- 1 | public class PointTest { 2 | public static void main(String args[]){ 3 | // Pass By Reference 4 | Point p1 = new Point(10,20); 5 | System.out.println(p1); // See the o/p for this line, this is going to call toString() method 6 | Point.changeState(p1); 7 | System.out.println(p1); // See the o/p for this line, this is going to call toString() method 8 | 9 | // Pass By value 10 | Point p2 = new Point(100,200); 11 | System.out.println(p2); // See the o/p for this line, this is going to call toString() method 12 | Point.changeReference(p2); 13 | System.out.println(p2); // See the o/p for this line, this is going to call toString() method 14 | } // End of Method main() 15 | 16 | } 17 | 18 | 19 | class Point { 20 | 21 | private double x; // Instance field x-coordinate 22 | private double y; // Instance field y-coordinate 23 | 24 | Point(double x, double y) { 25 | this.x=x; 26 | this.y=y; 27 | } 28 | 29 | 30 | public double getX() { return this.x; } 31 | public double getY() { return this.y; } 32 | public void setX(double x) { this.x = x; } 33 | public void setY(double y) { this.y = y; } 34 | 35 | public String toString() { 36 | return "X="+x+" Y ="+y ; 37 | } 38 | 39 | public static void changeState(Point other) { 40 | other.setX(-20); 41 | // Here you can write other.x = 20 also because this code is inside the class 42 | 43 | other.setY(-20); 44 | // Here you can write other.y = 20 also because this code is inside the class 45 | // Note that changeState Method changing the state of the Passed object by using the same reference 46 | // So this change in state will be reflected in caller method also 47 | } 48 | 49 | public static void changeReference(Point other){ 50 | other = new Point(-20,-20); 51 | // Will this change be reflected in caller method? 52 | // Note that this Method has changed the reference from incoming Point object to some other Point object 53 | // So this change will not be reflected in caller method. 54 | } 55 | 56 | } // End of class Point 57 | -------------------------------------------------------------------------------- /LAB 3/src/StaticBlock.java: -------------------------------------------------------------------------------- 1 | public class StaticBlock { 2 | 3 | static int[] values = initializeArray(10); 4 | private static int[] initializeArray(int N) { 5 | int[] arr = new int[N]; 6 | for (int i = 0; i < arr.length; i++) { 7 | arr [i] = i; 8 | } 9 | return arr; 10 | } 11 | 12 | void listValues() { 13 | for (int value : values) { //Here, what exactly is happening is that the 'values' array is accessed, but before accessing its elements, the 'initializeArray' method is called 14 | System.out.println(value); 15 | } 16 | } 17 | 18 | public static void main(String[] args) { 19 | 20 | StaticBlock example = new StaticBlock(); 21 | System.out.println("\nFirst object:"); 22 | example.listValues(); 23 | 24 | values[0]=values[4]=100; 25 | 26 | example = new StaticBlock(); 27 | System.out.println("\nSecond object:"); 28 | example.listValues(); 29 | } 30 | } -------------------------------------------------------------------------------- /LAB 3/src/StaticDemo.java: -------------------------------------------------------------------------------- 1 | class StaticDemo { 2 | public static void main(String args[]){ 3 | MyStatic s1 = new MyStatic (); 4 | s1.showData(); 5 | MyStatic s2 = new MyStatic (); 6 | s2.showData(); 7 | MyStatic.b++; 8 | s1.showData(); 9 | } 10 | 11 | } 12 | 13 | class MyStatic { 14 | int a; //initialized to zero 15 | 16 | static int b; 17 | /*initialized to zero only when class is 18 | loaded not for each object created.*/ 19 | 20 | 21 | //Constructor incrementing static variable b 22 | MyStatic (){ b++; } 23 | 24 | 25 | public void showData(){ 26 | System.out.println("Value of a = "+a); 27 | System.out.println("Value of b = "+b); 28 | } 29 | 30 | //public static void increment(){ 31 | //a++; 32 | //} 33 | } -------------------------------------------------------------------------------- /LAB 3/src/StaticExample.java: -------------------------------------------------------------------------------- 1 | public class StaticExample { 2 | static { 3 | System.out.println("This is first static block"); 4 | } 5 | public StaticExample(){ 6 | System.out.println("This is constructor"); 7 | } 8 | public static String staticString = "Static Variable"; 9 | static { 10 | System.out.println("This is second static block and " 11 | + staticString); 12 | } 13 | public static void main(String[] args){ 14 | StaticExample statEx = new StaticExample(); 15 | StaticExample.staticMethod2(); 16 | } 17 | static { 18 | staticMethod(); 19 | System.out.println("This is third static block"); 20 | } 21 | public static void staticMethod() { 22 | System.out.println("This is static method"); 23 | } 24 | public static void staticMethod2() { 25 | System.out.println("This is static method2"); 26 | } 27 | } 28 | 29 | // So first all static blocks are implemented and then static main method -------------------------------------------------------------------------------- /LAB 3/src/Test1.java: -------------------------------------------------------------------------------- 1 | 2 | public class Test1 { 3 | public static void main(String args[]) { 4 | Integer I = new Integer(10); 5 | Integer J = new Integer(20); 6 | // Observe the output for following two statements carefully 7 | 8 | System.out.println(I.intValue()); 9 | System.out.println(I); 10 | // Observe the output for following two statements carefully 11 | 12 | System.out.println(J.intValue()); 13 | System.out.println(J); 14 | Integer K1 = new Integer(I.intValue()+J.intValue()); 15 | // What happens for the following statement (Auto Unboxing) 16 | 17 | Integer K2 = I + J + K1; System.out.println(K2); 18 | } 19 | } 20 | 21 | /* 22 | 23 | // CASE-2 24 | 25 | public class Test1 { 26 | public static void main(String args[]) { 27 | Integer I = 10; // what happens for this statement 28 | Integer J = 20; // what happens for this statement 29 | 30 | // Observe the output for following two statements carefully 31 | System.out.println(I.intValue()); 32 | System.out.println(I); 33 | 34 | // Observe the output for following two statements carefully 35 | System.out.println(J.intValue()); 36 | System.out.println(J); 37 | 38 | Integer K1 = new Integer(I.intValue()+J.intValue()); 39 | Integer K2 = I + J + K1; 40 | System.out.println(K2); 41 | } 42 | } 43 | */ -------------------------------------------------------------------------------- /LAB 3/src/TestCircle.java: -------------------------------------------------------------------------------- 1 | /* 2 | class Circle{ 3 | static double PI; /* variables PI is a class variable, it is not instance specific */ 4 | /* 5 | private double radius; 6 | 7 | Circle(double radius) { 8 | this.radius = radius; 9 | Circle.PI = 3.141; 10 | System.out.println("NEW CIRCLE:"); 11 | } 12 | //accessor method 13 | public double getRadius() { 14 | return radius; 15 | } 16 | 17 | //mutator method 18 | public void setRadius(double radius) { 19 | this.radius = radius; 20 | } 21 | 22 | //method to find the area 23 | public void area() { 24 | System.out.println("Area= "+(PI * radius * radius)); 25 | } 26 | 27 | //static method's are not instance specific 28 | public static void getCircumference(double radius) { 29 | // here radius variable is a local variable and PI is a class variable i.e static variable 30 | System.out.println("Circumference = " + 2 * PI * radius); 31 | } 32 | 33 | }// End of circle 34 | 35 | class TestCircle { 36 | public static void main(String args[]) { 37 | Circle c1 = new Circle(2.3); 38 | c1.area(); 39 | 40 | // accessing static method with class name 41 | Circle.getCircumference(2.3); 42 | 43 | Circle c2 = new Circle(3.45); 44 | c2.area(); 45 | 46 | // accessing static method with references is discouraged 47 | c2.getCircumference (3.45); 48 | 49 | /* 1. Make the area function as static and observe the 50 | output 51 | 2. Remove the formal argument from getCircumference() 52 | method and observe the output 53 | 3. Rename static to final and observe the error(s) and 54 | correct them *//* 55 | } // end of main 56 | } 57 | 58 | /* 1. If we make area function static, it gives compile time error because a static method cannot access non static variables*/ 59 | /* 2. Same issue, it gives compile time error because a static method cannot access non static variables*//* 60 | 61 | */ 62 | class Circle{ 63 | final double PI; // variables PI is a class variable, it is not instance specific 64 | private double radius; 65 | 66 | Circle(double radius) { 67 | this.radius = radius; 68 | this.PI = 3.141; 69 | System.out.println("NEW CIRCLE:"); 70 | } 71 | //accessor method 72 | public double getRadius() { 73 | return radius; 74 | } 75 | 76 | //mutator method 77 | public void setRadius(double radius) { 78 | this.radius = radius; 79 | } 80 | 81 | //method to find the area 82 | public void area() { 83 | System.out.println("Area= "+(PI * radius * radius)); 84 | } 85 | 86 | //static method's are not instance specific 87 | public final void getCircumference(double radius) { 88 | // here radius variable is a local variable and PI is a class variable i.e static variable 89 | System.out.println("Circumference = " + 2 * PI * radius); 90 | } 91 | 92 | }// End of circle 93 | 94 | class TestCircle { 95 | public static void main(String args[]) { 96 | Circle c1 = new Circle(2.3); 97 | c1.area(); 98 | 99 | // accessing static method with class name 100 | c1.getCircumference(2.3); 101 | 102 | Circle c2 = new Circle(3.45); 103 | c2.area(); 104 | 105 | // accessing static method with references is discouraged 106 | c2.getCircumference (3.45); 107 | 108 | /* 1. Make the area function as static and observe the 109 | output 110 | 2. Remove the formal argument from getCircumference() 111 | method and observe the output 112 | 3. Rename static to final and observe the error(s) and 113 | correct them */ 114 | } // end of main 115 | } 116 | 117 | -------------------------------------------------------------------------------- /LAB 4/bin/Address.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/Address.class -------------------------------------------------------------------------------- /LAB 4/bin/AddressList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/AddressList.class -------------------------------------------------------------------------------- /LAB 4/bin/Item.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/Item.class -------------------------------------------------------------------------------- /LAB 4/bin/Name.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/Name.class -------------------------------------------------------------------------------- /LAB 4/bin/Pokeball.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/Pokeball.class -------------------------------------------------------------------------------- /LAB 4/bin/Pokemon.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/Pokemon.class -------------------------------------------------------------------------------- /LAB 4/bin/RetailStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/RetailStore.class -------------------------------------------------------------------------------- /LAB 4/bin/RetailStore2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/RetailStore2.class -------------------------------------------------------------------------------- /LAB 4/bin/RetailStoreExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/RetailStoreExample.class -------------------------------------------------------------------------------- /LAB 4/bin/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/Student.class -------------------------------------------------------------------------------- /LAB 4/bin/StudentList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/StudentList.class -------------------------------------------------------------------------------- /LAB 4/bin/Test.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/Test.class -------------------------------------------------------------------------------- /LAB 4/bin/Test2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/Test2.class -------------------------------------------------------------------------------- /LAB 4/bin/Test3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/Test3.class -------------------------------------------------------------------------------- /LAB 4/bin/Trainer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 4/bin/Trainer.class -------------------------------------------------------------------------------- /LAB 4/src/RetailStore2.java: -------------------------------------------------------------------------------- 1 | import java.util.Vector; 2 | public class RetailStore2 { 3 | 4 | private Vector items = new Vector (); 5 | public void addItem(Item item) { 6 | items.add(item); 7 | } 8 | 9 | private double computePrice(int value) { 10 | // method to compute the price of the item. 11 | // it returns the price 12 | for (Item item: items) { 13 | if (item.getId() == value) { 14 | return item.getPrice(); 15 | } 16 | } 17 | // if item not found return -1.0 18 | return -1.0; 19 | } 20 | 21 | 22 | public static void main(String[] args) { 23 | //main method. Execution begins here 24 | RetailStore2 retailOne = new RetailStore2(); 25 | retailOne.addItem(new Item(1001, 13.50)); 26 | retailOne.addItem(new Item(1002, 18.00)); 27 | retailOne.addItem(new Item(1003, 19.50)); 28 | retailOne.addItem(new Item(1004, 25.50)); 29 | retailOne.addItem(new Item(1005, 25.50)); 30 | System.out.println("price of item id 1003 is " + retailOne.computePrice(1003)); 31 | System.out.println("price of item id 1004 is " + retailOne.computePrice(1004)); 32 | System.out.println("price of item id 1005 is " + retailOne.computePrice(1005)); 33 | System.out.println("price of item id 1006 is " + retailOne.computePrice(1006)); 34 | } 35 | } 36 | 37 | class Item { 38 | private int itemId; // ID of item 39 | private double price; // name of student 40 | 41 | public Item(int itemId, double price) { 42 | this.itemId = itemId; 43 | this.price = price; 44 | } 45 | public int getId() { 46 | return itemId; 47 | } //accessor method for itemid 48 | 49 | public double getPrice() { 50 | return price; 51 | } //accessor method for price 52 | 53 | } // End of class Item -------------------------------------------------------------------------------- /LAB 4/src/RetailStoreExample.java: -------------------------------------------------------------------------------- 1 | class RetailStore { 2 | private int[] itemId; 3 | private double[] price; 4 | private String itemName[]; 5 | 6 | /* The constructor is used here for the initialization purpose*/ 7 | public RetailStore(){ 8 | itemId = new int[] { 1001, 1002, 1003, 1004, 1005 }; 9 | //itemId = { 1001, 1002, 1003, 1004, 1005 }; wont work 10 | 11 | price = new double[] { 950.00, 750.00, 450.00, 350.00, 250.00 }; 12 | 13 | itemName = new String[] { "Yonex Tennis Racket-950", 14 | "Yonex Badminton Racket-750", 15 | "Silvers Badminton Racket-450", 16 | "Cosco Badminton shuttle-350", 17 | "Cosco Tennis Racket-250" }; 18 | } 19 | 20 | protected double computePrice(int value) { 21 | // method to compute the price of the item. it returns the price 22 | for (int i = 0; i collection = new Vector(); 78 | 79 | public static void capturePokemon(Pokemon pokemon){ 80 | Pokeball pokeball= new Pokeball(pokemon); //It creates a pokeball with a pokemon and adds to the list 81 | collection.add(pokeball); 82 | } 83 | 84 | public static Pokemon[] getPokemonWithType(String type){ 85 | Pokemon a[]= new Pokemon[collection.size()]; 86 | int j=0; 87 | for(Pokeball pokeball:collection){ 88 | if(pokeball.getPokemon().getType().equals(type)){ 89 | a[j++]=pokeball.getPokemon(); 90 | } 91 | } 92 | if(a.length==0){ 93 | return null; 94 | } 95 | return a; 96 | } 97 | 98 | public static Pokemon[] getPokemonsWithGivenTypes(String[] types){ 99 | Pokemon a[]= new Pokemon[collection.size()]; 100 | int j=0; 101 | int flag; 102 | for(Pokeball pokeball:collection){ 103 | flag=0; 104 | for(int i=0;i=minId ){ 125 | a[j++]=pokeball.getPokemon(); 126 | } 127 | } 128 | if(a.length==0){ 129 | return null; 130 | } 131 | return a; 132 | } 133 | } 134 | 135 | public class Test3{ 136 | public static Pokemon readPokemon() throws IOException{ 137 | Scanner in = new Scanner(System.in); 138 | System.out.println("Enter Pokemon Name"); 139 | String name=in.nextLine(); 140 | System.out.println("Enter Pokemon Id"); 141 | int id = in.nextInt(); 142 | in.nextLine(); 143 | System.out.println("Enter Pokemon type"); 144 | String type=in.nextLine(); 145 | System.out.println("Enter Pokemon Name Format"); 146 | int x = in.nextInt(); 147 | 148 | 149 | String NAME=null; 150 | 151 | if(x==1){ 152 | NAME = name + "," + id + "," + type; 153 | } 154 | else{ 155 | NAME = id + ";" + name + ";" + type; 156 | } 157 | 158 | Pokemon p = new Pokemon(NAME); 159 | return p; 160 | } 161 | 162 | public static void main(String args[]) throws IOException{ 163 | 164 | Pokemon p; 165 | for(int i=0;i<15;i++){ 166 | p = readPokemon(); 167 | Trainer.capturePokemon(p); 168 | } 169 | 170 | Pokemon list1[]=Trainer.getPokemonWithType("Fire"); 171 | for(int i=0;i240){ 26 | return 240*super.getsalary(); 27 | } 28 | else{ 29 | return this.hours_worked*super.getsalary(); 30 | } 31 | } 32 | } 33 | 34 | class HourlyWorker extends worker{ 35 | private int hours_worked; 36 | public HourlyWorker(String name,double salary_rate,int hours_worked){ 37 | super(name,salary_rate); 38 | this.hours_worked = hours_worked; 39 | } 40 | public double computePay(){ 41 | if(hours_worked>60){ 42 | return 60*super.getsalary(); 43 | } 44 | else{ 45 | return this.hours_worked*super.getsalary(); 46 | } 47 | } 48 | } 49 | 50 | public class TestWorker{ 51 | public static void main(String args[]){ 52 | System.out.println(new FulltimeWorker("RAJESH",100,58).computePay()); 53 | System.out.println(new HourlyWorker("RAJESH",50,80).computePay()); 54 | } 55 | } -------------------------------------------------------------------------------- /LAB 6/bin/BinaryInterface.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/BinaryInterface.class -------------------------------------------------------------------------------- /LAB 6/bin/BinaryTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/BinaryTest.class -------------------------------------------------------------------------------- /LAB 6/bin/CompareByBoth.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/CompareByBoth.class -------------------------------------------------------------------------------- /LAB 6/bin/CompareByCenter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/CompareByCenter.class -------------------------------------------------------------------------------- /LAB 6/bin/CompareByRadius.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/CompareByRadius.class -------------------------------------------------------------------------------- /LAB 6/bin/Movable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/Movable.class -------------------------------------------------------------------------------- /LAB 6/bin/MovableCircle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/MovableCircle.class -------------------------------------------------------------------------------- /LAB 6/bin/MovablePoint.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/MovablePoint.class -------------------------------------------------------------------------------- /LAB 6/bin/OneComplement.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/OneComplement.class -------------------------------------------------------------------------------- /LAB 6/bin/Package2/Movable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/Package2/Movable.class -------------------------------------------------------------------------------- /LAB 6/bin/Package2/MovablePoint.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/Package2/MovablePoint.class -------------------------------------------------------------------------------- /LAB 6/bin/Package2/Outer$Inner.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/Package2/Outer$Inner.class -------------------------------------------------------------------------------- /LAB 6/bin/Package2/Outer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/Package2/Outer.class -------------------------------------------------------------------------------- /LAB 6/bin/Package2/TestMovable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/Package2/TestMovable.class -------------------------------------------------------------------------------- /LAB 6/bin/SignedMagnitude.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/SignedMagnitude.class -------------------------------------------------------------------------------- /LAB 6/bin/TestMovableSecond.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/TestMovableSecond.class -------------------------------------------------------------------------------- /LAB 6/bin/TwoComplement.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 6/bin/TwoComplement.class -------------------------------------------------------------------------------- /LAB 6/src/BinaryTest.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | interface BinaryInterface{ 4 | public void toBinary(int n); 5 | } 6 | 7 | class SignedMagnitude implements BinaryInterface{ 8 | ArrayList a = new ArrayList(); 9 | int temp; 10 | public void toBinary(int x){ 11 | int n = Math.abs(x); 12 | if(x<0){ 13 | a.add(1); 14 | } 15 | else{ 16 | a.add(0); 17 | } 18 | while(n!=0){ 19 | temp=n%2; 20 | a.add(1,temp); 21 | n=n/2; 22 | } 23 | int k=a.size(); 24 | for(int i=0;i<(8-k);i++){ 25 | a.add(1,0); 26 | } 27 | System.out.println(a); 28 | } 29 | } 30 | 31 | class OneComplement implements BinaryInterface{ 32 | ArrayList a = new ArrayList(); 33 | int temp; 34 | public void toBinary(int x){ 35 | int n = Math.abs(x); 36 | while(n!=0){ 37 | temp=n%2; 38 | a.add(0,temp); 39 | n=n/2; 40 | } 41 | int k=a.size(); 42 | for(int i=0;i<(8-k);i++){ 43 | a.add(0,0); 44 | } 45 | // CODE FOR CONVERTING INTO 1's COMPLEMENT 46 | //Also notice that One's complement is taken for the normal form, not the signed magnitude form 47 | 48 | for(int z=0;z a = new ArrayList(); 62 | int temp; 63 | public void toBinary(int x){ 64 | int n = Math.abs(x); 65 | while(n!=0){ 66 | temp=n%2; 67 | a.add(0,temp); 68 | n=n/2; 69 | } 70 | 71 | int k=a.size(); 72 | for(int i=0;i<(8-k);i++){ 73 | a.add(0,0); 74 | } 75 | // CODE FOR CONVERTING INTO 2's COMPLEMENT 76 | //Also notice that Two's complement is taken for the normal form, not the signed magnitude form 77 | int flag=0; 78 | for(int i=a.size()-1;i>=0;i--){ 79 | if(flag==1){ 80 | if(a.get(i)==0){ 81 | a.set(i,1); 82 | } 83 | else{ 84 | a.set(i,0); 85 | } 86 | } 87 | if(a.get(i)==1){ 88 | flag=1; 89 | } 90 | } 91 | System.out.println(a); 92 | } 93 | } 94 | 95 | public class BinaryTest{ 96 | public static void main(String args[]){ 97 | SignedMagnitude v1 = new SignedMagnitude(); 98 | v1.toBinary(-16); 99 | OneComplement v2 = new OneComplement(); 100 | v2.toBinary(-16); 101 | TwoComplement v3 = new TwoComplement(); 102 | v3.toBinary(-16); 103 | } 104 | } 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /LAB 6/src/Package2/Outer.java: -------------------------------------------------------------------------------- 1 | package Package2; 2 | 3 | class Outer{ 4 | 5 | Inner i1 = new Inner(); // Object is created in the class itself 6 | private String s = "Outer string"; // Outer instance variable 7 | void getS(){ System.out.println(s); } 8 | void getInnerS(){ System.out.println(i1.s); } 9 | class Inner{ 10 | //Inner instance variable, initialized 11 | private String s = "Inner string"; 12 | void getS(){ 13 | System.out.println(s); 14 | } 15 | void getOuterS(){ 16 | System.out.println(Outer.this.s); 17 | } 18 | } 19 | 20 | 21 | public static void main(String[] args){ 22 | Outer o = new Outer(); 23 | //can also be new Outer().new Inner(); 24 | Outer.Inner oi = o.new Inner(); 25 | o.getS(); 26 | oi.getS(); 27 | o.getInnerS(); 28 | oi.getOuterS(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LAB 6/src/Package2/TestMovable.java: -------------------------------------------------------------------------------- 1 | package Package2; 2 | 3 | public class TestMovable { 4 | public static void main(String[] args) { 5 | Movable m1 = new MovablePoint(5, 5); // upcast 6 | System.out.println(m1); 7 | m1.moveDown(); 8 | System.out.println(m1); 9 | m1.moveRight(); 10 | System.out.println(m1); 11 | } 12 | } 13 | interface Movable { 14 | // abstract methods to be implemented by the subclasses 15 | public void moveUp(); 16 | public void moveDown(); 17 | public void moveLeft(); 18 | public void moveRight(); 19 | } 20 | 21 | 22 | class MovablePoint implements Movable { 23 | // Private membet variables 24 | private int x, y; // (x, y) coordinates of the point 25 | 26 | // Constructor 27 | public MovablePoint(int x, int y) { 28 | this.x = x; 29 | this.y = y; 30 | } 31 | 32 | public String toString() { 33 | return "Point at (" + x + "," + y + ")"; 34 | } 35 | // Implement abstract methods defined in the interface Movable 36 | 37 | public void moveUp() { 38 | y++; 39 | } 40 | 41 | public void moveDown() { 42 | y--; 43 | } 44 | 45 | public void moveLeft() { 46 | x--; 47 | } 48 | 49 | public void moveRight() { 50 | x++; 51 | } 52 | } 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /LAB 6/src/TestMovableSecond.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | interface Movable { 3 | // abstract methods to be implemented by the subclasses 4 | public void moveUp(); 5 | public void moveDown(); 6 | public void moveLeft(); 7 | public void moveRight(); 8 | } 9 | 10 | class MovablePoint implements Movable, Comparable { 11 | 12 | int x, y, xSpeed, ySpeed; 13 | 14 | // Constructor 15 | public MovablePoint(int x, int y, int xSpeed, int ySpeed) { 16 | this.x = x; 17 | this.y = y; 18 | this.xSpeed = xSpeed; 19 | this.ySpeed = ySpeed; 20 | } 21 | 22 | public String toString() { 23 | return "Point at (" + x + "," + y + ") XSPEED: "+ xSpeed+" YSPEED: "+ySpeed; 24 | } 25 | // Implement abstract methods defined in the interface Movable 26 | 27 | public void moveUp() { 28 | y-=ySpeed; 29 | } 30 | 31 | public void moveDown() { 32 | y+=ySpeed; 33 | } 34 | 35 | public void moveLeft() { 36 | x-=xSpeed; 37 | } 38 | 39 | public void moveRight() { 40 | x+=xSpeed; 41 | } 42 | 43 | public int compareTo (MovablePoint point){ 44 | if(this.x==point.x){ 45 | return (int)(this.y-point.y); 46 | } 47 | else{ 48 | return (int)(this.x-point.x); 49 | } 50 | } 51 | } 52 | 53 | class MovableCircle implements Movable { 54 | // instance variables 55 | private MovablePoint center; // can use center.x, center.y directly because they are package accessible 56 | private int radius; 57 | 58 | //accessor for radius 59 | public int getRadius(){ 60 | return radius; 61 | } 62 | public MovablePoint getCenter(){ 63 | return center; 64 | } 65 | 66 | // Constructor 67 | public MovableCircle(int x, int y, int xSpeed, int ySpeed, int radius) { 68 | // Call the MovablePoint's constructor to allocate the center instance. 69 | 70 | center = new MovablePoint(x, y, xSpeed, ySpeed); 71 | this.radius = radius; 72 | } 73 | 74 | // Implement abstract methods declared in the interface Movable 75 | 76 | public void moveUp() { 77 | center.y -= center.ySpeed; 78 | } 79 | 80 | public void moveDown() { 81 | center.y += center.ySpeed; 82 | } 83 | 84 | public void moveLeft() { 85 | center.x -= center.xSpeed; 86 | } 87 | 88 | public void moveRight() { 89 | center.x += center.xSpeed; 90 | } 91 | 92 | public String toString() { 93 | return "Center at (" + center.x + "," + center.y + ") XSPEED: "+ center.xSpeed+" YSPEED: "+center.ySpeed+" RADIUS: "+this.radius; 94 | } 95 | 96 | 97 | } 98 | 99 | //no need of comparable and comparator here but still for practice I have included 100 | 101 | class CompareByRadius implements Comparator{ 102 | public int compare(MovableCircle m1, MovableCircle m2){ 103 | return (int)(m1.getRadius()-m2.getRadius()); 104 | } 105 | } 106 | 107 | class CompareByCenter implements Comparator{ 108 | public int compare(MovableCircle m1, MovableCircle m2){ 109 | return (int)(m1.getCenter().compareTo(m2.getCenter())); 110 | } 111 | } 112 | class CompareByBoth implements Comparator{ 113 | public int compare(MovableCircle m1, MovableCircle m2){ 114 | if(m1.getRadius()==m2.getRadius()) 115 | return (int)(m1.getCenter().compareTo(m2.getCenter())); 116 | else 117 | return (int)(m1.getRadius()-m2.getRadius()); 118 | } 119 | } 120 | 121 | public class TestMovableSecond { 122 | public static void main(String[] args) { 123 | Movable m1 = new MovablePoint(5, 6, 10,20); // upcast 124 | System.out.println(m1); 125 | m1.moveLeft(); 126 | System.out.println(m1); 127 | 128 | Movable m2 = new MovableCircle(2, 1, 2, 20, 25); // upcast 129 | System.out.println(m2); //toString method will be called from 130 | m2.moveRight(); 131 | System.out.println(m2); 132 | //WE CAN USE COMPARATOR AND COMPARABLE NOW TO SORT ARRAY OF MOVABLE CIRCLES AND MOVABLE POINTS 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /LAB 7/bin/Account.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 7/bin/Account.class -------------------------------------------------------------------------------- /LAB 7/bin/ArrayListDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 7/bin/ArrayListDemo.class -------------------------------------------------------------------------------- /LAB 7/bin/Bank.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 7/bin/Bank.class -------------------------------------------------------------------------------- /LAB 7/bin/DriverCode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 7/bin/DriverCode.class -------------------------------------------------------------------------------- /LAB 7/bin/Movie$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 7/bin/Movie$1.class -------------------------------------------------------------------------------- /LAB 7/bin/Movie$1EnglishMovie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 7/bin/Movie$1EnglishMovie.class -------------------------------------------------------------------------------- /LAB 7/bin/Movie$Bookable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 7/bin/Movie$Bookable.class -------------------------------------------------------------------------------- /LAB 7/bin/Movie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 7/bin/Movie.class -------------------------------------------------------------------------------- /LAB 7/bin/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 7/bin/Student.class -------------------------------------------------------------------------------- /LAB 7/bin/TestStudentList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 7/bin/TestStudentList.class -------------------------------------------------------------------------------- /LAB 7/src/ArrayListDemo.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class ArrayListDemo { 4 | public static void main(String[] args) { 5 | //Creating a new ArrayList 6 | ArrayList arlTest = new ArrayList(); 7 | //Size of arrayList 8 | System.out.println("Size of ArrayList at creation: " +arlTest.size()); 9 | //Lets add some elements to it 10 | arlTest.add("B"); 11 | arlTest.add("I"); 12 | arlTest.add("T"); 13 | arlTest.add("S"); 14 | //Recheck the size after adding elements 15 | System.out.println("Size of ArrayList after adding elements: "+arlTest.size()); 16 | //Display all contents of ArrayList 17 | System.out.println("List of all elements: " + arlTest); 18 | //Remove some elements from the list 19 | arlTest.remove("B"); 20 | System.out.println("See contents after removing one element: " + arlTest); 21 | //Remove element by index 22 | arlTest.remove(2); 23 | System.out.println("See contents after removing element by index: " + arlTest); 24 | //Check size after removing elements 25 | System.out.println("Size of arrayList after removing elements: " + arlTest.size()); 26 | System.out.println("List of all elements after removing elements: " + arlTest); 27 | //Check if the list contains "T" 28 | System.out.println(arlTest.contains("T")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LAB 7/src/DriverCode.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Account { 3 | private long acctNumber; 4 | private double balance; 5 | private String name; 6 | 7 | //Constructor 8 | public Account(long acctNumber, double balance, String name){ 9 | this.acctNumber=acctNumber; 10 | this.balance= balance; 11 | this.name= name; 12 | } 13 | 14 | //Accessors 15 | public long getAcctNumber(){ 16 | return acctNumber; 17 | } 18 | public double getBalance(){ 19 | return balance; 20 | } 21 | public String getName(){ 22 | return name; 23 | } 24 | 25 | //Mutators 26 | public void setAcctNumber(long acctNumber){ 27 | this.acctNumber=acctNumber; 28 | } 29 | public void setBalance(double balance){ 30 | this.balance= balance; 31 | } 32 | public void setName(String name){ 33 | this.name= name; 34 | } 35 | 36 | // ToString 37 | public String toString(){ 38 | return "Account: "+name+" Balance: "+balance+" Account No. "+acctNumber; 39 | } 40 | } 41 | 42 | class Bank{ 43 | private ArrayList accts = new ArrayList(); 44 | int maxActive; 45 | public boolean addAccount (Account newone){ 46 | if(accts.size()>30){ 47 | return false; 48 | } 49 | else{ 50 | accts.add(newone); 51 | return true; 52 | } 53 | } 54 | public boolean removeAccount (long acctnum){ 55 | Account a; 56 | Iterator itr= accts.iterator(); 57 | while(itr.hasNext()){ 58 | a=itr.next(); 59 | if(a.getAcctNumber()==acctnum){ 60 | itr.remove(); 61 | return true; 62 | } 63 | } 64 | return false; 65 | } 66 | public double deposit(long acctnum, double amount) { 67 | Account a; 68 | Iterator itr= accts.iterator(); 69 | while(itr.hasNext()){ 70 | a=itr.next(); 71 | if(a.getAcctNumber()==acctnum){ 72 | a.setBalance(a.getBalance()+amount); 73 | return a.getBalance(); 74 | } 75 | } 76 | return -1; 77 | } 78 | public double withdraw(long acctnum, double amount) { 79 | Account a; 80 | Iterator itr= accts.iterator(); 81 | while(itr.hasNext()){ 82 | a=itr.next(); 83 | if(a.getAcctNumber()==acctnum){ 84 | a.setBalance(a.getBalance()-amount); 85 | return a.getBalance(); 86 | } 87 | } 88 | return -1; 89 | } 90 | 91 | public String toString(){ 92 | String str=""; 93 | for(int i=0;i studentList = new ArrayList(); 32 | // add elements to the array list 33 | studentList.add(new Student("Ramesh","Male",18)); 34 | studentList.add(new Student("Reeta","Female",19)); 35 | studentList.add(new Student("Seema","Female",18)); 36 | studentList.add(new Student("Suresh","Male",20)); 37 | System.out.println("Original contents of studentList:"); 38 | Iterator itr = studentList.iterator(); 39 | while(itr.hasNext()) { 40 | Object element = itr.next(); 41 | System.out.print(element +"\n"); 42 | } 43 | 44 | System.out.println(); 45 | 46 | // modify objects being iterated 47 | ListIterator litr = studentList.listIterator(); 48 | while(litr.hasNext()) { 49 | Student element = (Student)litr.next(); 50 | if(element.getGender().equals("Male")){ 51 | element.setName("Mr."+element.getName()); 52 | } 53 | else{ 54 | element.setName("Miss."+element.getName()); 55 | } 56 | litr.set(element); 57 | } 58 | System.out.println("Modified contents of studentList: "); 59 | itr = studentList.iterator(); 60 | while(itr.hasNext()) { 61 | Object element = itr.next(); 62 | System.out.print(element + "\n"); 63 | 64 | } 65 | System.out.println(); // now, display the list backwards 66 | System.out.println("Modified list backwards: "); 67 | while(litr.hasPrevious()) { 68 | Object element = litr.previous(); 69 | System.out.print(element + "\n"); 70 | } 71 | System.out.println(); 72 | } 73 | } -------------------------------------------------------------------------------- /LAB 8/bin/test_bank/Bank.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 8/bin/test_bank/Bank.class -------------------------------------------------------------------------------- /LAB 8/bin/test_bank/BankAccount.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 8/bin/test_bank/BankAccount.class -------------------------------------------------------------------------------- /LAB 8/bin/test_bank/BankApp.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 8/bin/test_bank/BankApp.class -------------------------------------------------------------------------------- /LAB 8/bin/test_bank/InsufficientFundsException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB 8/bin/test_bank/InsufficientFundsException.class -------------------------------------------------------------------------------- /LAB 8/src/test_bank/Bank.java: -------------------------------------------------------------------------------- 1 | package test_bank; 2 | 3 | /** 4 | * A Bank can hold up to a fixed number of BankAccounts. 5 | * @author cs302 6 | */ 7 | public class Bank { 8 | 9 | /** The array of BankAccount objects. */ 10 | private BankAccount[] accounts; 11 | 12 | /** The first available account index. */ 13 | private int firstAvailableAcc; 14 | 15 | /** 16 | * Creates a bank that can have up to numAccounts accounts. 17 | */ 18 | public Bank(int numAccounts) { 19 | this.accounts = new BankAccount[numAccounts]; 20 | this.firstAvailableAcc = 0; 21 | } 22 | 23 | /** 24 | * Adds the given BankAccount to the bank. If the bank is full 25 | * an error message is printed and the bank is unchanged. 26 | * @param account The account to add 27 | */ 28 | public void add(BankAccount account) { 29 | if (firstAvailableAcc == accounts.length) { 30 | System.out.println("Bank is full. No account added."); 31 | return; 32 | } 33 | this.accounts[firstAvailableAcc] = account; 34 | firstAvailableAcc++; 35 | } 36 | 37 | /** 38 | * Returns the bank account with the given account number. 39 | * If no such account exists, null is returned. 40 | * @param acctNumber The account number 41 | * @return The account 42 | */ 43 | public BankAccount find(int acctNumber) { 44 | for (int i = 0; i < firstAvailableAcc; i++) { 45 | if (accounts[i].getAccountNumber() == acctNumber) { 46 | return accounts[i]; 47 | } 48 | } 49 | 50 | return null; 51 | } 52 | 53 | /** 54 | * Returns a string representation of the bank. 55 | * The format is one account per line. 56 | */ 57 | public String toString() { 58 | if (firstAvailableAcc == 0) return "NONE"; 59 | 60 | String result = ""; 61 | for (int i = 0; i < firstAvailableAcc; i++) { 62 | result += accounts[i].getAccountNumber() + " "; 63 | result += accounts[i].getBalance() + "\n"; 64 | // Note that we don't make use of BankAccount's toString because 65 | // we don't want to have dollar signs ($) as part of the String 66 | // representation for the Bank. 67 | } 68 | 69 | return result; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /LAB 8/src/test_bank/BankAccount.java: -------------------------------------------------------------------------------- 1 | package test_bank; 2 | 3 | /** 4 | * A class to represent a single bank account. 5 | * @author cs302 6 | */ 7 | public class BankAccount { 8 | 9 | private double balance; 10 | private int accountNumber; 11 | 12 | //************ 13 | //* TASK 2 * 14 | //************ 15 | /** 16 | * Constructor 17 | * @param initialBalance the initial balance of the BankAccount 18 | * @param accountNumber The account number to associate with this 19 | * BankAccount. Must be a 5 digit integer. 20 | */ 21 | public BankAccount(double initialBalance, int accountNumber) { 22 | 23 | if (initialBalance < 0) { 24 | throw new IllegalArgumentException( 25 | "Accounts with a negative balance cannot be created!"); 26 | } 27 | 28 | //TODO TASK 2: add code here to throw an exception if the account 29 | // number isn't 5 digits. 30 | 31 | if (accountNumber < 10000||accountNumber > 99999) { 32 | throw new IllegalArgumentException( 33 | "Invalid Account number!"); 34 | } 35 | 36 | balance = initialBalance; //This statement will not execute if an exception is thrown because the exception is caught remotely and the program will come out of this function 37 | this.accountNumber = accountNumber; //same case applies here 38 | 39 | } 40 | 41 | /** 42 | * Deposits money into the BankAccount 43 | * 44 | * @param amount the amount to deposit 45 | */ 46 | public void deposit(double amount) { 47 | if (amount < 0) { 48 | throw new IllegalArgumentException( 49 | "Don't deposit negative amounts!"); 50 | } 51 | balance = balance + amount; //same case applies here 52 | } 53 | 54 | //************ 55 | //* TASK 3 * 56 | //************ 57 | /** 58 | * Withdraws money from the BankAccount 59 | * 60 | * @param amount the amount to withdraw 61 | */ 62 | //TODO TASK 3: add code to throw our new exception if an overdraw is attempted 63 | public void withdraw(double amount) throws InsufficientFundsException{ 64 | if (amount < 0) { 65 | throw new IllegalArgumentException( 66 | "Don't withdraw a negative amount!"); 67 | } 68 | if(amount > balance){ 69 | throw new InsufficientFundsException("You can't withdraw more than you have!"); 70 | } 71 | balance = balance - amount; //same case applies here 72 | } 73 | 74 | /** 75 | * Gets the current balance of the BankAccount 76 | * 77 | * @return the current balance 78 | */ 79 | public double getBalance() { 80 | return balance; 81 | } 82 | 83 | /** 84 | * Gets the account number of the BankAccount 85 | * @return the account number 86 | */ 87 | public int getAccountNumber() { 88 | return accountNumber; 89 | } 90 | 91 | /** 92 | * Returns a string representation this BankAccount in 93 | * the following format, e.g. 12345 $100.52 where 12345 94 | * is the account number, and 100.52 is the balance. 95 | */ 96 | public String toString () { 97 | return "" + accountNumber + " $" + balance; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /LAB 8/src/test_bank/BankApp.java: -------------------------------------------------------------------------------- 1 | package test_bank; 2 | 3 | import java.util.Scanner; 4 | 5 | /** 6 | * A class to test the BankAccount class. Uses a menu-driven system to 7 | * allow the user to interactively test the BankAccount class. 8 | * @author cs302 9 | */ 10 | public class BankApp { 11 | 12 | private static Scanner stdin = new Scanner(System.in); 13 | 14 | public static void main(String[] args){ 15 | Bank bank = new Bank(100); 16 | 17 | //************ 18 | //* TASK 1 * 19 | //************ 20 | //TODO TASK 1: note that the account is initially null 21 | BankAccount account = null; 22 | int choice; 23 | double amount; 24 | int accountNumber; 25 | 26 | do { 27 | choice = getUserChoice(); 28 | switch (choice) { 29 | case 1: 30 | amount = getAmount(); 31 | accountNumber = getAccountNumber(); 32 | try { 33 | account = new BankAccount(amount, accountNumber); 34 | bank.add(account); 35 | System.out.println("Account info: " + account + "\n"); 36 | } catch (IllegalArgumentException exception) { 37 | System.out.println("\n*****ERROR*****: " + exception.getMessage() + "\n"); 38 | } 39 | break; 40 | 41 | //***************** 42 | //* TASKS 1 & 2 * 43 | //***************** 44 | //TODO TASK 1: Note the first catch clause 45 | //TODO TASK 2: Note the second catch clause 46 | case 2: 47 | amount = getAmount(); 48 | try { 49 | account.deposit(amount); 50 | System.out.println("Account info: " + account + "\n"); 51 | } catch (NullPointerException exception) { 52 | System.out.println("\n*****ERROR*****: " + "No account! First find account" 53 | + " or create a new account\n"); 54 | } catch (IllegalArgumentException exception) { 55 | System.out.println("\n*****ERROR*****: " + exception.getMessage() + "\n"); 56 | } 57 | break; 58 | 59 | //***************** 60 | //* TASKS 1 & 3 * 61 | //***************** 62 | //TODO TASK 1: add a similar NullPointerException catch clause below 63 | //TODO TASK 3: add a InsufficientFunds catch clause below 64 | case 3: 65 | amount = getAmount(); 66 | try { 67 | account.withdraw(amount); 68 | System.out.println("Account info: " + account + "\n"); 69 | } catch (IllegalArgumentException exception) { 70 | System.out.println("\n*****ERROR*****: " + exception.getMessage() + "\n"); 71 | } catch (NullPointerException exception) { 72 | System.out.println("\n*****ERROR*****: " + "No account! First find account" 73 | + " or create a new account\n"); 74 | } catch(InsufficientFundsException exception){ 75 | System.out.println("\n*****ERROR*****: " + exception.getMessage()+ "\n"); 76 | } 77 | break; 78 | 79 | case 4: 80 | accountNumber = getAccountNumber(); 81 | BankAccount found = bank.find(accountNumber); 82 | if (found != null) { 83 | account = found; 84 | System.out.println("Account info: " + account + "\n"); 85 | } else { 86 | System.out.println("\n*****ERROR*****: Bank account " + accountNumber 87 | + " not found!\n"); 88 | } 89 | break; 90 | 91 | case 5: 92 | System.out.print("\n\nThe accounts: \n" + bank + "\n\n"); 93 | break; 94 | } 95 | } while (choice != 0); 96 | System.out.println("\n\nGoodbye!"); 97 | } 98 | 99 | private static int getUserChoice() { 100 | int choice; 101 | do { 102 | choice = -1; 103 | System.out.println("Menu Options:"); 104 | System.out.println("0) Quit"); 105 | System.out.println("1) Create new account"); 106 | System.out.println("2) Deposit to current account"); 107 | System.out.println("3) Withdraw from current account"); 108 | System.out.println("4) Find account"); 109 | System.out.println("5) Print all accounts"); 110 | 111 | System.out.print("Enter your choice (0 - 5): "); 112 | try { 113 | choice = Integer.parseInt(stdin.nextLine()); 114 | } catch (NumberFormatException exception) { 115 | } 116 | if (choice < 0 || choice > 5) 117 | System.out.println("Invalid choice"); 118 | } while (choice < 0 || choice > 5); 119 | return choice; 120 | } 121 | 122 | private static double getAmount() { 123 | System.out.print("Enter the amount: $ "); 124 | double amount = -1; 125 | boolean valid = false; 126 | do { 127 | try { 128 | amount = Double.parseDouble(stdin.nextLine()); 129 | valid = true; 130 | } catch (NumberFormatException exception) { 131 | System.out.println("Make sure you enter a valid double!"); 132 | } 133 | } while (!valid); 134 | return amount; 135 | } 136 | 137 | private static int getAccountNumber() { 138 | System.out.print("Enter the account number: "); 139 | int amount = -1; 140 | boolean valid = false; 141 | do { 142 | try { 143 | amount = Integer.parseInt(stdin.nextLine()); 144 | valid = true; 145 | } catch (NumberFormatException exception) { 146 | System.out.println("Make sure you enter a valid integer!"); 147 | } 148 | } while (!valid); 149 | return amount; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /LAB 8/src/test_bank/InsufficientFundsException.java: -------------------------------------------------------------------------------- 1 | package test_bank; 2 | 3 | 4 | /** 5 | * An InsufficientFundsException is thrown when a BankAccount determines 6 | * that it does not contain enough funds to perform a transaction (withdrawal). 7 | * 8 | * @author cs302 9 | */ 10 | public class InsufficientFundsException extends Exception { 11 | 12 | public InsufficientFundsException(String message) { 13 | super(message); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LAB 8/src/test_bank/ThermostatDriver.java: -------------------------------------------------------------------------------- 1 | /** IMPORTANT POINT: EXECUTION OF A METHOD/TRY BLOCK STOPS AFTER AN EXEPTION IS THROWN AUTOMATICALLY/USING THROW KEYWORD 2 | * + EVEN FROM OTHER FUNCTION WHICH IS CALLED FROM A TRY BLOCK**/ 3 | 4 | // Exeception Classes 5 | class InvalidInitialTemperatureException extends Exception { 6 | private int temp; 7 | InvalidInitialTemperatureException(int temp) { 8 | this.temp = temp; 9 | } 10 | public String toString() { 11 | return "InvalidInitialTemperatureException : " + this.temp; 12 | } 13 | } 14 | /************************************************************************************/ 15 | 16 | class HighTemperatureException extends Exception { 17 | 18 | HighTemperatureException() {} 19 | public String toString() { 20 | return "\nHigh Temperature Exception : Cooling down\n"; 21 | } 22 | } 23 | /************************************************************************************/ 24 | 25 | class LowTemperatureException extends Exception { 26 | LowTemperatureException() {} 27 | public String toString() { 28 | return "\nLow Temperature Exception : Heating\n"; 29 | } 30 | } 31 | /************************************************************************************/ 32 | 33 | 34 | // Class Thermostat 35 | class Thermostat { 36 | private int temperature; 37 | static final int LOWER_LIM = 50; 38 | static final int UPPER_LIM = 100; 39 | 40 | Thermostat(int initTemp) throws InvalidInitialTemperatureException { 41 | if ((initTemp >= LOWER_LIM) && (initTemp <= UPPER_LIM)) { 42 | this.temperature = initTemp; 43 | System.out.println("Thermostat Starting. With Initial Temprature:" + temperature); 44 | } 45 | else { 46 | throw new InvalidInitialTemperatureException(initTemp); 47 | } 48 | } 49 | 50 | public void startThermostat() throws HighTemperatureException { 51 | System.out.println("*****************Thermostat Started*************************"); 52 | while(true){ 53 | System.out.println(temperature); 54 | if(temperature!=UPPER_LIM){ 55 | temperature++; 56 | try{ 57 | Thread.sleep(1000); 58 | } 59 | catch(InterruptedException e){System.out.println("Thread Interrupted");} 60 | } 61 | else{ 62 | throw new HighTemperatureException(); //If I write anything below this, that is unreachable because the program will stop the function execution if an exception is thrown as the exception is caught remotely 63 | } 64 | 65 | } 66 | /* 67 | This method increments (+1) and displays the temperature of the Thermostat after every 68 | 1000 ms. When the temperature reaches the UPPER_LIM it raises 69 | HighTemperatureException. 70 | */ 71 | 72 | } 73 | public void stopThermostat() throws LowTemperatureException { 74 | System.out.println("*****************Thermostat Stopping*************************"); 75 | while(true){ 76 | System.out.println(temperature); 77 | if(temperature!=LOWER_LIM){ 78 | temperature--; 79 | try{ 80 | Thread.sleep(1000); 81 | } 82 | catch(InterruptedException e){System.out.println("Thread Interrupted");} 83 | } 84 | else{ 85 | throw new LowTemperatureException(); //If I write anything below this, that is unreachable because the program will stop the function execution if an exception is thrown as the exception is caught remotely 86 | } 87 | } 88 | /* 89 | This method decrements (-1) and displays the temperature of the Thermostat after every 90 | 1000 ms. When the temperature reaches the LOWER_LIM it raises 91 | LowTemperatureException. 92 | */ 93 | 94 | } 95 | } 96 | /************************************************************************************/ 97 | 98 | 99 | public class ThermostatDriver { 100 | public static void main(String[] args) throws InvalidInitialTemperatureException { 101 | Thermostat t = new Thermostat(55); 102 | boolean flag=true; 103 | int z=0; 104 | //Setting the initial temperature of the thermostat as 55. 105 | 106 | while (flag) { 107 | 108 | try { 109 | t.startThermostat(); 110 | } catch (HighTemperatureException e) { 111 | System.out.println(e); 112 | } 113 | 114 | try { 115 | t.stopThermostat(); 116 | } catch (LowTemperatureException ex) { 117 | System.out.println(ex); 118 | } 119 | z++; 120 | if(z==2){ 121 | return; 122 | } 123 | } 124 | 125 | }// End of main() 126 | } // End of ThermostatDriver 127 | -------------------------------------------------------------------------------- /LAB 8/src/test_bank/accounts.txt: -------------------------------------------------------------------------------- 1 | 12345 20000.35 2 | 12000 3.12 3 | 13134 10000000.00 4 | 10000 23 5 | 99999 2000.00 6 | 24786 67.67 7 | 88889 600.10 8 | -------------------------------------------------------------------------------- /LAB 8/src/test_bank/badinput.txt: -------------------------------------------------------------------------------- 1 | 12323 23 2 | 10000 3 | 12345 100000 4 | 00001 -23.00 5 | -------------------------------------------------------------------------------- /LAB TEST/bin/ComputeThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB TEST/bin/ComputeThread.class -------------------------------------------------------------------------------- /LAB TEST/bin/CreateThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB TEST/bin/CreateThread.class -------------------------------------------------------------------------------- /LAB TEST/bin/OnlineMain$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB TEST/bin/OnlineMain$1.class -------------------------------------------------------------------------------- /LAB TEST/bin/OnlineMain$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB TEST/bin/OnlineMain$2.class -------------------------------------------------------------------------------- /LAB TEST/bin/OnlineMain$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB TEST/bin/OnlineMain$3.class -------------------------------------------------------------------------------- /LAB TEST/bin/OnlineMain$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB TEST/bin/OnlineMain$4.class -------------------------------------------------------------------------------- /LAB TEST/bin/OnlineMain$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB TEST/bin/OnlineMain$5.class -------------------------------------------------------------------------------- /LAB TEST/bin/OnlineMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB TEST/bin/OnlineMain.class -------------------------------------------------------------------------------- /LAB TEST/bin/QuadraticEquation.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB TEST/bin/QuadraticEquation.class -------------------------------------------------------------------------------- /LAB TEST/bin/QuadraticEquationQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB TEST/bin/QuadraticEquationQueue.class -------------------------------------------------------------------------------- /LAB TEST/src/OnlineMain.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | import java.awt.*; 3 | import javax.swing.*; 4 | import java.awt.event.*; 5 | 6 | class QuadraticEquation 7 | { 8 | private int quadNo; 9 | private int a; 10 | private int b; 11 | private int c; 12 | private boolean isSolved; 13 | private boolean isRootsPossible; 14 | private static int noofobjectsCreated = 0; 15 | private double root1; 16 | private double root2; 17 | 18 | QuadraticEquation(int a, int b, int c) 19 | { 20 | this.a = a; 21 | this.b = b; 22 | this.c = c; 23 | isSolved= false; 24 | noofobjectsCreated++; 25 | quadNo = noofobjectsCreated; 26 | } 27 | public synchronized void computeRoots() 28 | { 29 | if( b*b - 4*a*c < 0) 30 | { 31 | isRootsPossible = false; 32 | root1 = root2 = Double.NEGATIVE_INFINITY; 33 | isSolved = true; 34 | return; 35 | } 36 | double disc = Math.sqrt(b*b - 4*a*c); 37 | root1 = (-b+disc)/(2*a); 38 | root2 = (-b-disc)/(2*a); 39 | isRootsPossible = true; 40 | isSolved = true; 41 | return; 42 | } 43 | public synchronized String toString() 44 | { 45 | return "Quadratic Equation No:="+quadNo+"A:= "+a+"B:= "+b+"C:= "+c+"Root 1:="+root1+"Root 2:="+root2; 46 | } 47 | public synchronized boolean getisSolved() 48 | { 49 | return isSolved; 50 | } 51 | public synchronized int getNoofObjects() 52 | { 53 | return noofobjectsCreated; 54 | } 55 | }// End of class QuadraticEquation 56 | 57 | class QuadraticEquationQueue 58 | { 59 | private QuadraticEquation[] quadQueue = new QuadraticEquation[10]; 60 | private int tail; 61 | private int head; 62 | private int size; 63 | QuadraticEquationQueue() 64 | { 65 | head = tail = size =0; 66 | } 67 | public synchronized QuadraticEquation remove() throws InterruptedException 68 | { 69 | while(size == 0) wait(); 70 | QuadraticEquation quad = quadQueue[head]; 71 | head++; 72 | size--; 73 | if(head == quadQueue.length) 74 | head =0; 75 | notifyAll(); 76 | return quad; 77 | } 78 | public synchronized void add(QuadraticEquation quad) throws InterruptedException 79 | { 80 | while(size == quadQueue.length) wait(); 81 | quadQueue[tail] = quad; 82 | tail++; 83 | size++; 84 | if(tail == quadQueue.length) 85 | tail = 0; 86 | notifyAll(); 87 | } 88 | public synchronized boolean isFull() 89 | { 90 | return size == quadQueue.length; 91 | } 92 | public synchronized boolean isEmpty() 93 | { 94 | return size == 0; 95 | } 96 | }// End of class QuadraticEquationQueue 97 | 98 | 99 | class CreateThread extends Thread 100 | { 101 | private JTextField T1; 102 | private JTextField T2; 103 | private JTextField T3; 104 | private QuadraticEquationQueue queue; 105 | private boolean suspendFlag = false; 106 | private JLabel label; 107 | private JLabel queueFull; 108 | CreateThread(JTextField T1,JTextField T2,JTextField T3,QuadraticEquationQueue queue,JLabel label, JLabel queuefullLabel) 109 | { 110 | this.T1 = T1; 111 | this.T2 = T2; 112 | this.T3 = T3; 113 | this.queue = queue; 114 | this.label = label; 115 | this.queueFull = queuefullLabel; 116 | } 117 | public void run() 118 | { 119 | try 120 | { 121 | while(true) 122 | { 123 | synchronized(this) 124 | { 125 | while(suspendFlag) 126 | wait(); 127 | try 128 | { 129 | int a = Integer.parseInt(T1.getText()); 130 | int b = Integer.parseInt(T2.getText()); 131 | int c = Integer.parseInt(T3.getText()); 132 | if( a == 0 ) continue; 133 | QuadraticEquation quad = new QuadraticEquation(a,b,c); 134 | queue.add(quad); 135 | String text = "Total No of Equations Created:"+quad.getNoofObjects(); 136 | System.out.println(text); 137 | System.out.println(); 138 | label.setText(text); 139 | if(queue.isFull()) 140 | queueFull.setForeground(Color.green); 141 | else 142 | queueFull.setForeground(Color.black); 143 | } 144 | catch(NumberFormatException ne) {} 145 | } 146 | Thread.sleep(150); 147 | } 148 | } 149 | catch(InterruptedException e){} 150 | }// End of Run Method 151 | 152 | public void mysuspend() 153 | { 154 | suspendFlag = true; 155 | } 156 | public synchronized void myresume() 157 | { 158 | suspendFlag = false; 159 | notify(); 160 | } 161 | }// End of CreateThread class 162 | 163 | 164 | class ComputeThread extends Thread 165 | { 166 | private int threadNo; 167 | private QuadraticEquationQueue queue; 168 | private JLabel[] displayLabels = new JLabel[10]; 169 | private JLabel totalCountLabel; 170 | private JLabel countLabel; 171 | private int count; 172 | private JLabel queueEmpty; 173 | private boolean suspendFlag; 174 | 175 | private static int totalCount=0; 176 | 177 | ComputeThread(QuadraticEquationQueue queue,JLabel[] labels,JLabel totalcountLabel, JLabel L,JLabel queueEmpty,int no) 178 | { 179 | this.queue = queue; 180 | displayLabels = labels; 181 | this.totalCountLabel = totalcountLabel; 182 | countLabel = L; 183 | this.queueEmpty = queueEmpty; 184 | threadNo = no; 185 | count = 0; 186 | } 187 | public void run() 188 | { 189 | try 190 | { 191 | while(true) 192 | { 193 | synchronized(this) 194 | { 195 | while(suspendFlag) 196 | wait(); 197 | QuadraticEquation quad = queue.remove(); 198 | if(queue.isEmpty()) 199 | queueEmpty.setForeground(Color.green); 200 | else 201 | queueEmpty.setForeground(Color.black); 202 | 203 | boolean flag = quad.getisSolved(); 204 | 205 | if(flag) continue; 206 | 207 | int a = totalCount % 10; 208 | quad.computeRoots(); 209 | displayLabels[a].setText(quad.toString()); 210 | totalCount++; 211 | totalCountLabel.setText("Total No of Equations Solved :"+totalCount); 212 | count++; 213 | countLabel.setText("By Thread " + threadNo +" :"+count); 214 | Thread.sleep(150); 215 | } 216 | } 217 | } 218 | catch(InterruptedException e){System.out.println(e);} 219 | }// End of Run Method 220 | 221 | public void mysuspend() 222 | { 223 | suspendFlag = true; 224 | } 225 | public synchronized void myresume() 226 | { 227 | suspendFlag = false; 228 | notify(); 229 | } 230 | }// End of CreateThread class 231 | 232 | class OnlineMain 233 | { 234 | static Random r1 = new Random(20); 235 | 236 | static boolean createThreadStarted = false; 237 | static boolean createThreadStopped = false; 238 | static boolean createThreadResumed = false; 239 | 240 | static boolean computeThreadStarted = false; 241 | static boolean computeThreadStopped = false; 242 | static boolean computeThreadResumed = false; 243 | 244 | 245 | 246 | 247 | public static void main(String args[]) 248 | { 249 | JFrame frame = new JFrame("QuadraticFrame"); 250 | Container c1 = frame.getContentPane(); 251 | c1.setLayout(new BoxLayout(c1,BoxLayout.X_AXIS)); 252 | 253 | JPanel leftPanel = new JPanel(); 254 | leftPanel.setLayout(new BoxLayout(leftPanel,BoxLayout.Y_AXIS)); 255 | 256 | JLabel label1 = new JLabel("QUEUE FULL"); 257 | leftPanel.add(label1); 258 | 259 | JButton b1 = new JButton("START"); 260 | JButton b2 = new JButton("STOP"); 261 | 262 | JLabel L1 = new JLabel("A ="); 263 | JLabel L2 = new JLabel("B ="); 264 | JLabel L3 = new JLabel("C ="); 265 | JLabel L4 = new JLabel("Total No of Equations Created:"+0); 266 | 267 | JPanel btnPanel = new JPanel(); 268 | btnPanel.add(b1); 269 | btnPanel.add(b2); 270 | 271 | final JTextField T1 = new JTextField(6); 272 | final JTextField T2 = new JTextField(6); 273 | final JTextField T3 = new JTextField(6); 274 | 275 | T1.setText("0"); 276 | T2.setText("0"); 277 | T3.setText("0"); 278 | 279 | JPanel P1 = new JPanel(); 280 | P1.add(L1); 281 | P1.add(T1); 282 | 283 | JPanel P2 = new JPanel(); 284 | P2.add(L2); 285 | P2.add(T2); 286 | 287 | JPanel P3 = new JPanel(); 288 | P3.add(L3); 289 | P3.add(T3); 290 | 291 | JPanel P4 = new JPanel(); 292 | P4.add(L4); 293 | 294 | leftPanel.add(btnPanel); 295 | leftPanel.add(P1); 296 | leftPanel.add(P2); 297 | leftPanel.add(P3); 298 | leftPanel.add(P4); 299 | 300 | 301 | 302 | JPanel rightPanel = new JPanel(); 303 | rightPanel.setLayout(new BoxLayout(rightPanel,BoxLayout.Y_AXIS)); 304 | 305 | JLabel L20 = new JLabel("QUEUE EMPTY"); 306 | rightPanel.add(L20); 307 | 308 | JPanel P21 = new JPanel(); 309 | JButton b3 = new JButton("START"); 310 | JButton b4 = new JButton("STOP"); 311 | P21.add(b3); 312 | P21.add(b4); 313 | 314 | 315 | JLabel[] resultLabels = new JLabel[10]; 316 | for(int i=0;i<10;i++) 317 | resultLabels[i] = new JLabel(); 318 | 319 | JPanel P22 = new JPanel(); 320 | P22.setLayout(new BoxLayout(P22,BoxLayout.Y_AXIS)); 321 | for(int i=0;i<10;i++) 322 | P22.add(resultLabels[i]); 323 | 324 | JLabel L21 = new JLabel("Total No Of Equations Solved:"+0); 325 | P22.add(L21); 326 | 327 | JLabel L22 = new JLabel("By Thread 1:"+0); 328 | P22.add(L22); 329 | 330 | JLabel L23 = new JLabel("By Thread 2:"+0); 331 | P22.add(L23); 332 | 333 | JLabel L24 = new JLabel("By Thread 3:"+0); 334 | P22.add(L24); 335 | 336 | rightPanel.add(P21); 337 | rightPanel.add(P22); 338 | 339 | c1.add(leftPanel); 340 | c1.add(rightPanel); 341 | frame.setSize(400,600); 342 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 343 | frame.setVisible(true); 344 | 345 | 346 | 347 | 348 | ActionListener listener = new ActionListener() 349 | { 350 | public void actionPerformed(ActionEvent ae) 351 | { 352 | Integer a = r1.nextInt(20); 353 | Integer b = r1.nextInt(20); 354 | Integer c = r1.nextInt(20); 355 | T1.setText(a.toString()); 356 | T2.setText(b.toString()); 357 | T3.setText(c.toString()); 358 | return; 359 | } 360 | }; 361 | final Timer timer = new Timer(100,listener); 362 | final QuadraticEquationQueue queue = new QuadraticEquationQueue(); 363 | final CreateThread createThread1 = new CreateThread(T1,T2,T3,queue,L4,label1); 364 | 365 | final ComputeThread computeT1 = new ComputeThread(queue,resultLabels,L21,L22,L20,1); 366 | final ComputeThread computeT2 = new ComputeThread(queue,resultLabels,L21,L23,L20,2); 367 | final ComputeThread computeT3 = new ComputeThread(queue,resultLabels,L21,L24,L20,3); 368 | 369 | 370 | 371 | b1.addActionListener(new ActionListener() 372 | { 373 | public void actionPerformed(ActionEvent ae) 374 | { 375 | if(!createThreadStarted) 376 | { 377 | createThread1.start(); 378 | createThreadStarted = true; 379 | timer.start(); 380 | return; 381 | } 382 | if(createThreadStopped) 383 | { 384 | createThread1.myresume(); 385 | createThreadResumed = true; 386 | createThreadStopped = false; 387 | timer.restart(); 388 | } 389 | } 390 | }); 391 | 392 | b2.addActionListener(new ActionListener() 393 | { 394 | public void actionPerformed(ActionEvent ae) 395 | { 396 | if(createThreadResumed || createThreadStarted) 397 | { 398 | createThread1.mysuspend(); 399 | createThreadStopped = true; 400 | createThreadResumed = false; 401 | timer.stop(); 402 | } 403 | } 404 | }); 405 | 406 | b3.addActionListener(new ActionListener() 407 | { 408 | public void actionPerformed(ActionEvent ae) 409 | { 410 | if(!computeThreadStarted) 411 | { 412 | computeT1.start(); 413 | computeT2.start(); 414 | computeT3.start(); 415 | computeThreadStarted = true; 416 | return; 417 | } 418 | if(computeThreadStopped) 419 | { 420 | computeT1.myresume(); 421 | computeT2.myresume(); 422 | computeT3.myresume(); 423 | computeThreadResumed = true; 424 | computeThreadStopped = false; 425 | } 426 | } 427 | }); 428 | 429 | b4.addActionListener(new ActionListener() 430 | { 431 | public void actionPerformed(ActionEvent ae) 432 | { 433 | if(computeThreadStarted || computeThreadResumed) 434 | { 435 | computeT1.mysuspend(); 436 | computeT2.mysuspend(); 437 | computeT3.mysuspend(); 438 | computeThreadStopped = true; 439 | computeThreadResumed = false; 440 | } 441 | } 442 | }); 443 | 444 | 445 | 446 | } 447 | } 448 | -------------------------------------------------------------------------------- /LAB_01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB_01.pdf -------------------------------------------------------------------------------- /LAB_02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB_02.pdf -------------------------------------------------------------------------------- /LAB_03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB_03.pdf -------------------------------------------------------------------------------- /LAB_04.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB_04.pdf -------------------------------------------------------------------------------- /LAB_05.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB_05.pdf -------------------------------------------------------------------------------- /LAB_06.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB_06.pdf -------------------------------------------------------------------------------- /LAB_07.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB_07.pdf -------------------------------------------------------------------------------- /LAB_08.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB_08.pdf -------------------------------------------------------------------------------- /LAB_09.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB_09.pdf -------------------------------------------------------------------------------- /LAB_10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB_10.pdf -------------------------------------------------------------------------------- /LAB_11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/LAB_11.pdf -------------------------------------------------------------------------------- /Lab 11/Washing Machine.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivankit-Gaind/Object-Oriented-Programming-Lab-Solutions/1e9a96efa4f8a54f59b396b10ab325616e88bfc0/Lab 11/Washing Machine.rar -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Object-Oriented-Programming-Lab-Solutions 2 | This repository contains the solutions to the labsheets and the labtests of the course Object Oriented Programming in BITS Pilani. All the codes are written in JAVA. 3 | --------------------------------------------------------------------------------