# Untitled

unknown
plain_text
a year ago
11 kB
37
Indexable
Never
```LAB 1A: Program to check x and y values using if statement and displaying message whether x is greater than y

package LabPgm1;

public class Pgm1
{
public static void main(String args[])
{
int x=8, y=3;

System.out.println("X = " +x);
System.out.println("Y = " +y);

if( x > y )
System.out.println("X is greater than Y");
else
System.out.println("Y is greater than X");
}

}

OUTPUT:

X = 8
Y = 3
X is greater than Y

LAB 2A: Program to list the factorial of the numbers from 1 to 10 using while loop

package LabPgm2;

public class Pgm2
{
public static void main(String[] args) {
int fact, i, j;

for(i=1;i<=10;i++)
{
System.out.print("\nFactorial of " + i + " is: ");
fact=1;
j=1;
while(j<=i)
{
fact = fact * j;
j++;
}
System.out.print(fact);
}

}

}

OUTPUT:

Factorial of 1 is: 1
Factorial of 2 is: 2
Factorial of 3 is: 6
Factorial of 4 is: 24
Factorial of 5 is: 120
Factorial of 6 is: 720
Factorial of 7 is: 5040
Factorial of 8 is: 40320
Factorial of 9 is: 362880
Factorial of 10 is: 3628800

LAB 3A: Program to find the area and circumference of the circle by accepting the radius from the user

package LabPgm3;
import java.util.*;

public class Pgm3
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);

circum = 2 * Math.PI * radius;

System.out.println("Area = " +area);
System.out.println("Circumference = " +circum);
}

}

OUTPUT:

2.6
Area = 21.237166338267002
Circumference = 16.336281798666924

package LabPgm4;

{
int a=2, b=6, res;
double c=3.5, d=5.6, res1;
{
res = a+b;
System.out.println("Addition of default Integer values" +a+ " and  " +b+ " is: " + res);
}
{
a=x;
b=y;
res = a+b;
System.out.println("Addition of Integer parameters values "+a+" and "+b+" is: "+res);
}
{
res1 = c+d;
System.out.println("\nAddition of default Float values " +c+ " and  "+d+ " is: " +res1);
}
{
c=x;
d=y;
res1 = c+d;
System.out.println("Addition of Float parameters values "+c+" and "+d+" is: " +res1);
}

}

package LabPgm4;

public class Pgm4
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);

int a,b;
double c,d;

System.out.println("Enter 2 integer values" );
a=in.nextInt();
b=in.nextInt();

System.out.println("Enter 2 float values" );
c=in.nextDouble();
d=in.nextDouble();

}

}

OUTPUT:

Enter 2 integer values
3
6
Enter 2 float values
2.3
6.5

Addition of default Integer values 2 and 6 is: 8
Addition of Integer parameters values 3 and 6 is: 9

Addition of default Float values 3.5 and 5.6 is: 9.1
Addition of Float parameters values 2.3 and 6.5 is: 8.8

LAB 5A: Program to perform arithmatic operations by extending the classes

package LabPgm5;
import java.util.*;

{
int a, b;
Scanner in = new Scanner(System.in);
void getdata()
{
System.out.println("Enter a value:");
a= in.nextInt();
System.out.println("Enter b value:");
b= in.nextInt();
}
{
}
void sub1()
{
sub = a - b;
System.out.println("Subtraction: "+sub);
}
}

package LabPgm5;
{
int mul;
double div;

void mul1()
{
mul = a * b;
System.out.println("Multiplication: "+mul);
}
void div1()
{
div = a / b;
System.out.println("Division: "+div);
}
}

package LabPgm5;
public class Pgm5
{
public static void main(String[] args)
{
MulDiv obj = new MulDiv();

obj.getdata();
obj.sub1();
obj.mul1();
obj.div1();
}

}

OUTPUT:

Enter a value:
6

Enter b value:
2

Subtraction: 4
Multiplication: 12
Division: 3.0

LAB 6A: Program with class variable that is available for all instances of a class. Use static variable declaration. Observe the changes that occur in the objects member variable values

package LabPgm6;

public class VarDemo
{
static int num1=30; //Class Variable
int num2;
void display()
{
System.out.println("Num1 = " + num1);
System.out.println("Num2 = " + num2);
}

}

package LabPgm6;

public class Pgm6
{
public static void main(String[] args)
{
VarDemo obj1=new VarDemo();
VarDemo obj2=new VarDemo();

obj1.num2=25;
obj2.num2=50;

System.out.println("Variable num1 is static\n\nObject 1 values");
obj1.display();
System.out.println("Object 2 values");
obj2.display();

obj1.num2=66;
System.out.println("\nAfter changing num2 value for object1\nObject 1 values");
obj1.display();
System.out.println("Object 2 values");
obj2.display();

obj2.num2=78;
System.out.println("\nAfter changing num2 value for object2\nObject 1 values");
obj1.display();
System.out.println("Object 2 values");
obj2.display();
}

}

OUTPUT:

Variable num1 is static

Object 1 values
Num1 = 30
Num2 = 25
Object 2 values
Num1 = 30
Num2 = 50

After changing num2 value for object1
Object 1 values
Num1 = 30
Num2 = 66
Object 2 values
Num1 = 30
Num2 = 50

After changing num2 value for object2
Object 1 values
Num1 = 30
Num2 = 66
Object 2 values
Num1 = 30
Num2 = 78

LAB 7A:  Program to create a student class with following attributes; enrollment no: name, mark of sub1, mark of sub2, mark of sub3, total marks. Total of the three marks must be calculated only when the student passes in all three subjects. The passing mark for each subject is 50. If a candidate fails in any one of the subjects his total mark must be declared as zero. In the main method create an array of three student objects and display the details.

package LabPgm7a;
import java.util.*;

public class StudentData
{
int rno;
String name;
int s1, s2, s3;
int total;
String result;

void calculate()
{
if(s1>=50 && s2>=50 && s3>=50)
{
total = s1 + s2 +s3;
result = "Pass";
}
else
{
total = 0;
result = "Fail";
}
}

StudentData()
{
Scanner in = new Scanner(System.in);

System.out.println("Enter Roll no:");
rno = in.nextInt();

System.out.println("Enter Name:");
name = in.next();

System.out.println("Enter 3 subject marks:");
s1 = in.nextInt();
s2 = in.nextInt();
s3 = in.nextInt();
}
void display()
{
System.out.println("Roll no: "+rno);
System.out.println("Name: "+name);
System.out.println("Subject 1: "+s1);
System.out.println("Subject 2: "+s2);
System.out.println("Subject 3: "+s3);
System.out.println("Total: "+total);
System.out.println("Result: "+result);
}
}

package LabPgm7a;
public class Pgm7a
{
public static void main(String args[])
{
StudentData s[] = new StudentData[3];
for(int i=0; i<3; i++)
{
System.out.println("*****Enter " + (i+1) + "Student details");
s[i] = new StudentData();
s[i].calculate();
}
System.out.println("Student details");
for(int i=0; i<3; i++)
{
System.out.println("\n*****" + (i+1)
+ "Student details");
s[i].display();
}
}
}

OUTPUT:

*****Enter 1Student details
Enter Roll no:
1
Enter Name:
Rekha
Enter 3 subject marks:
34	67	87

*****Enter 2Student details
Enter Roll no:
2
Enter Name:
Suresh
Enter 3 subject marks:
67	89	98

*****Enter 3Student details
Enter Roll no:
3
Enter Name:
Anusha
Enter 3 subject marks:
56	78	67

Student details
*****1Student details
Roll no: 1
Name: Rekha
Subject 1: 34
Subject 2: 67
Subject 3: 87
Total: 0
Result: Fail

*****2Student details
Roll no: 2
Name: Suresh
Subject 1: 67
Subject 2: 89
Subject 3: 98
Total: 254
Result: Pass

*****3Student details
Roll no: 3
Name: Anusha
Subject 1: 56
Subject 2: 78
Subject 3: 67
Total: 201
Result: Pass

LAB 8A: Write a program to demonstrate multiple inheritance and use of implementing interfaces

package LabPgm8a;
class Student
{
int rollNumber;
String name;
void getInfo ( int n, String a)
{
rollNumber = n;
name = a;
}
void putInfo( )
{
System.out.println("Roll No: " + rollNumber );
System.out.println("Name: " + name );
}
}

package LabPgm8a;
public interface Test
{
float m1=45, m2=78;
void putMarks();
}

package LabPgm8a;
public class Result extends Student implements Test
{
float total;
public void putMarks()
{
System.out.println("Marks obtained are: ");
System.out.println("Marks1: " + m1);
System.out.println("Marks2: " + m2);
}
void display( )
{
total = m1 + m2;
putInfo( );
putMarks();
System.out.println("Total score = " + total );
}
}

package LabPgm8a;
import java.util.*;

public class Pgm8a
{
public static void main( String args [ ] )
{
Scanner in = new Scanner(System.in);
Result student1 = new Result( );

int rno;
String name;

System.out.println("Enter Roll No: ");
rno = in.nextInt();

System.out.println("Enter Name: ");
name = in.next();

student1.getInfo(rno, name);
student1.display();
}
}

OUTPUT:

Enter Roll No:
1
Enter Name:
Priya

Roll No: 1
Name: Priya
Marks obtained are:
Marks1: 45.0
Marks2: 78.0
Total score = 123.0

LAB 9A: Illustrate creation of thread by
b) Implementing Runnable Interfaces

package JavaLab9a;

{
public void run()
{
System.out.println("Welcome to Java Lab.");
}
public static void main(String[] args)
{
}
}

OUTPUT:

Welcome to Java Lab.

b) Implementing Runnable Interfaces
package JavaLab9a;

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

t.start();

System.out.println(t.getName());
}
@Override public void run()
{
System.out.println("Inside run method");
}
}

OUTPUT:

Runnable Interface
Inside run method

LAB 11A: Create a package „BCA‟ in your current working directory.
a. Create a class student in the above package with the following attributes: Name, age, gender. Include appropriate constructor and a method for displaying the details.
b. Import above package and access the member variables and function contained in a package.

package BCA;

public class Student
{
String name, gender;
int age;

public Student(String n, String g, int a)
{
name = n;
gender = g;
age = a;
}
public void display()
{
System.out.println("Name: " +name);
System.out.println("Gender: " +gender);
System.out.println("Age: " +age);
}
}

package JavaLab11a;

import BCA.*;

public class Lab11a
{
public static void main(String args[])
{
Student s = new Student("Rekha", "Female", 23);
s.display();
}
}

OUTPUT:

Name: Rekha
Gender: Female
Age: 23```