Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 61

Project Report CORE JAVA

Under the guidance : Mr. Arvind Kalyan

Made by: KASHIKA DUGGAL

Roll no.: 1727697

Branch: CSE-C

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

ACKNOWLEDGEMENT

It was a great opportunity for me to have studied at Hartron . I am


extremely grateful to those who have shared their expertise and
knowledge with me and without whom the completion of this project
would have been virtually impossible.

Firstly, I would like to thank my project guide MR. ARVIND , who has
been a constant source of inspiration for me during the completion of
this project.

I am indebted to all staff members of Hartron for their valuable support


and cooperation during the entire tenure of this project. Not to forget all
those who have kept our spirit surging and helped me in delivering my
best.

The acknowledgement will not be complete without a vote of thanks to


all other people who helped me in one way or the other for completion
of this project.

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

INDEX

 INTODUCTION TO CORE JAVA


 DECISION MAKING STATEMENTS
 LOOPS
 INPUT IN JAVA
 PYRAMIDS
 CALENDER
 OBJECT AND CLASSES
 INHERITANCE
 CONSTRUCTORS
 OVER-RIDING
 STRINGS
 POLYMORPHISM
 MULTI-THREADING
 APPLETS
 EVENT-HANDLING
 AWT(Abstract Window Toolkit)

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

CORE-JAVA

Introduction to Java:

Java is an object oriented language. It is developed by James Gosling t


Sun Microsystems. Java program are platform independent. They can be
run on any operating system with any type of processor. As long as Java
interpreter is available on that system. Java code is ‘Write Once ,Run
Anywhere’(WORA). JVM(Java Virtual Machine) executes java code.

Java used:

1. JSP: Used to create web applications like PHP, JSP(Java Server Pages
) used with normal HTML tags to create dynamic web pages.
2. Applets: Another type of Java program. Used to add features to
Web Browser.
3. J2EE(Java 2 Enterprise Edition):Used to transfer data based on XML
documents between one another.
4. Java Beans: It is reusable software component. Easily assemble to
create a new and advance application.
5. Mobile: Games and services build in java. All Nokia , Vodaphone
using Java technology.

Types of Java Application:

1. Web application: Used to create server-side web application.


Example:jsp,jsf,servlet are used.
2. Standalone application: it is a desktop application. Need to install
on every machine or platform.
Example: media player, antivirus.

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

3. Enterprise application: distributed in nature. Advantage of high


level security, load balance and clustering.EJB is used for it.
4. Mobile application:used to create mobile apps. Currently Java ME is
used.Java 2 used for google application development.

Facts about JAVA:

1. Object oriented.
2. Platform independent.
3. Simple and Secure.
4. Architectural neutral.
5. Portable.
6. Robust in nature.
7. Multi-threaded.
8. Interpreted java code into machine language.
9. High performance.

10.Distributed and dynamic in nature.

DECISION MAKING STATEMAENTS:

The decision making statements allow to choose the set-of- instructions


for execution depending upon an expression’s truth value. They are as
following:

1. If Statement: An if statement tests a particular condition evaluates


to true, then that statement is executed.

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

Program 1:Write a program of If Example.

class IfExample
{
public static void main(String[]args)
{
int age=20;
if(age>18)
{
System.out.println("age is greater than 18");
}}}
Output:

2. If-else statement: An if-else statement tests the If condition. If the


condition is true then it is executed. If it is false then else-
statement will be executed.

Program 2:Write a program of IfElse Example.

class IfelseExample
{
public static void main(String[]args)

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

{
int a=13;
if(a%2==0)
{
System.out.println("even number");
}
else
{
System.out.println("odd number");
}}}
Output:

3. If-else-if statement: In this statement the expressions are


evaluated from top to downward. As soon as the expression is
evaluated to be true, the statement associated with it is executed
and the rest of the ladder is bypassed. If none of the expression is
true then the final else gets executed.

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

Pogram 3:Write a program of IfElseIf Example:

class IfelseifExample
{
public static void main(String[]args)
{
int marks=97;
if(marks<50)
{
System.out.println("fail");
}
else if(marks>=50&&marks<60)
{
System.out.println("D grade");
}
else if(marks>=60&&marks<70)
{
System.out.println("C grade");
}
else if(marks>=70&&marks<80)
{
System.out.println("B grade");
}
else if(marks>=80&&marks<90)
{
System.out.println("A grade");
}
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

else if(marks>=90&&marks<100)
{
System.out.println("A++ grade");
}
else
{
System.out.println("Invalid");
}}}
Output:

4. Switch Statement: This statement successively tests the value of an


expression against the list of integer or character constants. When
the match is found the statement associated with that constant are
executed.

Program 4:Write a program of Switch Example

class SwitchExample
{
public static void main(String[]args)

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

{int number=20;
switch(number)
{
case 10:System.out.println("10");
break;
case 20:System.out.println("20");
break;
case 30:System.out.println("30");
break;
default:System.out.println("not in 10,20,30");
}}}
Output:

LOOPS: There may be a situation, when you need to execute a block of


code several number of times. The first statement in a function is
executed first, followed by the second, and so on. They are as follows:

1. FOR LOOP : The For loop has all it’s loop-control elements are
gathered in one place, means the initialization, condition and
increment or decrement are in one place.

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

Program 1:Write a program of For Loop.

class ForExample
{
public static void main(String[]args)
{
for(int i=1;i<=10;i++)
{
System.out.println(i);
}}}
Output:

2. FOR-EACH LOOP: It is used for array. It works on elements based on


index. It return element one by one in the defined variable.

Program 2:Write a program of For-Each Loop.

class ForeachExample

{
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

public static void main(String[]args)

int arr[]={12,23,34,45,56,67,78,89};

for(int i:arr)

System.out.println(i);

}}}

Output:

3. DO-WHILE LOOP: It is a exit control loop. It evaluates it’s text-


expression at the bottom of the loop after executing its loop-body
statements. This means that the do-while loop always executes at
least once.

Program 3:Write a program of Do-while loop.

class DowhileExample
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

public static void main(String[]args)

int i=1;

do{

System.out.println(i);

i++;

while(i<=6);

}}

Output:

4. WHILE LOOP: This loop is a entry-controlled loop. A loop control


variable should be initialised before the loop begins. The loop variable
should be updated inside the body of while loop.
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

Program 4:Write a program of while loop of reversing of numbers.

class Reverse

public static void main(String[]args)

int number=1234;

int reversed=0;

int temp=0;

while(number>0)

temp=number%10;

reversed=reversed*10+temp;

number=number/10;

System.out.println("reversed number is:"+reversed);

}}

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

INPUT:

Program 1:Write a program of input data.

import java.util.Scanner;

class Input

public static void main(String[]args)

Scanner sc=new Scanner(System.in);

System.out.println("enter hobbies");

String hobbies=sc.next();

System.out.println("your hobbies are"+hobbies);

}}

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

Program 2:Write a program of Fibonacci series.

class Fibo

public static void main(String[]args)

int limit=5;

long[]series=new long[limit];

series[0]=0;

series[1]=1;

for(int i=2;i<limit;i++)

series[i]=series[i-1]+series[i-2];

System.out.println("fibonacci series upto"+limit);

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

for(int i=0;i<limit;i++)

System.out.println(series[i]+"");

}}}

Output:

PYRAMIDS:

Program1:Write a program of pyramid pattern.

class Pyramid1

public static void main(String[]args)

for(int i=1;i<=5;i++)
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

for(int j=1;j<=i;j++)

System.out.print("*");

System.out.println("");

}}}

Output:

Program2:Write a program of Pyramid pattern.

class Pyramid2

public static void main(String[]args)

for(int i=1;i<=4;i++)

for(int j=1;j<=i;j++)
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

System.out.print("*");

