0% found this document useful (0 votes)
10 views

Final OOP Manual-2

PMC TECH aims to excel in technical education through innovative teaching and multidisciplinary research, with a mission to provide quality education and industry collaboration. The Department of Computer Science & Engineering focuses on equipping graduates with skills for complex engineering problems and lifelong learning. The Object Oriented Programming Laboratory course emphasizes practical software development skills using Java, covering various programming concepts and applications.

Uploaded by

Sagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Final OOP Manual-2

PMC TECH aims to excel in technical education through innovative teaching and multidisciplinary research, with a mission to provide quality education and industry collaboration. The Department of Computer Science & Engineering focuses on equipping graduates with skills for complex engineering problems and lifelong learning. The Object Oriented Programming Laboratory course emphasizes practical software development skills using Java, covering various programming concepts and applications.

Uploaded by

Sagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Vision and Mission of the Institute

Vision:
PMC TECH strives to achieve excellence in technical Education through innovative teaching, learning
and applied Multidisciplinary research with professional and ethical practices.
Mission:
PMC TECH will Endeavour
 To become the state of art teaching and learningcenter for Engineering and Technology,
Research and Management Studies
 To have world class infrastructure for providing quality education and research towards
creativity,self discipline and ethical values
 To associate with industry, R&D and business organizations and to have connectivity with the
society
 To create knowledge, based professionals to enrich their quality of life by empowering self and
family.

Department of Computer Science & Engineering


Vision and Mission of the Department
Vision:
Envisions Computer Science Engineering Graduates with profound skills and knowledge
embedded with innovative thinking for entrepreneurial, career and societal needs.

Mission:
M1: To imbibe high quality knowledge, skills and practices of computer science engineering through
quality infrastructure and resources.
M2: To endow the students to solve simple solutions to complex engineering problems through
software.
M3: To provide strong software development skills for lifelong learning, to meet the challenges of
industry and society.

PROGRAM OUTCOMES:
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.

Programme Specific Outcomes (PSOs):


PSO1: Apply standard practices in software development using open source programming
environments to deliver a high quality and cost effective products and solutions.

PSO2: Design, analyze and develop systems in the areas of networking, software engineering,
artificial intelligence, machine learning, Internet of Things and Cloud computing.

PSO3: Apply programming skill, Agile and Extreme Programming to solve the industrial and societal
problems.
CS3381 OBJECT ORIENTED PROGRAMMING LABORATORY (2021-REGULATION)

COURSE OBJECTIVES:

 To build software development skills using java programming for real-world applications.
 To understand and apply the concepts of classes, packages, interfaces, inheritance, exception handling
and file processing.
 To develop applications using generic programming and event handling

LIST OF EXPERIMENTS:
1. Solve problems by using sequential search, binary search, and quadratic sorting algorithms
(selection, insertion)
2. Develop stack and queue data structures using classes and objects.
3. Develop a java application with an Employee class with Emp_name, Emp_id, Address, Mail_id,
Mobile_no as members. Inherit the classes, Programmer, Assistant Professor, Associate
Professor and Professor from employee class. Add Basic Pay (BP) as the member of all the
inherited classes with 97% of BP as DA, 10 % of BP as HRA, 12% of BP as PF, 0.1% of BP for
staff club funds. Generate pay slips for the employees with their gross and net salary.
4. Write a Java Program to create an abstract class named Shape that contains two integers and an
empty method named printArea(). Provide three classes named Rectangle, Triangle and Circle
such that each one of the classes extends the class Shape. Each one of the classes contains only
the method printArea( ) that prints the area of the given shape
5. Solve the above problem using an interface.
6. Implement exception handling and creation of user defined exceptions.
7. Write a java program that implements a multi-threaded application that has three threads. First
thread generates a random integer every 1 second and if the value is even, the second thread
computes the square of the number and prints. If the value is odd, the third thread will print the
value of the cube of the number.
8. Write a program to perform file operations.
9. Develop applications to demonstrate the features of generics classes.
10. Develop applications using JavaFX controls, layouts and menus.
11. Develop a mini project for any application using Java concepts.
TOTAL: 45 PERIODS

