OOps Record
OOps Record
1a SEQUENTIAL SEARCH
1b BINARY SEARCH
1c SELECTION SORT
1d INSERTION SORT
AIM
To write a java program to implement linear searching algorithm.
ALGORITHM
PROGRAM
import java.util.*;
class LinearSearchExample2
{
public static void main(String args[])
{
int c, n, search, array[];
Scanner in = new Scanner(System.in);
System.out.println("Enter number of elements");
n = in.nextInt();
array = new int[n];
System.out.println("Enter those " + n + " elements");
for (c = 0; c < n; c++)
array[c] = in.nextInt();
System.out.println("Enter value to find");
search = in.nextInt();
for (c = 0; c < n; c++)
{
if (array[c] == search)
{
System.out.println(search + " is present at location " + (c + 1) + ".");
break;
}
}
if (c == n)
System.out.println(search + " isn't present in array.");
}
}
RESULT
Thus the java program to perform linear searching algorithms was executed and verified successfully.
EX NO : 1 b BINARY SEARCH
Date :
AIM
ALGORITHM
RESULT:
Thus the java program to perform binary searching algorithms was executed and verified successfully.
Ex No : 1 c SELECTION SORT
Date :
AIM
To write a java program to implement selection sorting algorithm.
ALGORITHM
{
if(arr[i] > arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
RESULT:
Thus the java program to perform selection sorting algorithms was executed and verified
successfully.
Ex No:1 d INSERTION SORT
Date :
AIM
To write a java program to implement insertion sorting algorithm.
ALGORITHM
PROGRAM
import java.util.Scanner;
public class CodesCracker
{
public static void main(String[] args)
{
int n, i, j, element;
Scanner scan = new Scanner(System.in);
System.out.print("Enter the Size of Array: ");
n = scan.nextInt();
int[] arr = new int[n]; System.out.print("Enter " +n+ " Elements: ");
for(i=0; i<n; i++)
arr[i] = scan.nextInt();
for(i=1; i<n; i++)
{
element = arr[i];
for(j=(i-1); j>=0 && arr[j]>element; j--)
arr[j+1] = arr[j];
arr[j+1] = element;
}
System.out.println("\nThe new sorted array is: ");
for(i=0; i<n; i++)
RESULT:
Thus the java program to perform selection sorting algorithms was executed and verified
successfully.
Ex No: 2a DEVELOP STACK DATA STRUCTURES USING CLASSES AND OBJECTS
Date :
AIM
To develop a stack program in java using classes and objects.
ALGORITHM
1. Create class stack and declare methods for push and pop.
2. Check whether the stack is full. If the stack is full, displays stack is full
3. If the stack is not full, increment the top pointer.
4. Add data element to the stack location where top is pointing.
5. If the stack is not empty, accesses the data element at which top is pointing.
6. Decrement the value of top by 1.
7. Return success.
PROGRAM
import java.io.*;
import java.util.*;
public class Stack1
{
static final int MAX=5;
int top=-1;
{
int option;
Scanner sc = new Scanner(System.in);
Stack1 s = new Stack1();
while(true)
{
System.out.println("Enter the choice You want to perform on the stack: ");
System.out.println(" 1. push \n 2. Pop \n 3. Display \n 4. peep \n 5. Exit");
System.out.println("Enter your option: ");
option = sc.nextInt();
switch(option)
{
case 1:
System.out.println("Enter the element you want to push into the stack: ");
s.push(sc.nextInt());
break;
case 2:
s.pop();
break;
case 3:
if(top==MAX-1)
{
System.out.println("Stack is FULL!");
}
else
{
top++;
stack[top]=val;
System.out.println("Element added to the stack is: "+val);
display();
}
}
{
System.out.println("Stack is EMPTY!");
}
else
{
x=stack[top];
System.out.println("The element deleted from the stack is: "+x);
top--;
display();
}
}
public void peep()
{
int n;
n=stack[top];
System.out.println("The value at the top of the stack is: "+n);
}
public void display()
{
int i;
if(top==-1)
System.out.println("STACK IS EMPTY!");
else
{
for(i=0; i<=top; i++)
System.out.println("The elements in the stack are: "+stack[i]);
}
}
}
RESULT
Thus the java program to perform Stack data structures using classes and objects is
executed and verified successfully.
Ex No: 2b DEVELOP QUEUE DATA STRUCTURES USING CLASSES AND OBJECTS
Date :
AIM
To write a java program to implement queue data structures using classes and objects.
ALGORITHM
1. Initialize the array variable for storing elements and declare the required variable.
2. Define a function to insert, delete, and display the data items.
3. For insert function, get the new elements, if the rear is greater than array size, display queue is
“overflow” otherwise, insert the new element and increment the top pointer.
4. For delete function, if the queue is empty, then display “queue is overflow” otherwise decrement
the top pointer.
5. For display function, apply the loop to display queue elements.
PROGRAM
import java.util.Random;
import java.util.Scanner;
class Que
{
private int size;
private int front = -1;
private int rear = -1;
private Integer[] queArr;
public Que(int size) {
this.size = size;
queArr = new Integer[size];
}
public void insert(int item)
{
if(rear == size-1)
{
System.out.println("queue is overflowing");
}
else if(front==-1) {
rear++;
queArr[rear] = item;
front = rear;
}
else
{
rear++;
queArr[rear] = item;
}
}
public void delete()
{
if(front == -1) {
System.out.println("queue is underflow");
}
else if(front==rear) {
System.out.println("removing "+queArr[front]);
queArr[front] = null;
front--;
rear--;
}
else
{
System.out.println("removing "+queArr[front]);
queArr[front] = null;
for(int i=front+1;i<=rear;i++) {
queArr[i-1]=queArr[i];
}
rear--;
}
}
{
System.out.println("queue is:");
for(int i=front;i<=rear;i++) {
System.out.print(queArr[i]+"\t");
}
}
}
}
public class TestQueue {
public static void main(String[] args)
{
System.out.println("Hi user!");
break;
case 2:
que.delete();
break;
case 3:
Random rand = new Random();
rand.nextInt(size);
break;
}
que.display();
System.out.println("\nDo you want to continue (Type y or n) \n");
ch = scan.next().charAt(0);
}while(!(ch=='N' || ch=='n'));
}
}
RESULT
Thus the java program to perform Queue data structures using classes and objects is
executed and verified successfully.
Ex No: 3 GENERATE PAYSLIP USING INHERITANCE
Date :
AIM
To develop a java application to generate pay slip for different category of employees using
the concept of inheritance.
ALGORITHM
1. Create the class employee with name, Empid, address, mailid, mobileno as members.
2. Inherit the classes programmer, asstprofessor,associateprofessor and professor from
employee class.
3. Add Basic Pay (BP) as the member of all the inherited classes.
4. Calculate DA as 97% of BP, HRA as 10% of BP, PF as 12% of BP, Staff club fund as 0.1% of
BP.
5. Calculate gross salary and net salary.
6. Generate payslip for all categories of employees.
7. Create the objects for the inherited classes and invoke the necessary methods to display the
Payslip.
PROGRAM
import java.util.*;
class employee
{
int empid;
long mobile;
String name, address, mailid;
Scanner get = new Scanner(System.in);
void getdata()
{
System.out.println("Enter Name of the Employee");
name = get.nextLine();
System.out.println("Enter Mail id");
mailid = get.nextLine();
System.out.println("Enter Address of the Employee:");
address = get.nextLine();
System.out.println("Enter employee id ");
empid = get.nextInt();
System.out.println("Enter Mobile Number");
mobile = get.nextLong();
}
void display()
{
System.out.println("Employee Name: "+name);
System.out.println("Employee id : "+empid);
System.out.println("Mail id : "+mailid);
System.out.println("Address: "+address);
System.out.println("Mobile Number: "+mobile);
}
}
class programmer extends employee
{
double salary,bp,da,hra,pf,club,net,gross;
void getprogrammer()
{
System.out.println("Enter basic pay");
bp = get.nextDouble();
}
void calculateprog()
{
da=(0.97*bp);
hra=(0.10*bp);
pf=(0.12*bp);
club=(0.1*bp);
gross=(bp+da+hra);
net=(gross-pf-club);
System.out.println("************************************************");
System.out.println("PAY SLIP FOR PROGRAMMER");
System.out.println("************************************************");
System.out.println("Basic Pay:Rs"+bp);
System.out.println("DA:Rs"+da);
System.out.println("PF:Rs"+pf);
System.out.println("HRA:Rs"+hra);
System.out.println("CLUB:Rs"+club);
System.out.println("GROSS PAY:Rs"+gross);
System.out.println("NET PAY:Rs"+net);
}
}
class asstprofessor extends employee
{
double salary,bp,da,hra,pf,club,net,gross;
void getasst()
{
System.out.println("Enter basic pay");
bp = get.nextDouble();
}
void calculateasst()
{
da=(0.97*bp);
hra=(0.10*bp);
pf=(0.12*bp);
club=(0.1*bp);
gross=(bp+da+hra);
net=(gross-pf-club);
System.out.println("************************************************");
System.out.println("PAY SLIP FOR ASSISTANT PROFESSOR");
System.out.println("************************************************");
System.out.println("Basic Pay:Rs"+bp);
System.out.println("DA:Rs"+da);
System.out.println("HRA:Rs"+hra);
System.out.println("PF:Rs"+pf);
System.out.println("CLUB:Rs"+club);
System.out.println("GROSS PAY:Rs"+gross);
System.out.println("NET PAY:Rs"+net);
}
}
class associateprofessor extends employee
{
double salary,bp,da,hra,pf,club,net,gross;
void getassociate()
{
System.out.println("Enter basic pay");
bp = get.nextDouble();
}
void calculateassociate()
{
da=(0.97*bp);
hra=(0.10*bp);
pf=(0.12*bp);
club=(0.1*bp);
gross=(bp+da+hra);
net=(gross-pf-club);
System.out.println("************************************************");
System.out.println("PAY SLIP FOR ASSOCIATE PROFESSOR");
System.out.println("************************************************");
System.out.println("Basic Pay:Rs"+bp);
System.out.println("DA:Rs"+da);
System.out.println("HRA:Rs"+hra);
System.out.println("PF:Rs"+pf);
System.out.println("CLUB:Rs"+club);
System.out.println("GROSS PAY:Rs"+gross);
System.out.println("NET PAY:Rs"+net);
}
}
class professor extends employee
{
double salary,bp,da,hra,pf,club,net,gross;
void getprofessor()
{
System.out.println("Enter basic pay");
bp = get.nextDouble();
}
void calculateprofessor()
{
da=(0.97*bp);
hra=(0.10*bp);
pf=(0.12*bp);
club=(0.1*bp);
gross=(bp+da+hra);
net=(gross-pf-club);
System.out.println("************************************************");
System.out.println("PAY SLIP FOR PROFESSOR");
System.out.println("************************************************");
System.out.println("Basic Pay:Rs"+bp);
System.out.println("DA:Rs"+da);
System.out.println("HRA:Rs"+hra);
System.out.println("PF:Rs"+pf);
System.out.println("CLUB:Rs"+club);
System.out.println("GROSS PAY:Rs"+gross);
System.out.println("NET PAY:Rs"+net);
}
}
class salary
{
public static void main(String args[])
{
int choice,cont;
do
{
System.out.println("PAYROLL");
choice=c.nextInt();
switch(choice)
{
case 1:
{
programmer p=new programmer();
p.getdata();
p.getprogrammer();
p.display();
p.calculateprog();
break;
}
case 2:
{
asstprofessor asst=new asstprofessor();
asst.getdata();
asst.getasst();
asst.display();
asst.calculateasst();
break;
}
case 3:
{
associateprofessor asso=new associateprofessor();
asso.getdata();
asso.getassociate();
asso.display();
asso.calculateassociate();
break;
}
case 4:
{
professor prof=new professor();
prof.getdata();
prof.getprofessor();
prof.display();
prof.calculateprofessor();
break;
}
}
System.out.println("Do u want to continue 0 to quit and 1 to continue ");
cont=c.nextInt();
}while(cont==1);
}
}
RESULT
Thus the java application to generate pay slip for different category of employees was
implemented using inheritance and the program was executed successfully.
Ex No : 4 CALCULATE AREA USING ABSTRACT CLASS
Date :
AIM
To write a java program to calculate the area of rectangle, circle and triangle using the
concept of abstract class.
ALGORITHM
1. Create an abstract class named shape that contains two integers and an empty method named
printarea().
2. Provide three classes named rectangle, triangle and circle such that each one of the classes
extends the class Shape.
3.Each of the inherited class from shape class should provide the implementation for the method
printarea().
4.Get the input and calculate the area of rectangle,circle and triangle .
5. In the shapeclass , create the objects for the three inherited classes and invoke the methods and
display the area values of the different shapes.
PROGRAM
import java.util.*;
abstract class shape
{
int a,b;
abstract public void printarea();
}
class rectangle extends shape
{
public int area_rect;
public void printarea()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the length and breadth of rectangle");
a=s.nextInt();
b=s.nextInt();
area_rect=a*b;
{
double area_tri;
public void printarea()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the base and height of triangle");
a=s.nextInt();
b=s.nextInt();
System.out.println("Base of triangle "+a +"height of triangle "+b);
area_tri=(0.5*a*b);
{
Scanner s=new Scanner(System.in);
System.out.println("enter the radius of circle");
a=s.nextInt();
area_circle=(3.14*a*a);
System.out.println("Radius of circle"+a);
System.out.println("The area of circle is:"+area_circle);
}
}
public class shapeclass
{
RESULT
Thus a java program to calculate the area of rectangle, circle and triangle was implemented
and executed successfully.
Ex No : 5 CALCULATE AREA USING INTERFACE
Date :
AIM
To write a java program to calculate the area of rectangle, circle and triangle using the
concept of interface.
ALGORITHM
1. Create an interface named shape that contains empty method named printarea().
2. Provide three classes named rectangle, triangle and circle which implements the interface and
provides implementation for the method printarea.
3.Get the input and calculate the area of rectangle,circle and triangle .
5. In the shapeclass , create the objects and invoke the methods and display the area values of the
different shapes
PROGRAM
import java.util.*;
interface shape
{
public void printarea();
}
class rectangle implements shape
{
int a,b;
}
class triangle implements shape
{
int a,b;
double area_tri;
public void printarea()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the base and height of triangle");
a=s.nextInt();
b=s.nextInt();
System.out.println("Base of triangle "+a +"height of triangle "+b);
area_tri=(0.5*a*b);
double area_circle;
public void printarea()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the radius of circle");
a=s.nextInt();
area_circle=(3.14*a*a);
System.out.println("Radius of circle"+a);
System.out.println("The area of circle is:"+area_circle);
}
}
public class shapeclass
{
public static void main(String[] args)
{
RESULT:
Thus a java program to calculate the area of rectangle, circle and triangle was implemented
and executed successfully.
Ex No :6 CREATION OF USER DEFINED EXCEPTION
Date :
AIM
To write a java program to implement user defined exception handling
ALGORITHM
1. Create a class which extends Exception class.
5. Using the exception handling mechanism , the thrown exception is handled by the catch
construct.
6. After the exception is handled , the string “invalid amount “ will be displayed.
7. If the amount is greater than 0 , the message “Amount Deposited “ will be displayed
PROGRAM
import java.util.Scanner;
class NegativeAmtException extends Exception
{
String msg;
NegativeAmtException(String msg)
{
this.msg=msg;
}
{
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)
{
}
catch(NegativeAmtException e)
{
System.out.println(e);
}
}
}
RESULT
Thus a java program to implement user defined exception handling has been
implemented and executed successfully.
Ex No :7 MULTITHREADED APPLICATION
Date :
AIM
To write a java program that implements a multi-threaded application .
ALGORITHM
1. Create a class even which implements first thread that computes the square of the number
2. run() method implements the code to be executed when thread gets executed.
3. Create a class odd which implements second thread that computes the cube of the number.
4.Create a third thread that generates random number.If the random number is even , it displays
the square of the number.If the random number generated is odd , it displays the cube of the
given number .
5.The Multithreading is performed and the task switched between multiple threads.
6.The sleep () method makes the thread to suspend for the specified time.
PROGRAM
import java.util.*;
class even implements Runnable
{
public int x;
public even(int x)
{
this.x = x;
}
public void run()
{
System.out.println("New Thread "+ x +" is EVEN and Square of " + x + " is: " + x * x);
}
}
class odd implements Runnable
{
public int x;
public odd(int x)
{
this.x = x;
}
public void run()
{
System.out.println("New Thread "+ x +" is ODD and Cube of " + x + " is: " + x * x * x);
}
}
class A extends Thread
{
{
Thread t1 = new Thread(new even(num));
t1.start();
}
else
{
Thread t2 = new Thread(new odd(num));
t2.start();
}
Thread.sleep(1000);
System.out.println(" ");
}
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
public class multithreadprog
{
public static void main(String[] args)
{
A a = new A();
a.start();
}
}
RESULT
Thus a java program for multi-threaded application has been implemented and executed
successfully.
Ex No :8 PROGRAM FOR DISPLAYING FILE INFORMATION
Date :
AIM
To write a java program that reads a file name from the user, displays information about
whether the file exists, whether the file is readable, or writable, the type of file and the length of
the file in bytes.
ALGORITHM
1. Create a class filedemo. Get the file name from the user .
2. Use the file functions and display the information about the file.
3.getName() displays the name of the file.
4. getPath() diplays the path name of the file.
5. getParent () -This method returns the pathname string of this abstract pathname’s parent, or
null if this pathname does not name a parent directory.
6. exists() – Checks whether the file exists or not.
7. canRead()-This method is basically a check if the file can be read.
8. canWrite()-verifies whether the application can write to the file.
9. isDirectory() – displays whether it is a directory or not.
10. isFile() – displays whether it is a file or not.
11. lastmodified() – displays the last modified information.
12.length()- displays the size of the file.
13. delete() – deletes the file
14.Invoke the predefined functions abd display the iformation about the file.
PROGRAM
import java.io.*;
import java.util.*;
class filedemo
{
public static void main(String args[])
{
String filename;
Scanner s=new Scanner(System.in);
System.out.println("Enter the file name ");
filename=s.nextLine();
System.out.println("NOT A DIRECTORY");
if(f1.isFile())
System.out.println("IT IS A FILE ");
else
System.out.println("NOT A FILE");
System.out.println("File last modified "+ f1.lastModified());
RESULT
Thus a java program to display file information has been implemented and
executed successfully.
Ex No: 9 PROGRAM TO FIND THE MAXIMUM VALUE FROM THE GIVEN
Date: TYPE OF ELEMENTS USING GENERICS
AIM
To write a java program to find the maximum value from the given type of elements using
a generic function.
ALGORITHM
PROGRAM
class MyClass<T extends Comparable<T>>
{
T[] vals;
MyClass(T[] o)
{
vals = o;
}
public T min()
{
T v = vals[0];
for(int i=1; i < vals.length; i++)
if(vals[i].compareTo(v) < 0)
v = vals[i];
return v;
}
public T max()
{
T v = vals[0];
for(int i=1; i < vals.length;i++)
if(vals[i].compareTo(v) > 0)
v = vals[i];
return v;
} }
class gendemo
{
public static void main(String args[])
{
int i;
Integer inums[]={10,2,5,4,6,1};
Character chs[]={'v','p','s','a','n','h'};
Double d[]={20.2,45.4,71.6,88.3,54.6,10.4};
} }
RESULT
Thus a java program to find the maximum value from the given type of elements has been
implemented using generics and executed successfully.
Ex No: 10a JAVAFX CONTROLS AND LAYOUTS
Date:
AIM
To write a java program for JavaFX controls and layouts.
ALGORITHM
1. import the javafx packages.
2. Create the class Registration that extends the application class.
3. Create the controls for Text, Radiobutton, Checkbox, Togglebutton
4. The different layouts can be used to lay the controls.
5. When the user presses the control , the event is generated and handled .
6. Launch method is used to launch the javafx application.
PROGRAM
package registration;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.ListView;
import javafx.scene.control.RadioButton;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.ToggleButton;
import javafx.stage.Stage;
public class Registration extends Application
{
public void start(Stage stage) {
Text nameLabel = new Text("Name");
TextField nameText = new TextField();
Text dobLabel = new Text("Date of birth");
DatePicker datePicker = new DatePicker();
Text genderLabel = new Text("gender");
ToggleGroup groupGender = new ToggleGroup();
RadioButton maleRadio = new RadioButton("male");
maleRadio.setToggleGroup(groupGender);
RadioButton femaleRadio = new RadioButton("female");
femaleRadio.setToggleGroup(groupGender);
Text reservationLabel = new Text("Reservation");
ToggleButton Reservation = new ToggleButton();
ToggleButton yes = new ToggleButton("Yes");
ToggleButton no = new ToggleButton("No");
ToggleGroup groupReservation = new ToggleGroup();
yes.setToggleGroup(groupReservation);
no.setToggleGroup(groupReservation);
Text technologiesLabel = new Text("Technologies Known");
CheckBox javaCheckBox = new CheckBox("Java");
javaCheckBox.setIndeterminate(false);
CheckBox dotnetCheckBox = new CheckBox("DotNet");
javaCheckBox.setIndeterminate(false);
Text educationLabel = new Text("Educational qualification");
ObservableList<String> names = FXCollections.observableArrayList( "Engineering", "MCA",
"MBA", "Graduation", "MTECH", "Mphil", "Phd");
ListView<String> educationListView = new ListView<String>(names);
Text locationLabel = new Text("location");
ChoiceBox locationchoiceBox = new ChoiceBox();
locationchoiceBox.getItems().addAll("Hyderabad", "Chennai", "Delhi", "Mumbai",
"Vishakhapatnam");
Button buttonRegister = new Button("Register");
buttonRegister.setOnAction(new EventHandler<ActionEvent>()
{ public void handle(ActionEvent t) {
System.out.println("Register successfully");
} };
GridPane gridPane = new GridPane();
gridPane.setMinSize(500, 500);
gridPane.setPadding(new Insets(10, 10, 10, 10));
gridPane.setVgap(5);
gridPane.setHgap(5);
gridPane.setAlignment(Pos.CENTER);
gridPane.add(nameLabel, 0, 0);
gridPane.add(nameText, 1, 0);
gridPane.add(dobLabel, 0, 1);
gridPane.add(datePicker, 1, 1);
gridPane.add(genderLabel, 0, 2);
gridPane.add(maleRadio, 1, 2);
gridPane.add(femaleRadio, 2, 2);
gridPane.add(reservationLabel, 0, 3);
gridPane.add(yes, 1, 3);
gridPane.add(no, 2, 3);
gridPane.add(technologiesLabel, 0, 4);
gridPane.add(javaCheckBox, 1, 4);
gridPane.add(dotnetCheckBox, 2, 4);
gridPane.add(educationLabel, 0, 5);
gridPane.add(educationListView, 1, 5);
gridPane.add(locationLabel, 0, 6);
gridPane.add(locationchoiceBox, 1, 6);
gridPane.add(buttonRegister, 2, 8);
buttonRegister.setStyle("-fx-background-color: darkslateblue; -fx-textfill: white;");
nameLabel.setStyle("-fx-font: normal bold 15px 'serif' ");
dobLabel.setStyle("-fx-font: normal bold 15px 'serif' ");
genderLabel.setStyle("-fx-font: normal bold 15px 'serif' ");
reservationLabel.setStyle("-fx-font: normal bold 15px 'serif' ");
technologiesLabel.setStyle("-fx-font: normal bold 15px 'serif' ");
educationLabel.setStyle("-fx-font: normal bold 15px 'serif' ");
locationLabel.setStyle("-fx-font: normal bold 15px 'serif' ");
gridPane.setStyle("-fx-background-color: BEIGE;");
Scene scene = new Scene(gridPane);
stage.setTitle("Registration Form");
stage.setScene(scene);
stage.show();
}
public static void main(String args[])
{
launch(args);
}
}
RESULT
Thus the program for Javafx controls and layout was verified and executed
successfully
Ex No: 10b JAVAFX MENUS
Date:
AIM
ALGORITHM
1. import the javafx packages.
2. Create the class MenuBarExample that extends the application class.
3. Create the menu for File and Edit
4.Create the submenus for File and Edit
5. The different layouts can be used to lay the menus
6.. When the user click the File or Edit menu the event is generated and handled
7. Launch method is used to launch the javafx application.
PROGRAM
package MenuBarExample;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.*;
import javafx.stage.Stage;
import javafx.scene.control.Alert.AlertType;
import java.time.LocalDate;
public class MenuBarExample extends Application
{
public void start(Stage s)
{
s.setTitle("creating MenuBar");
Menu m = new Menu("File");
Menu e = new Menu("Edit");
MenuItem m1 = new MenuItem("New");
MenuItem m2 = new MenuItem("Open");
MenuItem m3 = new MenuItem("Save");
MenuItem m4 = new MenuItem("Cut");
MenuItem m5 = new MenuItem("Copy");
MenuItem m6 = new MenuItem("Paste");
m.getItems().add(m1);
m.getItems().add(m2);
m.getItems().add(m3);
e.getItems().add(m4);
e.getItems().add(m5);
e.getItems().add(m6);
Label l = new Label("\t\t\t\t"+ "no menu item selected");
EventHandler<ActionEvent> event = new EventHandler<ActionEvent>()
{
public void handle(ActionEvent e)
{
l.setText("\t\t\t\t" + ((MenuItem)e.getSource()).getText() + " selected");
}};
m1.setOnAction(event);
m2.setOnAction(event);
m3.setOnAction(event);
m4.setOnAction(event);
m5.setOnAction(event);
m6.setOnAction(event);
MenuBar mb = new MenuBar();
mb.getMenus().add(m);
mb.getMenus().add(e);
VBox vb = new VBox(mb, l);
Scene sc = new Scene(vb, 500, 300);
s.setScene(sc);
s.show();
}
public static void main(String args[])
{
launch(args);
}
}
RESULT
Thus the program for Javafx Menus was verified and executed successfully
Ex No: 11 PROGRAM TO IMPLEMENT CURRENCY CONVERTER, DISTANCE
CONVERTER AND TIME CONVERTER USING PACKAGES
Date :
AIM
To develop a java application to implement currency converter ,distance converter and time
converter using the concept of packages .
ALGORITHM
1. Create a Package currencyconversion and place the class currency under the package
2. Create the methods to perform currency conversion from dollar to rupee ,rupee to dollar,euro to
rupee , rupee to euro , yen to rupee and rupee to yen.
3. Create the package distanceconverion and create the class distance within the package
4.Create the methods to convert from meter to km, km to meter, miles to km,km to miles
5.Create the package timeconversion and create the class timer .Create the methods to convert
from hours to minutes ,hours to seconds , minutes to hours and seconds to hours
6. Create a class and import the packages currencyconversion,distanceconversion and time
conversion.Create the objects for the class currency,distance and timer.
7. Get the choice from the user and invoke the methods to perform the corresponding conversion
and display the value.
PROGRAM
currencyconversion.java
package currencyconversion;
import java.util.*;
public class currency
{
double inr,usd;
double euro,yen;
Scanner in=new Scanner(System.in);
public void dollartorupee()
{
System.out.println("Enter dollars to convert into Rupees:");
usd=in.nextInt();
inr=usd*67;
System.out.println("Dollar ="+usd+"equal to INR="+inr);
}
public void rupeetodollar()
{
System.out.println("Enter Rupee to convert into Dollars:");
inr=in.nextInt();
usd=inr/67;
System.out.println("Rupee ="+inr+"equal to Dollars="+usd);
}
public void eurotorupee()
{
System.out.println("Enter euro to convert into Rupees:");
euro=in.nextInt();
inr=euro*79.50;
System.out.println("Euro ="+euro +"equal to INR="+inr);
}
public void rupeetoeuro()
{
System.out.println("Enter Rupees to convert into Euro:");
inr=in.nextInt();
euro=(inr/79.50);
System.out.println("Rupee ="+inr +"equal to Euro="+euro);
}
public void yentorupee()
{
System.out.println("Enter yen to convert into Rupees:");
yen=in.nextInt();
inr=yen*0.61;
System.out.println("YEN="+yen +"equal to INR="+inr);
}
public void rupeetoyen()
{
System.out.println("Enter Rupees to convert into Yen:");
inr=in.nextInt();
yen=(inr/0.61);
System.out.println("INR="+inr +"equal to YEN"+yen);
}
}
distance.java
package distanceconversion;
import java.util.*;
double km,m,miles;
Scanner sc = new Scanner(System.in);
public void kmtom()
{
System.out.print("Enter in km ");
km=sc.nextDouble();
m=(km*1000);
System.out.println(km+"km" +"equal to"+m+"metres");
}
public void mtokm()
{
System.out.print("Enter in meter ");
m=sc.nextDouble();
km=(m/1000);
System.out.println(m+"m" +"equal to"+km+"kilometres");
}
System.out.print("Enter in km");
km=sc.nextDouble();
miles=(km*0.621371);
System.out.println(km+"km" +"equal to"+miles+"miles");
}
}
timer.java
package timeconversion;
import java.util.*;
public class timer
{
int hours,seconds,minutes;
int input;
Scanner sc = new Scanner(System.in);
public void secondstohours()
{
{
System.out.println("enter the no of hours");
hours=sc.nextInt();
minutes=(hours*60);
System.out.println("Minutes: " + minutes);
}
public void hourstoseconds()
{
System.out.println("enter the no of hours");
hours=sc.nextInt();
seconds=(hours*3600);
System.out.println("Minutes: " + seconds);
}
}
converter.java
import java.util.*;
import java.io.*;
import currencyconversion.*;
import distanceconversion.*;
import timeconversion.*;
class converter
{
public static void main(String args[])
{
do
{
case 1:
{
c.dollartorupee();
break;
}
case 2:
{
c.rupeetodollar();
break;
}
case 3:
{
c.eurotorupee();
break;
}
case 4:
{
c.rupeetoeuro();
break;
}
case 5:
{
c.yentorupee();
break;
}
case 6 :
{
c.rupeetoyen();
break;
}
case 7 :
{
d.mtokm();
break;
}
case 8 :
{
d.kmtom();
break;
}
case 9 :
{
d.milestokm();
break;
}
case 10 :
{
d.kmtomiles();
break;
}
case 11 :
{
t.hourstominutes();
break;
}
case 12 :
{
t.hourstoseconds();
break;
}
case 13 :
{
t.secondstohours();
break;
}
case 14 :
{
t.minutestohours();
break;
}
}
System.out.println("Enter 0 to quit and 1 to continue ");
ch=s.nextInt();
}while(ch==1);
}
}
RESULT
Thus the java application to implement currency converter ,distance converter and time
converter was implemented and executed successfully.