System.out.println("");

for(int i=1;i<=4;i++)

for(int j=3;j>=i;j--)

System.out.print("*");

System.out.println("");

}}}

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

CALENDAR:

Program 1: Write a program to calculate current timestamp.

import java.time.*;

class Cal2

public static void main(String[]args)

Instant timestamp=Instant.now();

System.out.println("\n Current timestamp"+timestamp+"\n");

}}

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

OBJECT AND CLASSES :

 OBJECT: They are instances of class, which are used to access data
members and member functions of a class.
 CLASS: A class is a collection of objects having similar features. It is
used for better management of data and its security.

Program 1: Write a program to create multiple objects and store


information in it through reference variable.

class Student

int id;

String name;

class Test1

public static void main(String[]args)

Student s1=new Student();

Student s2=new Student();

s1.id=101;

s1.name="Kashika";

s2.id=102;

s2.name="krishna";
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

System.out.println(s1.id+" "+s1.name);

System.out.println(s2.id+" "+s2.name);

}}

Output:

Program 2: Write a program of Bank data.

class Account

int acc_no;

String name;

float amount;

void insert(int a,String n,float amt)

acc_no=a;

name=n;

amount=amt;

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

void deposit(float amt)

amount=amount+amt;

System.out.println(amt+"deposited");

void withdraw(float amt)

if(amount<amt)

System.out.println("insufficient amount");

else

amount=amount+amt;

System.out.println(amt+"withdraw");

void checkBalance()

System.out.println("balance is:"+amount);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

void display()

System.out.println(acc_no+" "+name+" "+amount);

}}

class TestAccount

public static void main(String[]args)

Account a1=new Account();

a1.insert(832345,"kashika",10000);

a1.display();

a1.checkBalance();

a1.deposit(40000);

a1.checkBalance();

a1.withdraw(1500);

a1.checkBalance();

}}

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

INHERITANCE : It is the capability of one class to inherit the properties


from another class. It provides reusability of code. It has child class and
parent class. The class that extends the feature of another class is called
the child or derived class. The class whose properties are inherited is
called parent class.

Program 1: Write a program of inheritance.

class Teacher

String destination="Teacher";

String collegeName="CGC";

void does()

System.out.println("teaching");
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

}}

public class MathTeacher extends Teacher

String mainSubject="Math";

public static void main(String[]args)

MathTeacher m=new MathTeacher();

System.out.println(m.collegeName);

System.out.println(m.destination);

System.out.println(m.mainSubject);

m.does();

}}

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

CONSTRUCTORS: When we create the object of subclass by default it


invokes default constructor of super class. Super keyword refers to super
class, immediately above the calling class in the hierarchy. The
constructor has same name as parent class.

Program 1: Write a program of constructor.

class A

A()

System.out.println("constructor of A");

}}

class B extends A

B()

System.out.println("constructor of B");

public static void main(String[]args)

new B();

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

}}

Output:

OVER-RIDING: It is declare the same method in child class which is


already present in parent class.

Program 1: Write a program of over-riding.

class A

A()

System.out.println("constructor of A");
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

void display()

System.out.println("A method");

}}

class B extends A

B()

System.out.println("constructor of B");

void display()

System.out.println("B method");

super.display();

public static void main(String[]args)

B b=new B();

b.display();

}}
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

Output:

STRINGS: Strings are sequence of characters. In Java the strings have


been implemented like objects and also as variable. This is done so the
operations can be performed.

Program 1: Write a program of string concatenate.

class A

public static void main(String[]args)

String myString="this is my string";

String yourString="\nthis is your string";

String ourString=myString+yourString;

ourString=myString.concat(yourString);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

System.out.println(ourString);

}}

Output:

Program 2: Write a program of String Indexing.

class A

public static void main(String[]args)

{String myString="hello";

System.out.println(myString.charAt(3));

}}

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

POLYMORPHISM : Polymorphism is the ability for a message or data to