COURSE OUTCOMES:
On completion of this course, the students will be able to

CO1 : Design and develop java programs using object oriented programming concepts
CO2 : Develop simple applications using object oriented concepts such as package, exceptions
CO3: Implement multithreading, and generics concepts
CO4 : Create GUIs and event driven programming applications for real world problems
CO5: Implement and deploy web applications using Java
ATTAINMENT OF PROGRAM OUTCOMES & PROGRAM SPECIFIC OUTCOMES

DATE Name of the Experiment Course Program Program


SL.N Outcome outcomes Specific
O attained attained Outcomes
attained
1. Solve problems by using sequential search, CO1 PO1,PO2, PSO1, PSO2
binary search, and quadratic sorting algorithms PO3, PO5
(selection, insertion)
2. . Develop stack and queue data structures using CO1,2 PO1,PO2, PSO1, PSO2
classes and objects PO3, PO5
3. Pay slip Generation using Inheritance CO2 PO1,PO2, PSO1, PSO2
PO3, PO5
4. Java Program to create an abstract classthat CO2 PO1,PO2, PSO1, PSO2
prints the area of the given shape. PO3, PO5
5. Solve the above problem using an interface. CO3 PO1,PO2, PSO1, PSO2
PO3, PO5
6. Implement exception handling and creation of CO3 PO1,PO2, PSO1, PSO2
user defined exceptions. PO3, PO5
7. java program that implements a multi-threaded CO4 PO1,PO2, PSO1, PSO2
application that has three threads. PO3, PO5
8. program to perform file operations. CO4,5 PO1,PO2, PSO1, PSO2
PO3, PO5
9. Develop applications to demonstrate the CO5 PO1,PO2, PSO1, PSO2
features of generics classes. PO3, PO5
10. Develop applications using JavaFX controls, CO5 PO1,PO2, PSO1, PSO2
layouts and menus. PO3, PO5
11. mini project for any application using Java CO2,3,4 PO1,PO2, PSO1, PSO2
concepts. PO3, PO5

CONTENT BEYOND EXPERIMENTS IN OBJECT ORIENTED PROGRAMMING LAB

1. Implementationissuesrelatedtoobject- CO1,2,3,4 PO1,PO2, PSO1, PSO2


orientedtechniques ,5 PO3, PO5
2. Understandingstructsandapplythemin C+ CO1,2,3,4 PO1,PO2, PSO1, PSO2
+programs. ,5 PO3, PO5
COURSE OUTCOME (COs)

CO Level Outcome

C207.1 K3 Demonstrate the concepts of classes, Packages, interface &inheritance

C207.2 Execute java program for practicing exception handling of files.


K3
C207.3 K3 Execute java program for practicing exception handling of files.

C207.4 K3 Implement application using generic programming & event handling

C207.5 K3 Develop java program for practicing threads and IO.

CO & PO MAPPING

P P P P P P P P P PO PO PO PS PS PS
CO
O1 O2 O3 O4 O5 O6 O7 O8 O9 10 11 12 O1 O2 O3
C20
3 3 3 2 1 - - 1 2 1 - 2 3 3 3
7.1
C20
3 3 3 3 3 - - 1 2 1 - 2 3 3 3
7.2
C20
3 3 3 3 3 - - 1 2 1 - 2 3 3 3
7.3
C20
3 3 3 3 3 - - 1 2 1 - 2 3 3 3
7.4
C20
3 3 3 3 3 - - 1 2 1 - 2 3 3 3
7.5
C20
3 3 3 2.8 2.6 - - 1 2 1 - 2 3 3 3
7
CS3381-OBJECT ORIENTED
PROGRAMMINGLABORATORY

CONTENTS

