BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI
SOFTWARE DEVELOPMENT & EDUCATIONAL TECHNOLOGY UNIT
SDET C102, CORE JAVA
LAB-2 : 21/09/07

1.      Create a class called Calculator and write another class called CalculatorDemo (contains main method). Provide support for following methods in the Calculator class

Prototypes:
int add(int , int) ; int substract(int, int); int multiply(int, int); int divide(int, int);

Create an instance of Calculator and then invoke the above methods from CalculatorDemo.

2.      ---> Create a package called shapes. Now write a class called Point (belongs to package shape) which represents a point in 2D-space. It has two fields x and y. Write a parametrized constructor to initialize these values(do not provide default constructor).
---> Now write another class called Circle (belongs to package shapes) which has a field of type Point (to represent the center of circle) and another field radius. Write a parametrized constructor to initalize all fields of circle. Now write a method in this class called isInside() which takes a point as parameter and returns true if that point is inside the circle or false otherwise.
---> Now write main method (in CircleDemo class), create a circle and invoke isInside() method by passing a parameter to it and print the return value.

we will have Three classes Point, Circle and CircleDemo (contains main method)
Point(int x, int y){ } //parametrized constructor
Circle(Point centre, int radius){ } //parametrized constructor
boolean isInside(Point p)

CircleDemo doesn’t belong to shapes package.

We can pass Objects also as parameters to methods in the same way we pass primitive types like int, char etc.,

3.      Write a class called Gen which contains an instance variable called id (say of type int). Now whenever an object is created, id has to be assigned a unique value. This has to be assigned in incremental fashion. Do not set this id manually after creation of the object. Do not use parameterized constructors .

Object created first should be given 1 as id and object created second should be given 2 and so on...