be processed in more than one form. It is the concept that supports the
capability of an object of a class to behave differently in response to an
action. It is of two types:

 Runtime-polymorphism.
 Compile time-polymorphism.

Program 1: Write a program of Runtime Polymorphism.

class A

void display()

System.out.println("class A");
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

}}

class B extends A

void display()

System.out.println("class B");

public static void main(String[]args)

A a=new B();

a.display();

}}

Output:

Program 2: Write a program of Compile time Polymorphism.

class Sample

{
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

public void display(int x,int y)

System.out.println("value of x:"+x);

System.out.println("value of y:"+y);

public void display(int x)

System.out.println("value of x:"+x);

public static void main(String[]args)

Sample s=new Sample();

s.display(5,6);

s.display(7);

}}

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

MULTI-THREADING: It is done to run multiple threads or sub-programs at


once. The program of multi-threading in Java runs more than one thread
simultaneously.this thread is a very light-weight process.

Program 1: Write a program of multi-threading.

public class CheckState extends Thread

public void run()

System.out.println("run method");

public static void main(String[]args)

CheckState t1=new CheckState();

CheckState t2=new CheckState();

System.out.println("t1 State"+t1.getState());

System.out.println("t2 State"+t2.getState());

t1.start();

System.out.println("t1 State"+t1.getState());

System.out.println("t2 State"+t2.getState());

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

t2.start();

System.out.println("t1 State"+t1.getState());

System.out.println("t2 State"+t2.getState());

}}

Output:

APPLETS: It is Java program that runs in the Browser. It can work with
HTML.

Program 1: Write a program to draw oval, rectangle.

import java.applet.Applet;

import java.awt.*;

public class Demo extends Applet

public void paint(Graphics g)


Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

g.setColor(Color.pink);

g.drawString("welcome",50,50);

g.drawLine(20,30,20,300);

g.drawRect(70,100,30,30);

g.drawRect(170,100,30,30);

g.drawOval(70,200,30,30);

}}

Html:

<html>

<body>

<applet code="Demo.class"

width="300"

height="300">

</applet>

</body>

</html>

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

EVENT-HANDLING:

Program 1: Write a program to get welcome after click the button.

Prm click button:

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

public class Event extends Applet implements ActionListener

{Button b;

TextField tf;

public void init()


Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

{tf=new TextField();

tf.setBounds(20,40,150,20);

b=new Button("click");

b.setBounds(80,150,60,50);

add(b);add(tf);

b.addActionListener(this);

setLayout(null);

public void actionPerformed(ActionEvent e)

{tf.setText("Welcome to core java");

}}

Html:

<html>

<body>

<applet code="Event.class"

width="300"

height="300">

</applet>

</body>

</html>

Output:
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

Program 2: Write a program of painting.

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

public class Mouse extends Applet implements MouseMotionListener

public void init()

addMouseMotionListener(this);

setBackground(Color.Green);

public void mouseDragged(MouseEvent e)


Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

Graphics g=getGraphics();

g.setColor(Color.white);

g.fillOval(e.getX(),e.getY(),5,5);

public void mouseMoved(MouseEvent e)

}}

Html:

<html>

<body>

<applet code="Mouse.class"

width="300"

height="300">

</applet>

</body>

</html>

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

Program 3: Write a program of digital clock.

import java.applet.*;

import java.awt.*;

import java.util.*;

import java.text.*;

public class Digital extends Applet implements Runnable

Thread t=null;

int hours=0,minutes=0,seconds=0;

String timeString="";

public void init()