SL.NO DATE Name of the Experiment Staff Remarks


Signature
1. Solve problems by using sequential search, binary
search, and quadratic sorting algorithms (selection,
insertion)
2. Develop stack and queue data structures using classes
and objects

3. Pay slip Generation using Inheritance

4. Java Program to create an abstract class that prints the


area of the given shape.
5. Solve the above problem using an interface.

6. Implement exception handling and creation of user


defined exceptions.
7. java program that implements a multi-threaded
application that has three threads
8. program to perform file operations.

9. Develop applications to demonstrate the features of


generics classes.
10. Develop applications using JavaFX controls, layouts and
menus.
11. mini project for any application using Java concepts.

CONTENT BEYOND EXPERIMENTS IN OBJECT ORIENTED PROGRAMMING LAB

1. Implementationissuesrelatedtoobject-orientedtechniques

2. Understandingstructsandapplythemin C++programs.
EX. NO:1
GENERATIONDATE:

Solve problems by using sequential search, binary


search, and quadratic sorting algorithms (selection,
insertion)

1.A) Sequential Search

PROGRAM:

import java.util.Scanner;
public class Lab_001 {
public static void main(String[] args)
{
intc,n,search,array[];
Scanner S=new Scanner(System.in);
System.out.println("enter the number of elements");
n=S.nextInt();
array=new int[n];
System.out.println("enter those elements:");
for(c=0;c<n;c++)
array[c]=S.nextInt();
System.out.println("enter value to find:");
search=S.nextInt();
for(c=0;c<n;c++)
{
if(array[c]==search){
System.out.println(search+"present at location"+(c+1));
break;
}
}
if(c==n)
System.out.println(search+"is not present in array:");
}
}

OUTPUT :

1.B) Binary Search

PROGRAM :

import java.util.*;
public class Lab_002 {

public static void main(String[] args) {


intnumArray[]={5,10,15,20,25,30,35};
System.out.println("The input array is:"+Arrays.toString(numArray));
int key=20;
System.out.println("\n key to be searched:"+key);
int first=0;
int last=numArray.length-1;
int mid=(first+last/2);
while(first<=last){
if(numArray[mid]<key){
first=mid+1;
}
else if(numArray[mid]==key){
System.out.println("elment is found at index:"+mid);
break;
}else{
last=mid+1;
}
mid=(first+last)/2;
}if(first>last){
System.out.println("element is not found!!");
}
}
}

OUTPUT :

1.C) Selection Sort

PROGRAM:

import java.util.Arrays;
public class SelectionSort {

public static void main(String[] args) {


inti, j, temp;
intarr[] = {3,6,4,9,5,8};
System.out.print("Sorting Array using Selection Sort Technique..\n");
for(i=0; i<5; i++)
{
for(j=i+1; j<5; j++)
{
if(arr[i] >arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
System.out.println("the sorted array is:"+Arrays.toString(arr));
}
}

}
}

OUTPUT :

1.D) Insertion sort

PROGRAM :

public class InsertionSortExample {


public static void sub(int array[]) {
int n = array.length;
for (int j = 1; j < n; j++) {
int key = array[j];
inti = j-1;
while ( (i> -1) && ( array [i] > key ) ) {
array [i+1] = array [i];
i--;
}
array[i+1] = key;
}
}

public static void main(String args[]){


int arr1[] = {9,14,3,2,43,11,58,22};
System.out.println("Before Insertion Sort");
for(int i:arr1){
System.out.print(i+" ");
}
System.out.println();

sub(arr1);//sorting array using insertion sort

System.out.println("After Insertion Sort");


for(int i:arr1){
System.out.print(i+" ");
}
}
}

OUTPUT :

EX NO:2
DATE :
Develop stack and queue data structures using classes and objects

2.A) stack using classes and objects

PROGRAM:

import java.util.*;
public class StackDemo { static void showpush(Stack st, int a) { st.push(new Integer(a));
System.out.println("push(" + a + ")");
System.out.println("stack: " + st);
}
static void showpop(Stack st) { System.out.print("pop -> ");
Integer a = (Integer) st.pop();
System.out.println(a);
System.out.println("stack: " + st);
}
public static void main(String args[]) { Stack st = new Stack();
System.out.println("stack: " + st);
showpush(st, 42);
showpush(st, 66);
showpush(st, 99);
showpop(st);
showpop(st);
showpop(st);
try { showpop(st);
}
catch (EmptyStackException e)
{ System.out.println("empty stack");
}}}
OUTPUT:

2.B)Queue using classes and objects

PROGRAM:

public class Queue


{
int SIZE = 5; int items[] = new int[SIZE];

int front, rear;


Queue() { front = -1; rear = -1;
}
boolean isFull()
{
if (front == 0 && rear == SIZE - 1)
{
return true;
}
return false;
}
boolean isEmpty()
{
if (front == -1)
return true;
else
return false;
}
void enQueue(int element)
{
if (isFull())
{
System.out.println("\nThe queue is full");
}
else
{ if (front == -1)
{
front = 0;
}
rear++;
items[rear] = element;
System.out.println("\nThe element " + element + " is inserted");
}}
int deQueue()
{
int element;
if (isEmpty())
{
System.out.println("\nThe queue is empty");
return (-1);
}
else
{
element = items[front];
if (front >= rear)
{
front = -1;
rear = -1;
}
else
{
front++;
}
System.out.println("\nThe element " +element + " is deleted");
return (element);
}}
void display()
{
int i;
if (isEmpty())
{
System.out.println("The queue is empty ");
}
else
{
System.out.println("\nThe elements of the queue are: ");
for (i = front; i <= rear; i++)
System.out.print(items[i] + " ");
}}
public static void main(String[] args)
{ Queue input_queue = new Queue();
for(int i = 1; i < 6; i ++)
{
input_queue.enQueue(i * 100);
}
System.out.println("The queue is defined as: " + input_queue);
input_queue.enQueue(6);
input_queue.display();
input_queue.deQueue();
input_queue.display();
}
}

OUTPUT:
EX NO: 3
DATE :

Develop a java application with Employee class with Emp_name, Emp_id, Address, Mail_id,
Mobile_no as members. Inherit the classes, Programmer, Assistant Professor, Associate
Professor and Professor from employee class. Add Basic Pay (BP) as the member of all the
inherited classes with 97% of BP as DA, 10 % of BP as HRA, 12% of BP as PF, 0.1% of BP for
staff club fund. Generate pay slips for the employees with their gross and net salary

PROGRAM :

import java.util.Scanner;

