SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
PRACTICAL 1
AIM :- Accept integer values for a, b and c which are coefficients of quadratic equation. Find the solution
of quadratic equation.
Source Code:-
import java.util.Scanner;
public class pract1
{
public static void main(String[] args)
{
int a, b, c;
double root1, root2, d;
Scanner s = new Scanner(System.in);
System.out.println("Given quadratic equation:ax^2 + bx + c");
System.out.print("Enter a:");
a = s.nextInt();
System.out.print("Enter b:");
b = s.nextInt();
System.out.print("Enter c:");
c = s.nextInt();
System.out.println("Given quadratic equation:"+a+"x^2 + "+b+"x + "+c);
d = b * b - 4 * a * c;
if(d > 0)
{
System.out.println("Roots are real and unequal");
root1 = ( - b + Math.sqrt(d))/(2*a);
root2 = (-b - Math.sqrt(d))/(2*a);
System.out.println("First root is:"+root1);
System.out.println("Second root is:"+root2);
}
else if(d == 0)
{
System.out.println("Roots are real and equal");
root1 = (-b+Math.sqrt(d))/(2*a);
System.out.println("Root:"+root1);
}
else
{
System.out.println("Roots are imaginary");
}
}
}
OUTPUT :-
PRACTICAL 2
AIM :- Accept two n x m matrices. Write a Java program to find addition of these matrices
Source Code:-
import java.util.Scanner;
class pract2
{
public static void main(String args[])
{
int m, n, c, d;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n = in.nextInt();
int first[][] = new int[m][n];
int second[][] = new int[m][n];
int sum[][] = new int[m][n];
System.out.println("Enter the elements of first matrix");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
first[c][d] = in.nextInt();
System.out.println("Enter the elements of second matrix");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
second[c][d] = in.nextInt();
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
sum[c][d] = first[c][d] + second[c][d]; //replace '+' with '-' to subtract matrices
System.out.println("Sum of entered matrices:-");
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
System.out.print(sum[c][d]+"t");
System.out.println();
}
}
}
OUTPUT :-
PRACTICAL 3
AIM :- Accept n strings. Sort names in ascending order.
Source Code:-
import java.util.Scanner;
public class pract3
{
public static void main(String[] args)
{
int n;
String temp;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of names you want to enter:");
n = s.nextInt();
String names[] = new String[n];
Scanner s1 = new Scanner(System.in);
System.out.println("Enter all the names:");
for(int i = 0; i < n; i++)
{
names[i] = s1.nextLine();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (names[i].compareTo(names[j])>0)
{
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
System.out.print("Names in Sorted Order:");
for (int i = 0; i < n - 1; i++)
{
System.out.print(names[i] + ",");
}
System.out.print(names[n - 1]);
}
}
OUTPUT :-
PRACTICAL 4
AIM :- Create a package: Animals. In package animals create interface Animal with suitable
behaviors. Implement the interface Animal in the same package animals.
Source Code:-
Animals.java (interface):
interface Animals {
void callSound();
int run();
}
Feline.java (abstract class):
abstract class Feline implements Animals {
@Override
public void callSound() {
System.out.println("roar");
}
}
Canine.java (abstract class):
abstract class Canine implements Animals {
@Override
public void callSound() {
System.out.println("howl");
}
}
Lion.java (class):
class Lion extends Feline {
@Override
public void callSound() {
super.callSound();
}
@Override
public int run() {
return 40;
}
}
Cat.java (class):
class Cat extends Feline {
@Override
public void callSound() {
System.out.println("meow");
}
@Override
public int run() {
return 30;
}
}
Wolf.java (class):
class Wolf extends Canine {
@Override
public void callSound() {
super.callSound();
}
@Override
public int run() {
return 20;
}
}
Dog.java (class):
class Dog extends Canine {
@Override
public void callSound() {
System.out.println("woof");
super.callSound();
}
@Override
public int run() {
return 10;
}
}
Main.java:
public class Main {
public static void main(String[] args) {
Animals[] animals = new Animals[4];
animals[0] = new Cat();
animals[1] = new Dog();
animals[2] = new Wolf();
animals[3] = new Lion();
for (int i = 0; i < animals.length; i++) {
animals[i].callSound();
}
}}
OUTPUT :-
PRACTICAL 5
AIM :- Demonstrate Java inheritance using extends keyword.
Source Code:-
Animal.java:
public class Animal {
public Animal() {
System.out.println("A new animal has been created!");
}
public void sleep() {
System.out.println("An animal sleeps...");
}
public void eat() {
System.out.println("An animal eats...");
}
}
Bird.java:
public class Bird extends Animal {
public Bird() {
super();
System.out.println("A new bird has been created!");
}
@Override
public void sleep() {
System.out.println("A bird sleeps...");
}
@Override
public void eat() {
System.out.println("A bird eats...");
}
}
Dog.java:
public class Dog extends Animal {
public Dog() {
super();
System.out.println("A new dog has been created!");
}
@Override
public void sleep() {
System.out.println("A dog sleeps...");
}
@Override
public void eat() {
System.out.println("A dog eats...");
}
}
MainClass.java:
public class MainClass {
public static void main(String[] args) {
Animal animal = new Animal();
Bird bird = new Bird();
Dog dog = new Dog();
System.out.println();
animal.sleep();
animal.eat();
bird.sleep();
bird.eat();
dog.sleep();
dog.eat();
}
}
OUTPUT :-
PRACTICAL 6
AIM :- Demonstrate method overloading and method overriding in Java
Source Code:-
Method overloading:-
class Polymorphism
{
void add(int a, int b)
{
System.out.println("Sum of two="+(a+b));
}
void add(int a, int b,int c)
{
System.out.println("Sum of three="+(a+b+c));
}
}
class pract6_overloading
{
public static void main(String args[])
{
Sum s=new Sum();
s.add(10,15);
s.add(10,20,30);
}
}
OUTPUT :-
Method overriding:-
class Bank{
int getRateOfInterest()
{
return 0;
}
}
class SBI extends Bank
{
int getRateOfInterest()
{
return 8;
}
}
class ICICI extends Bank
{
int getRateOfInterest()
{
return 7;
}
}
class AXIS extends Bank
{
int getRateOfInterest()
{
return 9;
}
}
class pract6_overriding
{
public static void main(String args[])
{
SBI s=new SBI();
ICICI i=new ICICI();
AXIS a=new AXIS();
System.out.println("SBI Rate of Interest: "+s.getRateOfInterest());
System.out.println("ICICI Rate of Interest: "+i.getRateOfInterest());
System.out.println("AXIS Rate of Interest: "+a.getRateOfInterest());
}
}
OUTPUT :-
PRACTICAL 7
AIM :- Demonstrate creating your own exception in Java.
Source Code:-
class NumberRangeException extends Exception
{
String msg;
NumberRangeException()
{
msg = new String("Enter a number between 20 and 100");
}
}
public class My_Exception
{
public static void main (String args [ ])
{
try
{
int x = 10;
if (x < 20 || x >100) throw new NumberRangeException( );
}
catch (NumberRangeException e)
{
System.out.println (e);
}
}
}
OUTPUT :-
PRACTICAL 8
AIM :- Using various swing components design Java application to accept a student's resume.
(Design form)
Source Code:-
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class Frame1 extends Frame implements ActionListener
{
String msg="";
Button btnNew,btnSubmit,btnView;
Label lblName,lblAge,lblAddr,lblGender,lblQua;
TextField txtName,txtAge;
TextArea txtAddr,txtAns;
CheckboxGroup ChkGrp;
Checkbox chkMale,chkFemale;
Checkbox chkMca,chkBca,chkBba,chkMba;
Frame1(String name)
{
super(name);
setLayout(new GridLayout(3,2));
lblName = new Label("Name: ");
lblAge = new Label("Age: ");
lblAddr = new Label("Address : ");
lblGender = new Label("Gender: ");
lblQua = new Label("Qualification: ");
txtName = new TextField(20);
txtAge = new TextField(20);
txtAddr = new TextArea();
ChkGrp = new CheckboxGroup();
chkMale = new Checkbox("Male",ChkGrp,false);
chkFemale = new Checkbox("Female",ChkGrp,false);
chkMca = new Checkbox("MCA");
chkBca = new Checkbox("BCA");
chkMba = new Checkbox("MBA");
chkBba = new Checkbox("BBA");
btnNew = new Button("NEW");
btnSubmit = new Button("SUBMIT");
btnView = new Button("VIEW");
btnNew.addActionListener(this);
btnSubmit.addActionListener(this);
btnView.addActionListener(this);
add(lblName);
add(txtName);
add(lblAge);
add(txtAge);
add(lblAddr);
add(txtAddr);
add(lblGender);
add(chkMale);
add(chkFemale);
add(lblQua);
add(chkBca);
add(chkBba);
add(chkMca);
add(chkMba);
add(btnNew);
add(btnSubmit);
add(btnView);
txtAns = new TextArea();
add(txtAns);
}
@Override
public void actionPerformed(ActionEvent ae)
{
String s="";
boolean b;
FileInputStream Fin;
DataInputStream dis;
FileOutputStream Fout;
DataOutputStream dos;
try
{
Fout = new FileOutputStream("Biodata.txt",true);
dos = new DataOutputStream(Fout);
String str = ae.getActionCommand();
if(str.equals("SUBMIT"))
{
s=txtName.getText().trim();
dos.writeUTF(s);
dos.writeInt(Integer.parseInt(txtAge.getText()));
s=txtAddr.getText();
dos.writeUTF(s);
if(chkMale.getState())
dos.writeUTF("Male ");
if(chkFemale.getState())
dos.writeUTF("Female ");
s="";
if(chkMca.getState())
s="MCA ";
if(chkBca.getState())
s+="BCA ";
if(chkBba.getState())
s+="BBA ";
if(chkMba.getState())
s+="MBA ";
s+="!";
dos.writeUTF(s);
Fout.close();
}
if(str.equals("VIEW"))
if(str.equals("NEW"))
{
txtName.setText("");
txtAge.setText("");
txtAddr.setText("");
chkMale.setState(false);
chkFemale.setState(false);
chkMca.setState(false);
chkBca.setState(false);
chkBba.setState(false);
chkMba.setState(false);
}
}
catch(Exception e)
{
System.out.println("The Exception Is : " +e);
}
}
}
class pract8
{
public static void main(String args[])
{
try{
Frame1 F = new Frame1("Biodata");
F.setSize(400,400);
F.show();
}catch(Exception e)
{
System.out.println(e);
}
}
}
OUTPUT :-
PRACTICAL 9
AIM :- Write a Java List example and demonstrate methods of Java List interface.
Source Code:-
import java.util.*;
public class Pract9 {
public static void main(String[] args) {
List a1 = new ArrayList();
a1.add("Zara");
a1.add("Mahnaz");
a1.add("Ayan");
System.out.println(" ArrayList Elements");
System.out.print("t" + a1);
List l1 = new LinkedList();
l1.add("Zara");
l1.add("Mahnaz");
l1.add("Ayan");
System.out.println();
System.out.println(" LinkedList Elements");
System.out.print("t" + l1);
}
}
OUTPUT :-
PRACTICAL 10
AIM :- Design simple calculator GUI application using AWT components
Source Code:-
import java.awt.*;
import java.awt.event.*;
class Calculator implements ActionListener
{
//Declaring Objects
Frame f=new Frame();
Label l1=new Label("First Number");
Label l2=new Label("Second Number");
Label l3=new Label("Result");
TextField t1=new TextField();
TextField t2=new TextField();
TextField t3=new TextField();
Button b1=new Button("Add");
Button b2=new Button("Sub");
Button b3=new Button("Mul");
Button b4=new Button("Div");
Button b5=new Button("Cancel");
Calculator()
{
//Giving Coordinates
l1.setBounds(50,100,100,20);
l2.setBounds(50,140,100,20);
l3.setBounds(50,180,100,20);
t1.setBounds(200,100,100,20);
t2.setBounds(200,140,100,20);
t3.setBounds(200,180,100,20);
b1.setBounds(50,250,50,20);
b2.setBounds(110,250,50,20);
b3.setBounds(170,250,50,20);
b4.setBounds(230,250,50,20);
b5.setBounds(290,250,50,20);
//Adding components to the frame
f.add(l1);
f.add(l2);
f.add(l3);
f.add(t1);
f.add(t2);
f.add(t3);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
f.setLayout(null);
f.setVisible(true);
f.setSize(400,350);
}
public void actionPerformed(ActionEvent e)
{
int n1=Integer.parseInt(t1.getText());
int n2=Integer.parseInt(t2.getText());
if(e.getSource()==b1)
{
t3.setText(String.valueOf(n1+n2));
}
if(e.getSource()==b2)
{
t3.setText(String.valueOf(n1-n2));
}
if(e.getSource()==b3)
{
t3.setText(String.valueOf(n1*n2));
}
if(e.getSource()==b4)
{
t3.setText(String.valueOf(n1/n2));
}
if(e.getSource()==b5)
{
System.exit(0);
}
}
public static void main(String...s)
{
new Calculator();
}
}
OUTPUT :-

Weitere ähnliche Inhalte

Was ist angesagt?

Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)mehul patel
 
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...Mumbai B.Sc.IT Study
 
Java Puzzle
Java PuzzleJava Puzzle
Java PuzzleSFilipp
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL fileRACHIT_GUPTA
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestHoward Lewis Ship
 
Smarter Testing With Spock
Smarter Testing With SpockSmarter Testing With Spock
Smarter Testing With SpockIT Weekend
 
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source Code
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source CodeUsing Fuzzy Code Search to Link Code Fragments in Discussions to Source Code
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source CodeNicolas Bettenburg
 
Java весна 2013 лекция 2
Java весна 2013 лекция 2Java весна 2013 лекция 2
Java весна 2013 лекция 2Technopark
 

Was ist angesagt? (19)

Why Learn Python?
Why Learn Python?Why Learn Python?
Why Learn Python?
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
 
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
 
Java Puzzle
Java PuzzleJava Puzzle
Java Puzzle
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
Spock framework
Spock frameworkSpock framework
Spock framework
 
Java puzzles
Java puzzlesJava puzzles
Java puzzles
 
Unit Testing with Foq
Unit Testing with FoqUnit Testing with Foq
Unit Testing with Foq
 
Java Language fundamental
Java Language fundamentalJava Language fundamental
Java Language fundamental
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To Test
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Smarter Testing With Spock
Smarter Testing With SpockSmarter Testing With Spock
Smarter Testing With Spock
 
Networking Core Concept
Networking Core ConceptNetworking Core Concept
Networking Core Concept
 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
 
Java practical
Java practicalJava practical
Java practical
 
Spock Framework
Spock FrameworkSpock Framework
Spock Framework
 
JDBC Core Concept
JDBC Core ConceptJDBC Core Concept
JDBC Core Concept
 
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source Code
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source CodeUsing Fuzzy Code Search to Link Code Fragments in Discussions to Source Code
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source Code
 
Java весна 2013 лекция 2
Java весна 2013 лекция 2Java весна 2013 лекция 2
Java весна 2013 лекция 2
 

Ähnlich wie Core java pract_sem iii

Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab FileKandarp Tiwari
 
Computer java programs
Computer java programsComputer java programs
Computer java programsADITYA BHARTI
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdfanupamfootwear
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Ayes Chinmay
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical FileSoumya Behera
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfoptokunal1
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarROHIT JAISWAR
 
Code javascript
Code javascriptCode javascript
Code javascriptRay Ray
 

Ähnlich wie Core java pract_sem iii (19)

Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab File
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
JAVAPGMS.docx
JAVAPGMS.docxJAVAPGMS.docx
JAVAPGMS.docx
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
Java programs
Java programsJava programs
Java programs
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Java -lec-5
Java -lec-5Java -lec-5
Java -lec-5
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswar
 
Code javascript
Code javascriptCode javascript
Code javascript
 

Mehr von Niraj Bharambe

T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai UniversityT.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai UniversityNiraj Bharambe
 
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.Niraj Bharambe
 
Advanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceAdvanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceNiraj Bharambe
 
Unit 1st and 3rd notes of java
Unit 1st and 3rd notes of javaUnit 1st and 3rd notes of java
Unit 1st and 3rd notes of javaNiraj Bharambe
 
Xml 150323102007-conversion-gate01
Xml 150323102007-conversion-gate01Xml 150323102007-conversion-gate01
Xml 150323102007-conversion-gate01Niraj Bharambe
 
Htmlnotes 150323102005-conversion-gate01
Htmlnotes 150323102005-conversion-gate01Htmlnotes 150323102005-conversion-gate01
Htmlnotes 150323102005-conversion-gate01Niraj Bharambe
 
Htmlcolorcodes 150323101937-conversion-gate01
Htmlcolorcodes 150323101937-conversion-gate01Htmlcolorcodes 150323101937-conversion-gate01
Htmlcolorcodes 150323101937-conversion-gate01Niraj Bharambe
 
Sixth sense technology
Sixth sense technologySixth sense technology
Sixth sense technologyNiraj Bharambe
 
Embedded System Practical manual (1)
Embedded System Practical manual (1)Embedded System Practical manual (1)
Embedded System Practical manual (1)Niraj Bharambe
 
Data Warehousing Practical for T.Y.I.T.
Data Warehousing Practical for T.Y.I.T.Data Warehousing Practical for T.Y.I.T.
Data Warehousing Practical for T.Y.I.T.Niraj Bharambe
 

Mehr von Niraj Bharambe (18)

Tybsc cs dbms2 notes
Tybsc cs dbms2 notesTybsc cs dbms2 notes
Tybsc cs dbms2 notes
 
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai UniversityT.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
 
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
 
Advanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceAdvanced java practical semester 6_computer science
Advanced java practical semester 6_computer science
 
Core java tutorial
Core java tutorialCore java tutorial
Core java tutorial
 
Java unit 4_cs_notes
Java unit 4_cs_notesJava unit 4_cs_notes
Java unit 4_cs_notes
 
Unit 1st and 3rd notes of java
Unit 1st and 3rd notes of javaUnit 1st and 3rd notes of java
Unit 1st and 3rd notes of java
 
J2 ee tutorial ejb
J2 ee tutorial ejbJ2 ee tutorial ejb
J2 ee tutorial ejb
 
Xml 150323102007-conversion-gate01
Xml 150323102007-conversion-gate01Xml 150323102007-conversion-gate01
Xml 150323102007-conversion-gate01
 
Htmlnotes 150323102005-conversion-gate01
Htmlnotes 150323102005-conversion-gate01Htmlnotes 150323102005-conversion-gate01
Htmlnotes 150323102005-conversion-gate01
 
Htmlcolorcodes 150323101937-conversion-gate01
Htmlcolorcodes 150323101937-conversion-gate01Htmlcolorcodes 150323101937-conversion-gate01
Htmlcolorcodes 150323101937-conversion-gate01
 
Definition
DefinitionDefinition
Definition
 
Sixth sense technology
Sixth sense technologySixth sense technology
Sixth sense technology
 
collisiondetection
collisiondetectioncollisiondetection
collisiondetection
 
Html color codes
Html color codesHtml color codes
Html color codes
 
Embedded System Practical manual (1)
Embedded System Practical manual (1)Embedded System Practical manual (1)
Embedded System Practical manual (1)
 
Data Warehousing Practical for T.Y.I.T.
Data Warehousing Practical for T.Y.I.T.Data Warehousing Practical for T.Y.I.T.
Data Warehousing Practical for T.Y.I.T.
 
Forouzan appendix
Forouzan appendixForouzan appendix
Forouzan appendix
 

Kürzlich hochgeladen

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Kürzlich hochgeladen (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Core java pract_sem iii

  • 1. PRACTICAL 1 AIM :- Accept integer values for a, b and c which are coefficients of quadratic equation. Find the solution of quadratic equation. Source Code:- import java.util.Scanner; public class pract1 { public static void main(String[] args) { int a, b, c; double root1, root2, d; Scanner s = new Scanner(System.in); System.out.println("Given quadratic equation:ax^2 + bx + c"); System.out.print("Enter a:"); a = s.nextInt(); System.out.print("Enter b:"); b = s.nextInt(); System.out.print("Enter c:"); c = s.nextInt(); System.out.println("Given quadratic equation:"+a+"x^2 + "+b+"x + "+c); d = b * b - 4 * a * c; if(d > 0) { System.out.println("Roots are real and unequal"); root1 = ( - b + Math.sqrt(d))/(2*a); root2 = (-b - Math.sqrt(d))/(2*a); System.out.println("First root is:"+root1); System.out.println("Second root is:"+root2); } else if(d == 0) { System.out.println("Roots are real and equal"); root1 = (-b+Math.sqrt(d))/(2*a); System.out.println("Root:"+root1); } else { System.out.println("Roots are imaginary"); } } }
  • 3. PRACTICAL 2 AIM :- Accept two n x m matrices. Write a Java program to find addition of these matrices Source Code:- import java.util.Scanner; class pract2 { public static void main(String args[]) { int m, n, c, d; Scanner in = new Scanner(System.in); System.out.println("Enter the number of rows and columns of matrix"); m = in.nextInt(); n = in.nextInt(); int first[][] = new int[m][n]; int second[][] = new int[m][n]; int sum[][] = new int[m][n]; System.out.println("Enter the elements of first matrix"); for ( c = 0 ; c < m ; c++ ) for ( d = 0 ; d < n ; d++ ) first[c][d] = in.nextInt(); System.out.println("Enter the elements of second matrix"); for ( c = 0 ; c < m ; c++ ) for ( d = 0 ; d < n ; d++ ) second[c][d] = in.nextInt(); for ( c = 0 ; c < m ; c++ ) for ( d = 0 ; d < n ; d++ ) sum[c][d] = first[c][d] + second[c][d]; //replace '+' with '-' to subtract matrices System.out.println("Sum of entered matrices:-"); for ( c = 0 ; c < m ; c++ ) { for ( d = 0 ; d < n ; d++ ) System.out.print(sum[c][d]+"t"); System.out.println(); } } }
  • 5. PRACTICAL 3 AIM :- Accept n strings. Sort names in ascending order. Source Code:- import java.util.Scanner; public class pract3 { public static void main(String[] args) { int n; String temp; Scanner s = new Scanner(System.in); System.out.print("Enter number of names you want to enter:"); n = s.nextInt(); String names[] = new String[n]; Scanner s1 = new Scanner(System.in); System.out.println("Enter all the names:"); for(int i = 0; i < n; i++) { names[i] = s1.nextLine(); } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (names[i].compareTo(names[j])>0) { temp = names[i]; names[i] = names[j]; names[j] = temp; } } } System.out.print("Names in Sorted Order:"); for (int i = 0; i < n - 1; i++) { System.out.print(names[i] + ","); } System.out.print(names[n - 1]); } }
  • 7. PRACTICAL 4 AIM :- Create a package: Animals. In package animals create interface Animal with suitable behaviors. Implement the interface Animal in the same package animals. Source Code:- Animals.java (interface): interface Animals { void callSound(); int run(); } Feline.java (abstract class): abstract class Feline implements Animals { @Override public void callSound() { System.out.println("roar"); } } Canine.java (abstract class): abstract class Canine implements Animals { @Override public void callSound() { System.out.println("howl"); } } Lion.java (class): class Lion extends Feline { @Override public void callSound() { super.callSound(); } @Override public int run() { return 40; } } Cat.java (class): class Cat extends Feline { @Override public void callSound() {
  • 8. System.out.println("meow"); } @Override public int run() { return 30; } } Wolf.java (class): class Wolf extends Canine { @Override public void callSound() { super.callSound(); } @Override public int run() { return 20; } } Dog.java (class): class Dog extends Canine { @Override public void callSound() { System.out.println("woof"); super.callSound(); } @Override public int run() { return 10; } } Main.java: public class Main { public static void main(String[] args) { Animals[] animals = new Animals[4]; animals[0] = new Cat(); animals[1] = new Dog(); animals[2] = new Wolf(); animals[3] = new Lion(); for (int i = 0; i < animals.length; i++) { animals[i].callSound(); } }}
  • 10. PRACTICAL 5 AIM :- Demonstrate Java inheritance using extends keyword. Source Code:- Animal.java: public class Animal { public Animal() { System.out.println("A new animal has been created!"); } public void sleep() { System.out.println("An animal sleeps..."); } public void eat() { System.out.println("An animal eats..."); } } Bird.java: public class Bird extends Animal { public Bird() { super(); System.out.println("A new bird has been created!"); } @Override public void sleep() { System.out.println("A bird sleeps..."); } @Override public void eat() { System.out.println("A bird eats..."); } } Dog.java: public class Dog extends Animal { public Dog() { super(); System.out.println("A new dog has been created!"); } @Override public void sleep() { System.out.println("A dog sleeps..."); } @Override public void eat() {
  • 11. System.out.println("A dog eats..."); } } MainClass.java: public class MainClass { public static void main(String[] args) { Animal animal = new Animal(); Bird bird = new Bird(); Dog dog = new Dog(); System.out.println(); animal.sleep(); animal.eat(); bird.sleep(); bird.eat(); dog.sleep(); dog.eat(); } }
  • 13. PRACTICAL 6 AIM :- Demonstrate method overloading and method overriding in Java Source Code:- Method overloading:- class Polymorphism { void add(int a, int b) { System.out.println("Sum of two="+(a+b)); } void add(int a, int b,int c) { System.out.println("Sum of three="+(a+b+c)); } } class pract6_overloading { public static void main(String args[]) { Sum s=new Sum(); s.add(10,15); s.add(10,20,30); } } OUTPUT :-
  • 14. Method overriding:- class Bank{ int getRateOfInterest() { return 0; } } class SBI extends Bank { int getRateOfInterest() { return 8; } } class ICICI extends Bank { int getRateOfInterest() { return 7; } } class AXIS extends Bank { int getRateOfInterest() { return 9; } } class pract6_overriding { public static void main(String args[]) { SBI s=new SBI(); ICICI i=new ICICI(); AXIS a=new AXIS(); System.out.println("SBI Rate of Interest: "+s.getRateOfInterest()); System.out.println("ICICI Rate of Interest: "+i.getRateOfInterest()); System.out.println("AXIS Rate of Interest: "+a.getRateOfInterest()); } }
  • 16. PRACTICAL 7 AIM :- Demonstrate creating your own exception in Java. Source Code:- class NumberRangeException extends Exception { String msg; NumberRangeException() { msg = new String("Enter a number between 20 and 100"); } } public class My_Exception { public static void main (String args [ ]) { try { int x = 10; if (x < 20 || x >100) throw new NumberRangeException( ); } catch (NumberRangeException e) { System.out.println (e); } } } OUTPUT :-
  • 17. PRACTICAL 8 AIM :- Using various swing components design Java application to accept a student's resume. (Design form) Source Code:- import java.io.*; import java.awt.*; import java.awt.event.*; class Frame1 extends Frame implements ActionListener { String msg=""; Button btnNew,btnSubmit,btnView; Label lblName,lblAge,lblAddr,lblGender,lblQua; TextField txtName,txtAge; TextArea txtAddr,txtAns; CheckboxGroup ChkGrp; Checkbox chkMale,chkFemale; Checkbox chkMca,chkBca,chkBba,chkMba; Frame1(String name) { super(name); setLayout(new GridLayout(3,2)); lblName = new Label("Name: "); lblAge = new Label("Age: "); lblAddr = new Label("Address : "); lblGender = new Label("Gender: "); lblQua = new Label("Qualification: "); txtName = new TextField(20); txtAge = new TextField(20); txtAddr = new TextArea(); ChkGrp = new CheckboxGroup(); chkMale = new Checkbox("Male",ChkGrp,false); chkFemale = new Checkbox("Female",ChkGrp,false); chkMca = new Checkbox("MCA"); chkBca = new Checkbox("BCA"); chkMba = new Checkbox("MBA"); chkBba = new Checkbox("BBA"); btnNew = new Button("NEW"); btnSubmit = new Button("SUBMIT"); btnView = new Button("VIEW"); btnNew.addActionListener(this); btnSubmit.addActionListener(this); btnView.addActionListener(this); add(lblName);
  • 18. add(txtName); add(lblAge); add(txtAge); add(lblAddr); add(txtAddr); add(lblGender); add(chkMale); add(chkFemale); add(lblQua); add(chkBca); add(chkBba); add(chkMca); add(chkMba); add(btnNew); add(btnSubmit); add(btnView); txtAns = new TextArea(); add(txtAns); } @Override public void actionPerformed(ActionEvent ae) { String s=""; boolean b; FileInputStream Fin; DataInputStream dis; FileOutputStream Fout; DataOutputStream dos; try { Fout = new FileOutputStream("Biodata.txt",true); dos = new DataOutputStream(Fout); String str = ae.getActionCommand(); if(str.equals("SUBMIT")) { s=txtName.getText().trim(); dos.writeUTF(s); dos.writeInt(Integer.parseInt(txtAge.getText())); s=txtAddr.getText(); dos.writeUTF(s); if(chkMale.getState())
  • 19. dos.writeUTF("Male "); if(chkFemale.getState()) dos.writeUTF("Female "); s=""; if(chkMca.getState()) s="MCA "; if(chkBca.getState()) s+="BCA "; if(chkBba.getState()) s+="BBA "; if(chkMba.getState()) s+="MBA "; s+="!"; dos.writeUTF(s); Fout.close(); } if(str.equals("VIEW")) if(str.equals("NEW")) { txtName.setText(""); txtAge.setText(""); txtAddr.setText(""); chkMale.setState(false); chkFemale.setState(false); chkMca.setState(false); chkBca.setState(false); chkBba.setState(false); chkMba.setState(false); } } catch(Exception e) { System.out.println("The Exception Is : " +e); } } } class pract8 { public static void main(String args[])
  • 20. { try{ Frame1 F = new Frame1("Biodata"); F.setSize(400,400); F.show(); }catch(Exception e) { System.out.println(e); } } } OUTPUT :-
  • 21. PRACTICAL 9 AIM :- Write a Java List example and demonstrate methods of Java List interface. Source Code:- import java.util.*; public class Pract9 { public static void main(String[] args) { List a1 = new ArrayList(); a1.add("Zara"); a1.add("Mahnaz"); a1.add("Ayan"); System.out.println(" ArrayList Elements"); System.out.print("t" + a1); List l1 = new LinkedList(); l1.add("Zara"); l1.add("Mahnaz"); l1.add("Ayan"); System.out.println(); System.out.println(" LinkedList Elements"); System.out.print("t" + l1); } } OUTPUT :-
  • 22. PRACTICAL 10 AIM :- Design simple calculator GUI application using AWT components Source Code:- import java.awt.*; import java.awt.event.*; class Calculator implements ActionListener { //Declaring Objects Frame f=new Frame(); Label l1=new Label("First Number"); Label l2=new Label("Second Number"); Label l3=new Label("Result"); TextField t1=new TextField(); TextField t2=new TextField(); TextField t3=new TextField(); Button b1=new Button("Add"); Button b2=new Button("Sub"); Button b3=new Button("Mul"); Button b4=new Button("Div"); Button b5=new Button("Cancel"); Calculator() { //Giving Coordinates l1.setBounds(50,100,100,20); l2.setBounds(50,140,100,20); l3.setBounds(50,180,100,20); t1.setBounds(200,100,100,20); t2.setBounds(200,140,100,20); t3.setBounds(200,180,100,20); b1.setBounds(50,250,50,20); b2.setBounds(110,250,50,20); b3.setBounds(170,250,50,20); b4.setBounds(230,250,50,20); b5.setBounds(290,250,50,20); //Adding components to the frame f.add(l1); f.add(l2); f.add(l3); f.add(t1);
  • 23. f.add(t2); f.add(t3); f.add(b1); f.add(b2); f.add(b3); f.add(b4); f.add(b5); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); f.setLayout(null); f.setVisible(true); f.setSize(400,350); } public void actionPerformed(ActionEvent e) { int n1=Integer.parseInt(t1.getText()); int n2=Integer.parseInt(t2.getText()); if(e.getSource()==b1) { t3.setText(String.valueOf(n1+n2)); } if(e.getSource()==b2) { t3.setText(String.valueOf(n1-n2)); } if(e.getSource()==b3) { t3.setText(String.valueOf(n1*n2)); } if(e.getSource()==b4) { t3.setText(String.valueOf(n1/n2)); } if(e.getSource()==b5) { System.exit(0); } }
  • 24. public static void main(String...s) { new Calculator(); } } OUTPUT :-