{setBackground(Color.blue);

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

public void start()

{t=new Thread(this);

t.start();

public void run()

try{

while(true)

{Calendar cal=Calendar.getInstance();

hours=cal.get(Calendar.HOUR_OF_DAY);

if(hours>12)

hours-=12;

minutes=cal.get(Calendar.MINUTE);

seconds=cal.get(Calendar.SECOND);

SimpleDateFormat formatter=new SimpleDateFormat("hh.mm.ss");

Date date=cal.getTime();

timeString=formatter.format(date);

repaint();

t.sleep(100);

}}
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

catch(Exception e){}

public void paint(Graphics g)

{g.setColor(Color.yellow);

g.drawString(timeString,50,50);

}}

Html:

<html>

<body>

<applet code="Digital.class"

width="300"

height="300">

</applet>

</body>

</html>

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

ABSTRACT WINDOW TOOLKIT(AWT): It contains large number classes


and methods that allow us to create and manage GUI applications. It is
designed to provide a common set of tools for GUI design. AWT is the
foundation upon which swing is made. Swing is set of GUI interfaces that
extends the AWT. Nowadays, Swing has most popularity then AWT, as it
is light weight in nature.

Program 1: Write a program of installing frame class.

import java.awt.*;

public class A

{A()

Frame fm=new Frame();

Label lb=new Label("Welcome to java Graphics");

fm.add(lb);

fm.setSize(300,300);

fm.setVisible(true);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

public static void main(String[]args)

A a=new A();

}}

Output:

Program 2: Write a program of AWT example by inheritance.

import java.awt.*;

class A extends Frame

A()

{Button b=new Button("click");

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

b.setBounds(30,100,80,30);

add(b);

setSize(300,300);

setLayout(null);

setVisible(true);

public static void main(String[]args)

A a=new A();

}}

Output:

Program 3: Write a program of Analog clock.

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

import java.applet.*;

import java.awt.*;

import java.util.*;

import java.text.*;

public class Analog extends Applet implements Runnable

int width,height;

Thread t=null;

boolean threadSuspended;

int hours=0,minutes=0,seconds=0;

String timeString="";

public void init()

width=getSize().width;

height=getSize().height;

setBackground(Color.pink);

public void start()

if(t==null)

{
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

t=new Thread(this);

t.setPriority(Thread.MIN_PRIORITY);

threadSuspended=false;

t.start();

else

{if(threadSuspended)

{threadSuspended=false;

synchronized(this)

notify();

}}

}}

public void stop()

threadSuspended=true;

public void run()

{try

while(true)
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

{Calendar cal=Calendar.getInstance();

hours=cal.get(Calendar.HOUR_OF_DAY);

if(hours>12)hours-=12;

minutes=cal.get(Calendar.MINUTE);

seconds=cal.get(Calendar.SECOND);

SimpleDateFormat formatter=new
SimpleDateFormat("hh:mm:ss",Locale.getDefault());

Date date=cal.getTime();

timeString=formatter.format(date);

if(threadSuspended)

{synchronized(this)

while(threadSuspended)

{wait();

}}}

repaint();

t.sleep(100);

}}

catch(Exception e)

}}
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

void drawHand(double angle,int radius,Graphics g)

angle-=0.5*Math.PI;

int x=(int)(radius*Math.cos(angle));

int y=(int)(radius*Math.sin(angle));

g.drawLine(width/2,height/2,width/2+x,height/2+y);

void drawWedge(double angle,int radius,Graphics g)

angle-=0.5*Math.PI;

int x=(int)(radius*Math.cos(angle));

int y=(int)(radius*Math.sin(angle));

angle+=2*Math.PI/3;

int x2=(int)(5*Math.cos(angle));

int y2=(int)(5*Math.sin(angle));

angle+=2*Math.PI/3;

int x3=(int)(5*Math.cos(angle));

int y3=(int)(5*Math.sin(angle));

g.drawLine(width/2+x2,height/2+y2,width/2+x,height/2+y);

g.drawLine(width/2+x3,height/2+y3,width/2+x,height/2+y);

g.drawLine(width/2+x2,height/2+y2,width/2+x3,height/2+y3);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

public void paint(Graphics g)