class Employee{

String Emp_name;

intEmp_id;

String Address;

String Mail_id;
intMobile_no;

void display(){

System.out.println(Emp_name);

System.out.println(Mail_id);

class Programmer extends Employee{

int BP;

/*int DA= (int) (0.97*BP);

HRA=(int) (0.10*BP);

PF=(int) (0.12*BP); */

void display(){

System.out.println(BP);

System.out.println("DA"+0.97*BP);

System.out.println("HRA"+0.10*BP);

System.out.println("PF"+0.12*BP);

System.out.println("SATFF CLUD FUND"+0.001*BP);

class Assistant_Professor extends Employee{


int BP;

void display(){

System.out.println(BP);

System.out.println("DA"+0.97*BP);

System.out.println("HRA"+0.10*BP);

System.out.println("PF"+0.12*BP);

System.out.println("SATFF CLUD FUND"+0.001*BP);

}}

class Associate_Professor extends Employee{

int BP;

void display(){

System.out.println(BP);

System.out.println("DA"+0.97*BP);

System.out.println("HRA"+0.10*BP);

System.out.println("PF"+0.12*BP);

System.out.println("SATFF CLUD FUND"+0.001*BP);

class Professor extends Employee{

int BP;
void display(){

System.out.println(BP);

System.out.println("DA"+0.97*BP);

System.out.println("HRA"+0.10*BP);

System.out.println("PF"+0.12*BP);

System.out.println("SATFF CLUD FUND"+0.001*BP);

public class Main {

public static void main(String[] args) {

System.out.println("\n 1.Programmer\n2.Assistant_Professor\n3.Associate_Professor\
n4.Professor");

Scanner input=new Scanner(System.in);

System.out.print("Enter an integer: ");

intch=input.nextInt();

switch (ch) {

case 1:

Employee e1=new Employee();

Programmer p1=new Programmer();

e1.Emp_name="ABC";

e1.Address="y-city";

e1.Mail_id="[email protected]";
e1.Emp_id=567;

e1.Mobile_no=2345678;

p1.BP=15000;

p1.display();

e1.display();

break;

case 2:

Employee e2=new Employee();

Assistant_Professor p2=new Assistant_Professor();

e2.Emp_name="DEF";

e2.Address="A-city";

e2.Mail_id="[email protected]";

e2.Emp_id=123;

e2.Mobile_no=987321;

p2.BP=30000;

p2.display();

e2.display();

break;

case 3:

Employee e3=new Employee();

Associate_Professor p3=new Associate_Professor();

e3.Emp_name="GHF";
e3.Address="B-city";

e3.Mail_id="[email protected]";

e3.Emp_id=456;

e3.Mobile_no=98710;

p3.BP=30000;

p3.display();

e3.display();

break;

case 4:

Employee e4=new Employee();

Professor p4=new Professor();

e4.Emp_name="KANNAN";

e4.Address="TRICHY";

e4.Mail_id="[email protected]";

e4.Emp_id=789;

e4.Mobile_no=9810;

p4.BP=30000;

p4.display();

e4.display();

break;

case 5:

//exit(1);
default:

System.out.println("enter correct choice");

OUTPUT:
EX NO: 4
DATE :

Write a Java Program to create an abstract class named Shape that contains two integers and an
empty method named printArea(). Provide three classes named Rectangle, Triangle and Circle
such that each one of the classes extends the class Shape. Each one of the classes contains only
the method printArea( ) that prints the area of the given shape.

PROGRAM:

import java.util.Scanner;
abstract class Shape {

int a = 10, b = 2;

Shape(int a, int b){


this.a=a;
this.b=b;
}

abstract void Printarea();

class Rectangle extends Shape {

Rectangle(int a, int b) {
super(a, b);
}

void Printarea() {
System.out.println("area of rectangle is " + (a * b));
}

class Triangle extends Shape {

Triangle(int a, int b) {
super(a, b);
}

void Printarea(){
System.out.println("area of triangle is " + (0.5 * a * b));
}

class Circle extends Shape {

Circle(int a, int b) {
super(a, b);
}

void Printarea() {
System.out.println("area of circle is " + (3.14 * a * a));
}

public class Z {

public static void main(String[] args) {


Shape shape=null;

String input;
int width, height;

while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("which shape? circle/rectangle/triangle (write any other thing for quitting): ");
input = scanner.nextLine();
if(!"circle".equalsIgnoreCase(input) && !"rectangle".equalsIgnoreCase(input)
&& !"triangle".equalsIgnoreCase(input) ){
System.exit(0);
}
System.out.println("height: ");
height =scanner.nextInt();

System.out.println("width: ");
width = scanner.nextInt();

if("circle".equalsIgnoreCase(input)){
shape=new Circle(width, height);
}
else if("rectangle".equalsIgnoreCase(input)){
shape=new Rectangle(width, height);
}
else{ // == triangle
shape=new Triangle(width, height);
}
shape.Printarea();
}
}
}

OUTPUT:

EX NO:5
DATE :

Solve the above problem using an interface.

PROGRAM:

class Rectangle implements Area{


public double Compute(double l,double b){
return(l*b);
}
}
class Triangle implements Area{
public double Compute(double b,double h)
{
return(b*h/2);
}
}
public class Mainarea {

public static void main(String[] args) {


Rectangle rect=new Rectangle();
double RArea=rect.Compute(10,20);
System.out.println("The area of Rectangle is"+RArea);
Triangle tri=new Triangle();
double TArea=tri.Compute(10,20);
System.out.println("The area of the Trinagle is"+TArea);
}
}

OUTPUT:

EX NO:6
DATE :

Implement exception handling and creation of user defined exceptions.

6.A) pre-defined exceptions

PROGRAM:

import java.util.Scanner;
public class Predefinedexceptions {

public static void main(String[] args) {


try{
Scanner sc=new Scanner(System.in);
System.out.println("enter the first number:");
int a=sc.nextInt();
System.out.println("enter the second number:");
int b=sc.nextInt();
if(a<b){
System.out.println("Dinominator is Greater!!");
}
else{
int c=a/b;
System.out.println("the result is :"+c);
}
}
catch(ArithmeticException e){
System.out.println("divide by Zero");
}
}
}
OUTPUT :

6.B) user defined exceptions

PROGRAM:

import java.util.*;
class NegativeAmtException extends Exception
{
String msg;
NegativeAmtException(String msg)
{
this.msg=msg;
}
public String toString()
{
return msg;
}
}
public class Userdefined {

public static void main(String[] args) {


Scanner s=new Scanner(System.in);
System.out.print("Enter Amount:");
int a=s.nextInt();
try
{
if(a<0)
{
throw new NegativeAmtException("Invalid Amount");
}
System.out.println("Amount Deposited");
}
catch(NegativeAmtException e)
{
System.out.println(e);
}

}
}

OUTPUT :

EX NO:7
DATE :

Write a java program that implements a multi-threaded application that has three threads. First
thread generates a random integer every 1 second and if the value is even, the second thread
computes the square of the number and prints. If the value is odd, the third thread will print the
value of the cube of the number.

PROGRAM :

import java.util.Random;
class Square extends Thread
{
int x;
Square(int n)
{
x = n;
}
public void run()
{
intsqr = x * x;
System.out.println("Square of " + x + " = " + sqr );
}
}
class Cube extends Thread
{
int x;
Cube(int n)
{x = n;
}
public void run()
{
int cub = x * x * x;
System.out.println("Cube of " + x + " = " + cub );
}
}
class Number extends Thread
{
public void run()
{
Random random = new Random();
for(inti =0; i<2; i++)
{
intrandomInteger = random.nextInt(100);
System.out.println("Random Integer generated : " + randomInteger);
Square s = new Square(randomInteger);
s.start();
Cube c = new Cube(randomInteger);
c.start();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
System.out.println(ex);
}
}
}
}
public class MultiThread {
public static void main(String args[])
{
Number n = new Number();
n.start();
}
}

OUTPUT:
EX NO:8
DATE :

Write a program to perform file operations.

FILE OPERATIONS:

1.creating a File
2.Get File Information
3.Write to a File
4.Read from a File
5.Delete a File

PROGRAM:

import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Handling {

public static void main(String[] args) {


//file creation
try {
// Creating an object of a file
File f0 = new File("C:sample.txt");
if (f0.createNewFile()) {
System.out.println("File " + f0.getName() + " is created successfully.");
} else {
System.out.println("File is already exist in the directory.");
}
} catch (IOException exception) {
System.out.println("An unexpected error is occurred.");
exception.printStackTrace();
}
//getting file information
File f0 = new File("C:sample.txt");
if (f0.exists()) {
// Getting file name
System.out.println("The name of the file is: " + f0.getName());

// Getting path of the file


System.out.println("The absolute path of the file is: " + f0.getAbsolutePath());

// Checking whether the file is writable or not


System.out.println("Is file writeable?: " + f0.canWrite());

// Checking whether the file is readable or not


System.out.println("Is file readable " + f0.canRead());

// Getting the length of the file in bytes


System.out.println("The size of the file in bytes is: " + f0.length());
} else {
System.out.println("The file does not exist.");
}
//writing into file
try {
FileWriter fwrite = new FileWriter("C:sample.txt");
// writing the content into the FileOperationExample.txt file
fwrite.write("A named location used to store related information is referred to as a File.");

// Closing the stream


fwrite.close();
System.out.println("Content is successfully wrote to the file.");
} catch (IOException e) {
System.out.println("Unexpected error occurred");
e.printStackTrace();
}
//read from the file
try {
// Create f1 object of the file to read data
File f1 = new File("C:sample.txt");
Scanner dataReader = new Scanner(f1);
while (dataReader.hasNextLine()) {
String fileData = dataReader.nextLine();
System.out.println(fileData);
}
dataReader.close();
} catch (FileNotFoundException exception) {
System.out.println("Unexcpected error occurred!");
exception.printStackTrace();
}
//delecting a file
if (f0.delete()) {
System.out.println(f0.getName()+ " file is deleted successfully.");
} else {
System.out.println("Unexpected error found in deletion of the file.");
}
}
}

OUTPUT:

EX NO:9
DATE :

Develop applications to demonstrate the features of generics classes.

PROGRAM:

public class GenericClasses {

public static void main(String[] args) {


// initialize generic class
// with Integer data
GenericsClass<Integer> intObj = new GenericsClass<>(5);
System.out.println("Generic Class returns: " + intObj.getData());

// initialize generic class


// with String data
GenericsClass<String> stringObj = new GenericsClass<>("Java Programming");
System.out.println("Generic Class returns: " + stringObj.getData());
}
}

// create a generics class


class GenericsClass<T> {

// variable of T type
private T data;

public GenericsClass(T data) {


this.data = data;
}

// method that return T type variable


public T getData() {
return this.data;
}
}

OUTPUT :

EX NO:10
DATE :

Develop applications using JavaFX controls, layouts and menus.

PROGRAM :

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class FDX1 extends Application {

@Override
public void start(Stage primaryStage) {
Text text1 = new Text("Email");

//creating label password


Text text2 = new Text("Password");

//Creating Text Filed for email


TextField textField1 = new TextField();

//Creating Text Filed for password


PasswordField textField2 = new PasswordField();

//Creating Buttons
Button button1 = new Button("Submit");
Button button2 = new Button("Clear");

//Creating a Grid Pane


GridPane gridPane = new GridPane();

//Setting size for the pane


gridPane.setMinSize(800, 200);

//Setting the padding


gridPane.setPadding(new Insets(10, 10, 10, 10));

//Setting the vertical and horizontal gaps between the columns


gridPane.setVgap(5);
gridPane.setHgap(5);

//Setting the Grid alignment


gridPane.setAlignment(Pos.CENTER);

//Arranging all the nodes in the grid


gridPane.add(text1, 0, 0);
gridPane.add(textField1, 1, 0);
gridPane.add(text2, 0, 1);
gridPane.add(textField2, 1, 1);
gridPane.add(button1, 0, 2);
gridPane.add(button2, 1, 2);
//Styling nodes
button1.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;");
button2.setStyle("-fx-background-color: darkslateblue; -fx-text-fill: white;");

text1.setStyle("-fx-font: normal bold 20px 'serif' ");


text2.setStyle("-fx-font: normal bold 20px 'serif' ");
gridPane.setStyle("-fx-background-color: BEIGE;");

//Creating a scene object


Scene scene = new Scene(gridPane);

//Setting title to the Stage


primaryStage.setTitle("CSS Example");

//Adding scene to the stage


primaryStage.setScene(scene);

//Displaying the contents of the stage


primaryStage.show();
}

public static void main(String[] args) {


launch(args);
}
}

OUTPUT :

EX NO:11
DATE :

Develop a mini project

11.A)password generator

PROGRAM :

import java.util.*;
public class PassGen {
public static void main(String[] args)
{
// Length of your password as I have choose
// here to be 8
int length = 10;
System.out.println(geek_Password(length));
}

// This our Password generating method


// We have use static here, so that we not to
// make any object for it
static char[] geek_Password(int len)
{
System.out.println("Generating password using random() : ");
System.out.print("Your new password is : ");

// A strong password has Cap_chars, Lower_chars,


// numeric value and symbols. So we are using all of
// them to generate our password
String Capital_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String Small_chars = "abcdefghijklmnopqrstuvwxyz";
String numbers = "0123456789";
String symbols = "!@#$%^&*_=+-/.?<>)";

String values = Capital_chars + Small_chars +


numbers + symbols;

// Using random method


Random rndm_method = new Random();

char[] password = new char[len];


for (int i = 0; i < len; i++)
{
// Use of charAt() method : to get character value
// Use of nextInt() as it is scanning the value as int
password[i] =
values.charAt(rndm_method.nextInt(values.length()));

}
return password;
}
}

OUTPUT :

11.B)Income tax system

PROGRAM :

import java.util.Scanner;
public class Income {

public static void main(String[] args) {


{
double tax=0,it;
Scanner sc=new Scanner(System.in);
System.out.println("Enter income ");
it=sc.nextDouble();
if(it<=200000)
tax=0;
else if(it<=300000)
tax=0.1*(it-200000);
else if(it<=500000)
tax=(0.2*(it-300000))+(0.1*100000);
else if(it<=1000000)
tax=(0.3*(it-500000))+(0.2*200000)+(0.1*100000);
else
tax=(0.4*(it-1000000))+(0.3*500000)+(0.2*200000)+(0.1*100000);
System.out.println("Income tax amount is "+tax);
}
}
}

OUTPUT :

11.C) QR code generator

PROGRAM:

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Snap extends javax.swing.JFrame {
public Snap() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {

jLabel1 = new javax.swing.JLabel();


jLabel2 = new javax.swing.JLabel();
link = new javax.swing.JFormattedTextField();
jButton1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("qr generator");

jLabel2.setText("select link");
link.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
linkActionPerformed(evt);
}
});

jButton1.setText("submit");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(layout.createSequentialGroup()
.addGap(154, 154, 154)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(67, 67, 67)
.addComponent(jLabel2)
.addGap(26, 26, 26)
.addComponent(link, javax.swing.GroupLayout.PREFERRED_SIZE, 123,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(132, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(51, 51, 51))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addComponent(jLabel1)
.addGap(72, 72, 72)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI
NE)
.addComponent(jLabel2)
.addComponent(link, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jButton1)
.addContainerGap(117, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void linkActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
try{
String snapData=link.getText();
String filepath="C:\\Users\\Admin\\Documents\\NetBeansProjects\\snap\\qr.png";
String charset="UTF-8";

Map <EncodeHintType,ErrorCorrectionLevel> hintMap= new HashMap


<EncodeHintType,ErrorCorrectionLevel> ();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
BitMatrix matrix= new MultiFormatWriter().encode(
new String (snapData.getBytes(charset),charset),
BarcodeFormat.QR_CODE,200,200,hintMap);

MatrixToImageWriter.writeToFile(matrix, filepath.substring(filepath.lastIndexOf('.')+1),new
File(filepath));
System.out.println("Qr code has been generated at the location "+filepath);

JFrame frame = new JFrame();


ImageIcon icon = new ImageIcon("C:\\Users\\Admin\\Documents\\NetBeansProjects\\
snap\\qr.png");
JLabel label = new JLabel(icon);
frame.add(label);
frame.setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
catch(Exception e){
System.out.println(e);
}
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(qr.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(qr.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(qr.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(qr.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new qr().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JFormattedTextField link;
// End of variables declaration
}
OUTPUT:

You might also like