JAVA RECORD-II BCA C
JAVA RECORD-II BCA C
Date :
PROGRAM TO CONVERT FAHRENHEIT TO CELSIUS
AIM:
To convert Fahrenheit to Celsius .
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable
Step 3: Read the temperature value using scanner object as sc.nextInt() and store it in thevariable
a. Step 4: In the main method, call the celsius method as celsius (a), then celsius(double f)method
returns the Celsius temperature.
Step 6: Print the output
Step 7: End the program
PROGRAM:
import java.util.Scanner;class
FahrenheittoCelsius
{
public static void main(String arg[])
{
double a,c;
Scanner sc=new Scanner(System.in);
System.out.println("Enter Fahrenheit temperature");
a=sc.nextDouble();
System.out.println("Celsius temperature is = "+celsius(a));
}
static double celsius(double f)
{
return (f-32)*5/9;
}
}
1
OUTPUT:
RESULT:
Thus the required output has been acquired successfully.
1
Ex No :1(b)
Date :
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable a,d and initialize it.
Step 3: Perform type conversion of integer to long by assigning a to l , long to float byassigning l
to f, and float to double by assigning d1 = f.
Step 6: Print the output variables
Step 7: End the program
PROGRAM:
import java.util.*;public
class Main
{
public static void main(String[] args)
{
int a = 50; double d =
100;
// Automatic type conversionlong l = a;
RESULT:
Thus the required output has been acquired successfully.
2
Ex No :1(c )
Date :
PROGRAM TO CHECK FOR EQUILATERAL TRIANGLE
AIM:
To check for Equilateral Triangle
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable,b,c.
Step 3:Read the input for a,b,c using Scanner object sc.
Step 4: Check the condition if(a=b)&&(b==c)
Step 5: if true then the it forms a equilateral triangle else print not a equilateral triangle.
Step 6: End the program
PROGRAM:
import java.io.*;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{ int a,b,c;
Scanner sc= new Scanner (System.in);
System.out.println("Enter the angles of Triangle");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
sc.close();
if((a==b)&&(b==c))
System.out.println("Yes, equilateral Triangle");
else
System.out.println("Not a equilateral Traingle");
}
}
OUTPUT:
3
RESULT: Thus the required output has been acquired successfully.
4
EX.NO: 2
Date :
OPERATORS
AIM
PROGRAM :
import java.io. *;
public class operator
{
public static void main (String args[])
{
int a=12, b= 5;
System.out.println("Arithmetic operator");
System.out.println("a+b="+(a+b));
System.out.println("a - b = " + (a-b));
System.out.println("Assignment operator");
int var;
var=a;
System.out.println("var using=:"+var);
var+=a;
System.out.println("var using +=: " +
var); System.out.println("Relational
operator"); System.out.println(a==b);
System.out.println(a!=b);
System.out.println("Logical operator");
System.out.println((5>3)&&(8>5));
int result1,result2;
System.out.println("Value of a:"+a);
result1=++a;
System.out.println("After increment:"+result1);
System.out.println("Unary operator");
System.out.println("Value of b:"+b);
result2=--b;
System.out.println("After decrement:"+result2);
}
}
5
OUTPUT:
RESULT:
The Program has been executed and the output was verified
6
EX.NO: 3
Date :
AIM:
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable as array
Step 3: Assign the values
Step 4: Start looping
Step 5: Check the condition
Step 6: Print the value
Step 7: End the program
PROGRAM:
7
OUTPUT:
RESULT:
8
EX.NO: 4
Date : CLASSES AND OBJECTS
AIM:
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable as array
Step 3: Assign the values
Step 4: Start looping
Step 5: Check the condition
Step 6: Print the value
Step 7: End the program
PROGRAM:
public class Employee
{
String name;
int age;
String designation;
double salary;
public Employee(String name)
{
this.name=name;
}
public void empAge(int empAge)
{
age=empAge;
}
public void empDesignation(String empDesig)
{
designation=empDesig;
}
public void empSalary(double empSalary)
{
salary=empSalary;
}
public void printEmployee()
{
System.out.println("Name:"+ name );
System.out.println("Age:" + age );
System.out.println("Designation:" + designation );
System.out.println("Salary:" + salary);
}
public static void main(String[] args)
9
{
Employee emp1=new Employee("Steve");
emp1.empAge(19);
emp1.empDesignation("Developer");
emp1.empSalary(80000);
emp1.printEmployee();
}
}
OUTPUT:
RESULT:
Thus the required output has been obtained successfully
10
EX.NO: 5(a)
Date :
METHOD OVERLOADING
AIM:
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable as array
Step 3: Assign the Method values
Step 4: Start looping
Step 5: Check the condition
Step 6: Print the value
Step 7: End the program
PROGRAM:
import java.io.*;
public class aaa
{
public int sum(int x, int y)
{
return (x + y);
}
public int sum(int x, int y, int z)
{
return (x + y + z);
}
public double sum(double x, double y)
{
return (x + y);
}
public static void main(String args[])
{
Sum s = new aaa();
System.out.println(s.sum(10, 20));
System.out.println(s.sum(10, 20, 30));
System.out.println(s.sum(10.5, 20.5));
11
}
}
OUTPUT:
30
60
31.0
RESULT:
The Program has been executed and the output was verified.
12
EX.NO: 5(b)
Date :
CONSTRUCTOR OVERLOADING
AIM:
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable as array
Step 3: Assign the Method values
Step 4: Start looping
Step 5: Check the condition
Step 6: Print the value
Step 7: End the program
PROGRAM:
import java.io.*;
class add
{
int x,y,z;
add(int a, int b, int c)
{
x= a;
y= b;
z=c
int tot=x+y+z;
System.out .println(“ The ans”+tot);
}
add()
{
x = y = z = 3;
int tot1= x+y+z;
System.out .println(“ The ans”+tot1);
}
add(int m)
{
x = y = z = m;
int tot2= x+y+z;
System.out .println(“ The ans”+tot2);
13
}
public class Test
{
public static void main(String args[])
{
add a1= new add (10, 20, 15);
add a2 = new add ();
add a3 = new add (7);
}
}
OUTPUT:
The ans 45
The ans 9
The ans 21
RESULT:
The Program has been executed and the output was verified.
14
EX.NO: 6
Date :
STRING CLASS
AIM:
To write a java program to handle with string functions
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable as array
Step 3: Assign the string
functionsvalues Step 4: Start looping
Step 5: Check the condition
Step 6: Print the value
Step 7: End the program
PROGRAM:
import java .io.*;
import java.lang.String;
public class strMethod
{
static String str="object";
public static void main(String arg[])
{
System.out.println("original string: "+str);
int str1=str.length();
System.out.println("length of string: "+str1);
String str2=str+" Oriented";
System.out.println("Modified string: "+str2);
String str3=str2.toUpperCase();
System.out.println("String :"+str3);
char ch;
ch="abc".charAt(2);
System.out.println("CharAt :"+ch);
byte x[]={66,67,68,69,70};
String s4=new String(x);
System.out.println(s4);
String str4="Hello".replace('l','w');
System.out.println(str4);
String s1="BCA";
String s2="bca";
System.out.println(s1.equals(s2));
15
System.out.println(s1.equalsIgnoreCase(s2));
String s5= "Foot ball";
System.out.println(s5.startsWith("foot"));
System.out.println(s5.endsWith("ball"));
}
}
OUTPUT:
original string:
object length of
string: 6
Modified string: object Oriented
String :OBJECT ORIENTED
CharAt :c
BCDEF
Hewwo
false
true
false
true
RESULT:
The Program has been executed and the output was verified.
16
EX.NO: 7
Date :
ABSTRACT CLASS and METHOD
AIM :
To write a java program to handle Abstract class and Method
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable as array
Step 3: Assign the string
functionsvalues Step 4: Start looping
Step 5: Check the condition
Step 6: Print the value
Step 7: End the program
PROGRAM:
17
}
}
18
class Main {
public static void main(String[] args) {
Pig myPig = new Pig(); // Create a Pig
object myPig.animalSound();
myPig.sleep();
}
}
OUTPUT:
RESULT:
The Program has been executed and the output was verified.
19
EX.NO: 8(a)
Date :
PACKAGES
Aim :
To write a java program to handle package.
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable as array
Step 3: Assign the string
functionsvalues Step 4: Start looping
Step 5: Check the condition
Step 6: Print the value
Step 7: End the program
PROGRAM:
20
OUTPUT:
RESULT:
The Program has been executed and the output was verified.
21
EX.NO: 8(b)
Date :
INTERFACES
Aim :
To write a java program to handle Interface.
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable as array
Step 3: Assign the string
functionsvalues Step 4: Start looping
Step 5: Check the condition
Step 6: Print the value
Step 7: End the program
PROGRAM:
interface printable{
void print();
}
class A6 implements printable{
public void print(){System.out.println("Hello");}
public static void main(String args[]){
A6 obj = new A6();
obj.print();
}
}
OUTPUT:
Result:The Program has been executed and the output was verified.
22
EX.NO: 9
Date :
EXCEPTION HANDLING
AIM
To write a java program to handle Exception handling.
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable as array
Step 3: Assign the string
functionsvalues Step 4: Start looping
Step 5: Check the condition
Step 6: Print the value
Step 7: End the program
PROGRAM:
public class MultipleCatchBlock1 {
public static void main(String[] args)
{
try{
int a[]=new
int[5]; a[5]=30/0;
}
catch(ArithmeticException e)
{
System.out.println("Arithmetic Exception occurs");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("ArrayIndexOutOfBounds Exception occurs");
}
catch(Exception e)
{
System.out.println("Parent Exception occurs");
}
System.out.println("rest of the code");
}
}
23
OUTPUT:
RESULT:
The Program has been executed and the output was verified.
24
EX.NO: 10
Date :
MULTITHREADING
AIM :
To write a java program to handle Multithreading.
ALGORITHM:
Step 1: Start the program
Step 2: Declare the variable as array
Step 3: Assign the string
functionsvalues Step 4: Start looping
Step 5: Check the condition
Step 6: Print the value
Step 7: End the program
PROGRAM:
}}}
Thread t2 = new
Worker(); Thread t3 =
t2.start();
t3.start();
25
}
OUTPUT:
Result:
The Program has been executed and the output was verified.
26
EX.NO: 11
Date :
LEGACY CLASSES AND METHODS
AIM :
To write a java program to handle Legacy classes and Method.
PROGRAM:
import java.util.*;
public class VectorExample
{
public static void main(String[] args)
{
Vector<String> vec = new
Vector<String>(); vec.add("C");
vec.add("C++");
vec.add("Java");
vec.add("Python");
vec.add("C#");
vec.add("Vb.Net");
Enumeration<String> data =
vec.elements();
while(data.hasMoreElements())
{
System.out.println(data.nextElement());
} } }
OUTPUT:
Result:
The Program has been executed and the output was verified.
27
EX.NO: 12
Date :
UTILITY CLASSES AND METHODS
AIM :
To write a java program to handle Utility classes and Method.
PROGRAM:
import java.util.*;
class Test1{
public static void main(String[] args)
{
ArrayList al;
al = new
ArrayList<>();
al.add(11);
al.add(32);
al.add(28);
al.add(10);
System.out.println(al);
Collections.sort(al);
System.out.println(al);
Collections.reverse(al);
System.out.println(al);
Collections.shuffle(al);
System.out.println(al);
}
}
OUTPUT:
RESULT:
The Program has been executed and the output was verified.
28
EX.NO: 13
Date :
EVENT HANDLING
AIM :
29
OUTPUT:
Result:
The Program has been executed and the output was verified.
30
EX.NO: 14
Date :
AWT CONTROLS
AIM :
To write a Java program for AWT Control.
PROGRAM:
import java.awt.*;
public class AWTExample1 extends Frame {
AWTExample1() {
Button b = new Button("Click Me!!");
b.setBounds(30,100,80,30);
add(b);
setSize(300,300);
setTitle("This is our basic AWT example");
setLayout(null);
setVisible(true);
}
public static void main(String args[]) {
AWTExample1 f = new AWTExample1();
} }
OUTPUT:
RESULT
The Program has been executed and the output was verified.
31
EX.NO: 15
Date :
BORDER LAYOUT
AIM :
PROGRAM:
import java.awt.*;
import javax.swing.*;
// creating buttons
JButton b1 = new JButton("NORTH");; // the button will be labeled as NORTH
JButton b2 = new JButton("SOUTH");; // the button will be labeled as SOUTH
JButton b3 = new JButton("EAST");; // the button will be labeled as EAST
JButton b4 = new JButton("WEST");; // the button will be labeled as WEST
JButton b5 = new JButton("CENTER");; // the button will be labeled as CENTER
f.setSize(300, 300);
f.setVisible(true);
}
public static void main(String[] args) {
new Border();
}
}
32
OUTPUT:
RESULT
The Program has been executed and the output was verified.
33