{g.setColor(Color.white);

drawWedge(2*Math.PI*hours/12,width/5,g);

drawWedge(2*Math.PI*minutes/60,width/3,g);

drawWedge(2*Math.PI*seconds/60,width/2,g);

g.setColor(Color.blue);

g.drawString(timeString,10,height-10);

}}

Html:

<html>

<body>

<applet code="Analog.class"

width="300"

height="300">

</applet>

</body>

</html>

Output:

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

PROJECT

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

CALCULATOR:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Cal extends Applet implements ActionListener
{String s,s1,s2,s3,s4;
int a,b,c;
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b11,b12,b13,b14,b15,b16,b17,b18;
TextField tf1;
Label lb1;
public void init()
{
lb1=new Label("result");
lb1.setBounds(50,40,100,20);
tf1=new TextField();
tf1.setBounds(150,40,200,30);
b1=new Button("7");
b1.setBounds(150,80,50,20);
b2=new Button("8");
b2.setBounds(200,80,50,20);
b3=new Button("9");
b3.setBounds(250,80,50,20);
b4=new Button("+");
b4.setBounds(300,80,50,20);
b5=new Button("4");
b5.setBounds(150,120,50,20);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

b6=new Button("5");
b6.setBounds(200,120,50,20);
b7=new Button("6");
b7.setBounds(250,120,50,20);
b8=new Button("-");
b8.setBounds(300,120,50,20);
b9=new Button("1");
b9.setBounds(150,160,50,20);
b11=new Button("2");
b11.setBounds(200,160,50,20);
b12=new Button("3");
b12.setBounds(250,160,50,20);
b13=new Button("*");
b13.setBounds(300,160,50,20);
b14=new Button("%");
b14.setBounds(150,200,50,20);
b15=new Button("0");
b15.setBounds(200,200,50,20);
b16=new Button("/");
b16.setBounds(250,200,50,20);
b17=new Button("=");
b17.setBounds(300,200,50,20);
b18=new Button("clear");
b18.setBounds(150,240,200,20);
add(lb1);
add(tf1);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(b11);
add(b12);
add(b13);
add(b14);
add(b15);
add(b16);
add(b17);
add(b18);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
b17.addActionListener(this);
b18.addActionListener(this);
setLayout(null);
}
public void actionPerformed(ActionEvent e)
{
s=e.getActionCommand();
if(s.equals("0")||s.equals("1")||s.equals("2")||s.equals("3")||s.equals("
4")||s.equals("5")||s.equals("6")||s.equals("7")||s.equals("8")||s.equal
s("9"))
{
s1=tf1.getText()+s;
tf1.setText(s1);
}
if(s.equals("+"))
{
s2=tf1.getText();
tf1.setText("");
s3="+";
}

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

if(s.equals("-"))
{
s2=tf1.getText();
tf1.setText("");
s3="-";
}
if(s.equals("*"))
{
s2=tf1.getText();
tf1.setText("");
s3="*";
}
if(s.equals("/"))
{
s2=tf1.getText();
tf1.setText("");
s3="/";
}
if(s.equals("%"))
{
s2=tf1.getText();
tf1.setText("");
s3="%";
}
if(s.equals("="))
{
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

s4=tf1.getText();
a=Integer.parseInt(s2);
b=Integer.parseInt(s4);
if(s3.equals("+"))
c=a+b;
if(s3.equals("-"))
c=a-b;
if(s3.equals("*"))
c=a*b;
if(s3.equals("/"))
c=a/b;
if(s3.equals("%"))
c=a%b;
tf1.setText(String.valueOf(c));
}
if(s.equals("clear"))
{
tf1.setText("");
}}
public void textvalueChanged(TextEvent e)
{
}}
Html:
<html>
<body>
<applet code="Cal.class"
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA

width="300"
height="300">
</applet>
</body>
</html>
Output:

1.)Enter 7

2.)click add sign

3.)Enter 8

Submitted By- KASHIKA DUGGAL


Project Report CORE JAVA

4.)output is:

Submitted By- KASHIKA DUGGAL

You might also like