Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 54

Ex. No.

:1
ELECTRICITY BILL CALCULATOR

Aim:
To develop a Java application to generate Electricity bill.
Procedure:
1. Start the program
2. Create consumer class with the following members: Consumer no., consumer name, previous month
reading, current month reading, type of EB connection (i.e domestic or commercial).
3. If the type of the EB connection is domestic, calculate the amount to be paid as follows:
First 100 units - Rs.1 per unit 101-200 units - Rs.2.50 per unit
201 -500 units - Rs. 4 per unit > 501 units - Rs.6 per unit
4. If the type of the EB connection is commercial, calculate the amount to be paid as follows:
First 100 units - Rs. 2 per unit 101-200 units - Rs. 4.50 per unit
201 -500 units - Rs. 6 per unit > 501 units - Rs. 7 per unit
4. Print the amount
5. Stop the program
Program:
import java.io.*;
class ComputeElectricityBill
{ int con_no;
String c_name;
int prev_reading;
int cur_reading;
int type_connection;
float bill_amt;
int consumed_unit;
public void getCurComDetail() throws Exception
{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter consumer number");
con_no=Integer.parseInt(br.readLine());
System.out.println("Enter consumer name");
c_name=br.readLine();
System.out.println("Enter previous month reading");
prev_reading=Integer.parseInt(br.readLine());
System.out.println("Enter current reading");

1
cur_reading=Integer.parseInt(br.readLine());
System.out.println("Enter type of connection");
System.out.println("1.Domestic connection");
System.out.println("2.Commercial connection");
Type_connection=Integer.parseInt(br.readLine());
} public void calculateBillAmt()
{ consumed_unit=cur_reading-prev_reading;
if(type_connection==1)
{ if(consumed_unit>500)
bill_amt=consumed_unit*6;
else if(consumed_unit>200)
bill_amt=consumed_unit*4;
else if(consumed_unit>100)
bill_amt=consumed_unit*2.5f;
else
bill_amt=consumed_unit*1;
} else
{ if(consumed_unit>500)
bill_amt=consumed_unit*7;
else if(consumed_unit>200)
bill_amt=consumed_unit*6;
else if(consumed_unit>100)
bill_amt=consumed_unit*4.5f;
else
bill_amt=consumed_unit*2;
} } public void display_amt()
{ System.out.println("Consumer No:"+con_no);
System.out.println("Consumer Name:"+c_name);
System.out.println("Consumed Units:"+consumed_unit);
System.out.println("Bill Amount:"+bill_amt);
} }//end of class
public class EBbillDemo
{ public static void main(String a[])throws Exception
{ ComputeElectricityBill b=new ComputeElectricityBill();
b.getCurComDetail();
b.calculateBillAmt();

2
b.display_amt();
} }
Output:
1. Domestic Connection

2. Commericial Connection

Result:
Thus the Electricity Bill Java application was successfully executed.
Outcome:
Thus the course outcome (CO1) has been attained by generating an Electricity Bill application using
Java.
Applications:
(1) Payroll Processing
(2) PF Calculation

3
Ex. No.:2
UNIT CONVERTERS APPLICATION USING PACKAGES FOR CURRENCY

Aim:
To develop a Java application to implement currency converter using packages.
Procedure:
1. Start the program.
2. Create packages for currency converter for (Dollar to INR, EURO to INR, Yen to INR and vice
versa).
3. Create corresponding code for conversion.
4. Print the converted value.
5. Stop the program.
Program:
Package Program
package MyPack; // creating a package “MyPack”
import java.util.Scanner;
public class currency
{ public currency()
{ char us_dollar_sym = 36;
char rupee_sym = 163;
char yen_sym = 165;
char euro_sym = 8364;
String us_dollar = "Dollars";
String rupee = "Rupees";
String yen = "Yen";
String euro = "Euros";
double rate = 0;
System.out.println("Welcome to the Currency Converter Program \n");
System.out.println("Use the following codes to input your currency choices
: \n 1 - US dollars \n 2 - Euros \n 3 - Indian Rupees \n 4 - Japanese Yen \n");
System.out.println("Please choose the input currency:");
Scanner in = new Scanner(System.in);
int choice = in.nextInt();
String inType = null;
switch(choice)
{ case 1: inType = "US Dollars >> " + us_dollar_sym; break;

4
case 2: inType = "Euros >> " + euro_sym; break;
case 3: inType = "Indian Rupees >> " + rupee_sym; break;
case 4: inType = "Japanese Yen >> " + yen_sym; break;
default:
System.out.println("Please restart the program & enter a number from the list.");
return;
} System.out.println("Please choose the output currency");
int output = in.nextInt();
System.out.printf("Now enter the input in " + inType);
double input = in.nextDouble();
if (choice == output)
System.out.println("Same currency no need to convert");
if (choice == 1 && output == 2)
{ double dollar_euro_rate = 83;
rate = input * dollar_euro_rate;
System.out.printf( "%s" + input + " at a conversion rate of "
+ dollar_euro_rate + " Dollars to %s = %.2f\n", (char)us_dollar_sym, euro, rate);
} else if (choice == 1 && output == 3)
{ double dollar_rupee_rate = 66.82;
rate = input * dollar_rupee_rate;
System.out.printf( "%s" + input + " at a conversion rate of "
+ dollar_rupee_rate + " Dollars to %s = %.2f\n", (char)us_dollar_sym, rupee, rate);
} else if (choice == 1 && output == 4)
{ double dollar_yen_rate = 109.12;
rate = input * dollar_yen_rate;
System.out.printf( "%s" + input + " at a conversion rate of "
+ dollar_yen_rate + " Dollars to %s = %.2f\n", (char)us_dollar_sym, yen, rate);
} if (choice == 2 && output == 1)
{ double euro_dollar_rate = 1.20;
rate = input * euro_dollar_rate;
System.out.printf( "%s" + input + " at a conversion rate of "
+ euro_dollar_rate + " Euros to %s = %.2f\n", (char)euro_sym, us_dollar, rate);
} else if (choice == 2 && output == 3)
{ double euro_rupee_rate = 80.03;
rate = input * euro_rupee_rate;
System.out.printf( "%s" + input + " at a conversion rate of "

5
+ euro_rupee_rate + " Euros to %s = %.2f\n", (char)euro_sym, rupee, rate);
} else if (choice == 2 && output == 4)
{ double euro_yen_rate = 130.69;
rate = input * euro_yen_rate;
System.out.printf( "%s" + input + " at a conversion rate of "
+ euro_yen_rate + " Euros to %s = %.2f\n", (char)euro_sym, yen, rate);
} if (choice == 3 && output == 1)
{ double rupee_dollar_rate = 0.015;
System.out.printf( "%s" + input + " at a conversion rate of "
+ rupee_dollar_rate + " Pounds to %s = %.2f\n", (char)rupee_sym, us_dollar, rate);
} else if (choice == 3 && output == 2)
{ double rupee_euro_rate = 0.012;
System.out.printf( "%s" + input + " at a conversion rate of "
+ rupee_euro_rate + " Pounds to %s = %.2f\n", (char)rupee_sym, euro, rate);
} else if (choice == 3 && output == 4)
{ double rupee_yen_rate = 1.641;
System.out.printf( "%s" + input + " at a conversion rate of "
+ rupee_yen_rate + " Pounds to %s = %.2f\n", (char)rupee_sym, yen, rate);
} if (choice == 4 && output == 1)
{ double yen_dollar_rate = 0.0092;
System.out.printf( "%s" + input + " at a conversion rate of "
+ yen_dollar_rate + " Yen to %s = %.2f\n", (char)yen_sym, us_dollar, rate);
} else if (choice == 4 && output == 2)
{ double yen_euro_rate = 0.0077;
System.out.printf( "%s" + input + " at a conversion rate of "
+ yen_euro_rate + " Yen to %s = %.2f\n", (char)yen_sym, euro, rate);
} else if (choice == 4 && output == 3)
{ double yen_rupee_rate = 0.61;
System.out.printf( "%s" + input + " at a conversion rate of "
+ yen_rupee_rate + " Yen to %s = %.2f\n", (char)yen_sym, rupee, rate);
} System.out.println("Thank you for using the currency converter");
} }
Main Program:
import MyPack.*;
public class Ex2
{ public static void main(String args[])

6
{ currency c=new currency();
} }
Output:
1. Compile Package Program.

2. Compile and run main program.


Dollar to Indian Rupee

Result:
Thus the Java application has been created for currency conversion and it was successfully executed.
Outcome:
Thus the course outcome (CO2) has been attained by applying the concept of packages using Java.

Applications:
1) Kilogram to gram conversion
2) Celsius to Fahrenheit conversion

7
Ex. No.: 3
UNIT CONVERTERS APPLICATION USING PACKAGES FOR DISTANCE

Aim:
To develop a Java application to implement Distance converter using packages.
Procedure:
1. Start the program.
2. Create three packages for currency distance converter (meter to KM, miles to KM and vice versa).
3. Create corresponding code for conversion.
4. Print the converted value.
5. Stop the program.
Program:
Package Program:
package MyPack;
import java.util.Scanner;
public class DConverter
{ public DConverter()
{ // Variable declarations
int num;//num entered by user
double meters;
// Scanner object for keyboard input
Scanner keyboard = new Scanner(System.in);
// Ask user for meters
System.out.print("Enter a distance in meters, e.g 100: ");
meters = keyboard.nextDouble();
// Check for input greater than zero
while(meters <=0)
{ String error = "Please enter a num greater than zero";
System.out.println(error);
meters = keyboard.nextDouble();
} // Menu options
System.out.print("\nEnter 1-4 from the menu options: ");
System.out.println("\n1. Convert to kilometers\n2. Convert to inches\n" +
"3. Convert to feet\n4. End");
num = keyboard.nextInt();

8
// num entered by the user
while(num <=0 || num>=5)
{ String invalid = "Invalid option entered. Please use 1 through 4";
System.out.println(invalid);
meters = keyboard.nextDouble();
} switch (num)
{ case 1: dpKilometers(meters); break;
case 2: dpInches(meters); break;
case 3: dpFeet(meters); break;
case 4: System.exit(0);
} }
public static void dpKilometers(double meters)
{ double km;
km = meters * .001;
System.out.println(+ meters + " meters equals to " +km+ " kilometers");
} public static void dpInches(double meters)
{ double in;
in = meters * 39.37;
System.out.println(meters + " meters equals to " + in + " inches.");
} public static void dpFeet(double meters)
{ double ft;
ft = meters * 3.281;
System.out.println(meters + " meters equals to " + ft + " feet.");
} }
Main Program:
import MyPack.*;
public class Ex3
{ public static void main(String args[])
{ DConverter dc=new DConverter();
} }

9
Output:
1. Compile Package Program.

2. Compile and run main program.

Result:
Thus the Java application has been created for distance conversion and it was successfully executed.
Outcome:
Thus the course outcome (CO2) has been attained by applying the concept of packages using Java.
Applications:
a) Kilogram to gram conversion
b) Celsius to Fahrenheit conversion

10
Ex. No.: 4
UNIT CONVERTERS APPLICATION USING PACKAGES FOR TIME

Aim:
To develop a Java application to implement time converter using packages.
Procedure:
1. Start the program.
2. Create three packages for time converter ( hours to minutes, seconds and vice versa).
3. Create corresponding code for conversion.
4. Print the converted value.
5. Stop the program
Program:
Package Program:
package MyPack;
import java.util.Scanner;
public class TConverter
{ public TConverter()
{
String hr = "Hours";
String min = "Minutes";
String sec = "Seconds";
double time = 0, rate=0;
System.out.println("Welcome to the Time Converter Program \n");
System.out.println("Use the following codes to input your Time choices:
\n 1 - Hours \n 2 - Minutes \n 3 - Seconds \n");
System.out.println("Please choose the input time format:");
Scanner in = new Scanner(System.in);
int choice = in.nextInt();
String inType = null;
switch(choice)
{
case 1: inType = "Hours >> " ; break;
case 2: inType = "Minutes >> "; break;
case 3: inType = "Seconds >> "; break;
default:

11
System.out.println("Please restart the program & enter a number from the list.");
return;
}
System.out.println("Please choose the output time format");
int output = in.nextInt();
System.out.printf("Now enter the input in " + inType);
double input = in.nextDouble();
if (choice == output)
System.out.println("Same time format no need to convert");
if (choice == 1 && output == 2)
{ double hrs_min_rate = 60;
rate = input * hrs_min_rate;
System.out.printf(input+ " Hours converted to "+rate+" Minutes");
}
else if (choice == 1 && output == 3){
double hrs_sec_rate = 3600;
rate = input * hrs_sec_rate;
System.out.printf(input+ " Hours converted to "+rate+" seconds");
}
if (choice == 2 && output == 1)
{ double min_hrs_rate = 0.01667;
rate = input * min_hrs_rate;
System.out.printf(input+ " Minutes converted to "+rate+" Hours");
}
else if (choice == 2 && output == 3)
{ double min_sec_rate = 60;
rate = input * min_sec_rate;
System.out.printf(input+ " Minutes converted to "+rate+" Seconds");
}
if (choice == 3 && output == 1)
{ double sec_hrs_rate = 0.0002778;
rate = input * sec_hrs_rate;
System.out.printf(input+ " Seconds converted to "+rate+" Hours");
}
else if (choice == 3 && output == 2)

12
{ double sec_min_rate = 0.01667;
rate = input * sec_min_rate;
System.out.printf(input+ " Seconds converted to "+rate+" Minutes");
}
System.out.println("Thank you for using the Time converter");
} }
Main Program:
import MyPack.*;
public class Ex4
{ public static void main(String args[])
{ TConverter tc=new TConverter();
} }
Output:
1. Compile Package Program.

2. Compile and run main program.

Result:
Thus the Java application has been created for time conversion and it was successfully executed.
Outcome:
Thus the course outcome (CO2) has been attained by applying the concept of packages using Java.
Applications:
a) Kilogram to gram conversion
b) Celsius to Fahrenheit conversion

13
Ex. No.:5
EMPLOYEE PAYROLL SYSTEM

Aim:
To develop a Java application with employee class and generate pay slips for the employees with
their gross and net salary.
Procedure:
1. Start the program.
2. Create Employee class with Emp_name, Emp_id, Address, Mail_id, Mobile no as members.
3. Inherit the classes, Programmer, Assistant Professor, Associate Professor and Professor from
employee class.
4. 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.
5. Generate pay slips for the employees with their gross and net salary.
6. Stop the program
Program:
import java.io.*;
class Employee
{ int Emp_id;
String Emp_name;
String addressline1;
String addressline2;
String addressline3;
String mail_id;
String mobile_no;
float bp,da,hra,pf,scf;
float netpay;
float grosspay;
public void getEmpDetails()throws Exception
{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Employee id");
Emp_id=Integer.parseInt(br.readLine());
System.out.println("Enter Employee Name");
Emp_name=br.readLine();
System.out.println("Enter Employee Address Line1");
addressline1=br.readLine();
14
System.out.println("Enter Employee Address Line2");
addressline2=br.readLine();
System.out.println("Enter Employee Address Line3");
addressline3=br.readLine();
System.out.println("Enter Employee Mail ID");
mail_id=br.readLine();
System.out.println("Enter Employee Phone Number");
mobile_no=br.readLine();
} public void displyEmpDetails()
{ System.out.println("Pay Slip");
System.out.println("Employee Name:"+Emp_name);
System.out.println("Employee Address");
System.out.println(addressline1);
System.out.println(addressline2);
System.out.println(addressline3);
System.out.println("Employee Mail ID"+mail_id);
System.out.println("Employee Phone Number:"+mobile_no);
System.out.println("Basic Pay:"+bp);
System.out.println("DA:"+da);
System.out.println("HRA:"+hra);
System.out.println("PF:"+pf);
System.out.println("Staff Club Fund:"+scf);
System.out.println("Net Pay:"+netpay);
System.out.println("Gross Pay:"+grosspay);
} }
class Programmer extends Employee
{ public void salaryCalculation()
{ bp=15000;
da=bp*0.97f;
hra=bp*0.1f;
pf=bp*0.12f;
scf=bp*0.001f;
netpay=bp+da+hra;
grosspay=netpay-pf-scf;
System.out.println("******************************\nEmployee
Position:Programmer");
15
} } class Professor extends Employee
{ public void salaryCalculation()
{ bp=60000;
da=bp*0.97f;
hra=bp*0.1f;
pf=bp*0.12f;
scf=bp*0.001f;
netpay=bp+da+hra;
grosspay=netpay-pf-scf;
System.out.println("**********************\nEmployee Position:Professor");
} } class AssistantProfessor extends Employee
{ public void salaryCalculation()
{ bp=30000;
da=bp*0.97f;
hra=bp*0.1f;
pf=bp*0.12f;
scf=bp*0.001f;
netpay=bp+da+hra;
grosspay=netpay-pf-scf;
System.out.println("***********************\nEmployee Position:Assistant Professor");
} } class AssociateProfessor extends Employee
{ public void salaryCalculation()
{ bp=45000;
da=bp*0.97f;
hra=bp*0.1f;
pf=bp*0.12f;
scf=bp*0.001f;
netpay=bp+da+hra;
grosspay=netpay-pf-scf;
System.out.println("******************\nEmployee Position:Associate Professor");
} } class EmployeePayCalculator
{ public static void main(String ar[])throws Exception
{ String opt;
int ch;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Programmer p1=new Programmer();
16
Professor p2=new Professor();
AssistantProfessor p3=new AssistantProfessor();
AssociateProfessor p4=new AssociateProfessor();
do
{ System.out.println("Enter the Employee Position:");
System.out.println("1- Programmer");
System.out.println("2- Professor");
System.out.println("3- Assistant Professor");
System.out.println("4- Associate Professor");
ch=Integer.parseInt(br.readLine());
switch(ch)
{ case 1:
p1.getEmpDetails();
p1.salaryCalculation();
p1.displyEmpDetails(); break;
case 2:
p2.getEmpDetails();
p2.salaryCalculation();
p2.displyEmpDetails(); break;
case 3:
p3.getEmpDetails();
p3.salaryCalculation();
p3.displyEmpDetails(); break;
case 4:
p4.getEmpDetails();
p4.salaryCalculation();
p4.displyEmpDetails(); break;
default: System.out.println(" Invalid Position");
}
System.out.println("**********************************");
System.out.println("Do you want to Continue(y/n)");
opt=br.readLine();
}
while(opt.equals("y"));
} }

17
Output:

Result:
Thus the Java application has been created with with employee class and pay slips are generated for the
employees with their gross and net salary.

Outcome:
Thus the course outcome (CO1) has been attained by applying the concept of inheritance to generate
Payroll Processing application using Java.

Applications:
a) EB Bill Generation
b) Income Tax Calculation

18
Ex. No.: 6
JAVA APPLICATION FOR ADT STACK USING INTERFACES

Aim
To design a Java interface for ADT Stack using array.
Procedure:
1. Start the program
2. Define the interface.
3. Read the elements using array.
4. Initialize stackTop pointer as zero,
5. Define and use the method Push() to insert the elements into the stack with ‘STACK
OVERFLOW’ condition.
6. Define and use the method pop() to remove an element from an array with ‘STACK
UNDERFLOW’ condition
7. Display the output.
Program:
import java.io.*;
interface Interface_StackADT
{ public void push(int pushedElement)throws ArrayIndexOutOfBoundsException;
public void pop()throws ArrayIndexOutOfBoundsException;
public void printElements();
}
class Ipmlementation_StackADT implements Interface_StackADT
{ private static final int capacity = 3;
int arr[] = new int[capacity];
int top = -1;
public void push(int pushedElement)throws ArrayIndexOutOfBoundsException
{ if (top<capacity - 1)
{ top++;
arr[top] = pushedElement;
System.out.println("Element " + pushedElement + " is pushed to Stack ");
} else
{ System.out.println("Stack Overflow !"); }
}
public void pop()throws ArrayIndexOutOfBoundsException
{
19
if (top >= 0)
{ top--;
System.out.println("Pop operation done ! the poped element is:"+arr[top+1]);
} else
{ System.out.println("Stack Underflow !"); }
} public void printElements()
{ if (top >= 0)
{ System.out.println("Elements in stack :");
for (int i = 0; i <= top; i++)
{ System.out.print(arr[i]+" "); }
System.out.println("");
} } }
class StackInterfaceTest
{ public static void main(String arg[])throws
IOException,ArrayIndexOutOfBoundsException
{ int ch,ele;
String opt;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Interface_StackADT s=new Ipmlementation_StackADT();
do
{ System.out.println("1-PUSH Element in to Stack");
System.out.println("2-POP Element from Stack");
System.out.println("3-Print Elements of Stack");
System.out.println(" Enter your Choice");
ch=Integer.parseInt(br.readLine());
switch(ch)
{ case 1: System.out.println(" Enter the Element you want to Push");
ele=Integer.parseInt(br.readLine());
s.push(ele); break;
case 2: s.pop(); break;
case 3: s.printElements(); break;
default: System.out.println(" Invalid input");
} System.out.println(" do you want to continue(y/n):");
opt=br.readLine();
} while(opt.equals("y")); } }

20
Output:

Result:
Thus the design and implementation of ADT Stack using array has successfully executed.
Outcome:
Thus the course outcome (CO2) has been attained by applying the concept of array to generate ADT
Stack using Java.
Applications:
a) ADT Queue
b) ADT circular queue

21
Ex. No.: 7

JAVA APPLICATION FOR STRING OPERATIONS USING ARRAY LIST

Aim:
To write a program to perform string operations using ArrayList.
Procedure:
1. Start the program.
2. Add the String as an object to List.
3. Get the choice from the user and do according to the choice
a. Append-add at end
b. Insert-add at particular index
c. Search
d. List all string starts with given letter.
4. Display the result.
5. Stop the program.
Program:
import java.util.*;
import java.io.*;
class StringOperationDemo
{ String str;
int n,index;
ArrayList<String> obj = new ArrayList<String>();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void createArrayList()throws Exception
{ System.out.println("Enter the no of Strings you want to create the List:");
n=Integer.parseInt(br.readLine());
for(int i=0;i<n;i++)
{ System.out.println("Enter the String you want to Insert:");
str=br.readLine();
obj.add(str);
} }
public void append_AddatEnd()throws Exception
{ System.out.println("Enter the String you want to Append at the End:");
str=br.readLine();

22
obj.add(str);
}
public void addAtTheIndex()throws Exception
{ System.out.println("Enter the index of List you want to Insert a String:");
index=Integer.parseInt(br.readLine());
System.out.println("Enter the String you want to Insert:");
str=br.readLine();
obj.add(index,str);
}
public void searchString()throws Exception
{ System.out.println("Enter the String you want to Search:");
str=br.readLine();
if(obj.contains(str))
System.out.println("The given String is present in the arraylist");
else
System.out.println("The given String is not present in the arraylist");
}
public void listAllStringStartswithGivenLetter()throws Exception
{ System.out.println("Enter the First letter of the String you want to list");
Scanner reader = new Scanner(System.in);
String c1 = br.readLine();
for(int i = 0; i < obj.size(); i++)
{ String test = obj.get(i);
if(test.charAt(0) == c1.charAt(0) )
{ System.out.println(test); }
}
}
public void display()
{ System.out.println("Currently the array list has following elements:"+obj);
} }
class ArrayListDemo
{ public static void main(String arg[])throws Exception
{ int ch;
String opt;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

23
StringOperationDemo op=new StringOperationDemo();
do
{ System.out.println("Choose any one String operation you want to do:");
System.out.println("1-Creation of an ArrayList");
System.out.println("2-Append String at the End of an ArrayList:");
System.out.println("3-Append String at the given index of an ArrayList:");
System.out.println("4-Search a String");
System.out.println("5-List Strings with the given first letter:");
System.out.println("6-Display all strings currently in the ArrayList:");
System.out.println(" Enter your Choice");
ch=Integer.parseInt(br.readLine());
switch(ch)
{ case 1: op.createArrayList();
break;
case 2: op.append_AddatEnd();
break;
case 3: op.addAtTheIndex();
break;
case 4: op.searchString();
break;
case 5: op.listAllStringStartswithGivenLetter();
break;
case 6:
op.display();
break;
default:
System.out.println(" Invalid input");
} System.out.println(" do you want to continue(y/n):");
opt=br.readLine();
} while(opt.equals("y"));
} }

24
Output:

Result:
Thus the implementation of string operations using array list has been successfully executed.

Outcome:
Thus the course outcome (CO2) has been attained by applying the concept of arraylist for string
manipulations using Java.

Applications:
a) Reverse of the String.
b) String Matching.
c) Counting the number of vowels and consonants in a line.

25
Ex. No.: 8
JAVA APPLICATION TO FIND THE AREA OF DIFFERENT SHAPES

Aim:
To write a Java Program to create an abstract class named Shape and provide three classes named
Rectangle, Triangle and Circle such that each one of the classes extends the class Shape.
Procedure:
1. Start the program
2. Define the abstract class shape.
3. Define the class Rectangle with Print Area() method that extends(makes use of) Shape.
4. Define the class Triangle with Print Area() method that extends(makes use of) Shape.
5. Define the class Circle with Print Area() method that extends(makes use of) Shape.
6. Print the area of the Rectangle, Triangle and Circle .
7. Stop the Program.
Program:
import java.io.*;
abstract class Shape
{ float a,b,area;
public void getInput(float x,float y)
{ a=x;
b=y; }
public abstract void printArea(); }
class Rectangle extends Shape
{ public void printArea()
{ area=a*b;
System.out.println("Area of the Rectangle:"+ area);
} }
class Triangle extends Shape
{ public void printArea()
{ area=0.5f*a*b;
System.out.println("Area of the Triangle:"+ area);
} }
class Circle extends Shape
{ public void printArea()
{ area=3.14f*a*a;

26
System.out.println("Area of the Circle:"+ area);
} }
class Square extends Shape
{ public void printArea()
{ area=a*a;
System.out.println("Area of the Circle:"+ area);
} }
class AbstractDemo
{ public static void main(String ar[])throws Exception
{ int ch,ele;
String opt;
//float heg,br;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Shape s1=new Triangle();
Shape s2=new Rectangle();
Shape s3=new Circle();
Shape s4=new Square();
do
{ System.out.println("1-Triangle");
System.out.println("2-Rectangle");
System.out.println("3-Circle");
System.out.println("4-Square");
System.out.println(" Enter your Choice");
ch=Integer.parseInt(br.readLine());
switch(ch)
{ case 1:
System.out.print("Enter the height of a Triangle:");
float heg=Float.parseFloat(br.readLine());
System.out.print("Enter the breadth of a Triangle:");
float brt=Float.parseFloat(br.readLine());
s1.getInput(heg,brt);
s1.printArea();
break;
case 2:
System.out.print("Enter the Length of a Rectangle:");

27
float len=Float.parseFloat(br.readLine());
System.out.print("Enter the breadth of a Rectangle:");
float brth=Float.parseFloat(br.readLine());
s2.getInput(len,brth);
s2.printArea();
break;
case 3:
System.out.print("Enter the radius of a Circle:");
float r=Float.parseFloat(br.readLine());
s3.getInput(r,0.0f);
s3.printArea();
break;
case 4:
System.out.print("Enter the side of a Square:");
float a=Float.parseFloat(br.readLine());
s4.getInput(a,0.0f);
s4.printArea();
break;
default:
System.out.println(" Invalid input");
} System.out.println(" do you want to continue(y/n):");
opt=br.readLine();
} while(opt.equals("y"));
} }

28
Output:

Result:
Thus the design and implementation of Abstract class has been successfully executed.

Outcome:
Thus the course outcome (CO2) has been attained by applying the concept of abstract class using
Java.

Applications:
a) Volume of the Cube.
b) Length of the Cube.
c) Area of Triangle.

29
Ex. No.: 9
BANK TRANSACTION SYSTEM WITH USER EXCEPTIONS

Aim:
To write a Java program to implement user defined exception handling.
Procedure:
1. Start the program
2. Define the exception for getting a number from the user.
3. If the number is positive print the number as such.
4. If the number is negative throw the exception to the user as ‘Number must be positive’.
5. Stop the Program.
Program:
import java.io.*;
class Queue
{ int front;
int rear;
int size;
int Array[];
public Queue(int s)
{ front=0;
rear=-1;
size=s;
Array=new int[size];
} public void insertElement(int ele)throws QueueException
{ if(rear==size-1)
{ throw new QueueException(); }
else
{ Array[++rear]=ele;
System.out.println("Inserted : " + ele); } }
public void deleteElement()
{ if(rear==-1)
{ throw new ArrayIndexOutOfBoundsException(); }
System.out.println("Deleted : " + ++front);
if(front>rear)
{ front=0;
30
rear=-1; } }
public void displayElements()
{ System.out.println("elements in queue");
for(int i=front;i<=rear;i++)
{ System.out.println(Array[i]+" "); }
System.out.println(); } }
class QueueException extends Exception
{ public void Error()
{ System.out.println("Queue is full"); } }
public class ExceptionDemo
{ public static void main(String args[])
{ int ch,ele;
String opt;
Queue queue=new Queue(5);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{ do
{ System.out.println("1-Insert Element in to Queue");
System.out.println("2-Delete Element from Queue");
System.out.println("3-Print Elements of Queue");
System.out.println(" Enter your Choice");
ch=Integer.parseInt(br.readLine());
switch(ch)
{ case 1:
System.out.println(" Enter the Element you want to Push");
ele=Integer.parseInt(br.readLine());
queue.insertElement(ele); break;
case 2:
queue.deleteElement(); break;
case 3:
queue.displayElements(); break;
default: System.out.println(" Invalid input");
} System.out.println(" do you want to continue(y/n):");
opt=br.readLine(); }
while(opt.equals("y")); }
31
catch(QueueException e)
{ e.Error(); }
catch(ArrayIndexOutOfBoundsException e)
{ System.out.println("Queue is empty"); }
catch(IOException e)
{ System.out.println("Queue Input Output Exception"); }
} }
Output:

Result:
Thus the user defined exception has been successfully implemented.

Outcome:
Thus the course outcome (CO2) has been attained by applying the concept of Exception handling for
a user defined exception using Java.

Applications:
a) Throwing exception for Checking the @ symbol in Email Id
b) Throwing exception for password mismatch.

32
Ex. No.: 10
JAVA APPLICATION FOR FILE HANDLING

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.
Procedure:
1. Start the program
2. Read the filename from the user.
3. Use getName() Method to display the filename.
4. Use getPath() Method to display the path of the file.
5. Use getParent() Method to display its parent’s information.
6. Use exists() Method to display whether the file exist or not
7. Use isFile() and isDirectory() Methods to display whether the file is file or directory.
8. Use canRead() and canWrite) methods to display whether the file is readable or writable.
9. Use lastModified() Method to display the modified information.
10. Use length() method to display the size of the file.
11. Use isHiddden() Method to display whether the file is hidden or not.
Program:
import java.io.*;
class FileInformation
{ String s;
File f1;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void getFileName()throws Exception
{ System.out.println("Enter the File name:");
s=br.readLine();
f1=new File(s); }
public boolean isExists()
{ if(f1.exists())
{ System.out.println("The given File " + s +" is Exists");
return true; }
else
{ System.out.println("The given File " + s +" is not Exists");
return false; }
33
} public void isReadable()
{ if(f1.canRead())
{ System.out.println("The given File " + s +" is Readable"); }
else
{ System.out.println("The given File " + s +" is not Readable"); }
} public void isWritable()
{ if(f1.canWrite())
{ System.out.println("The given File " + s +" is Writable"); }
else
{ System.out.println("The given File " + s +" is not Writable"); }
} public void fileType()
{ if (s.endsWith(".jpg") || s.endsWith(".gif") || s.endsWith(".png"))
{ System.out.println("The given file is an image file."); }
else if (s.endsWith(".exe"))
{ System.out.println("The given file is an executable file."); }
else if (s.endsWith(".txt"))
{ System.out.println("The given file is a text file."); }
else
{ System.out.println("The file type is unknown."); }
}
public void fileSize()
{ System.out.println("File Size:"+f1.length()+"bytes"); }
public void displayFileInfo()
{ if(isExists())
{ isReadable();
isWritable();
fileType();
fileSize(); } } }
class FileDemo
{ public static void main(String[] args)throws Exception
{ FileInformation fi=new FileInformation();
fi.getFileName();
fi.displayFileInfo(); } }

34
Output:

Result:
Thus the information of the file has been displayed successfully using various file methods.

Outcome:
Thus the course outcome (CO1) has been attained y file operations using Java..

Applications:
a) IRCTC chart display (RAC reservation).
b) A2B menu display

35
Ex. No.: 11
JAVA APPLICATION FOR MULTI THREADING

Aim
To write a java program that implements a multi-threaded application.
Procedure:
1. Start the program
2. Design the first thread that generates a random integer for every 1 second .
3. If the first thread value is even, design the second thread as the square of the number and
then print it.
4. If the first thread value is odd, then third thread will print the value of cube of the
number.
5. Stop the program.
Program:
import java.io.*;
import java.util.*;
class RandomIntegerThread extends Thread
{ public void run()
{ try
{ Random rand = new Random();
int r;
for (int i=0;i<10;i++)
{ r = rand.nextInt(10);
System.out.println("Random Number:"+r);
if(r%2==0)
{ SquareofNumberThread sq=new SquareofNumberThread(r);
sq.start();
} else
{ CubeofNumberThread sq=new CubeofNumberThread(r);
sq.start();
} Thread.sleep(1000);
} } catch (Exception e)
{
System.out.println ("Exception is caught");
}

36
}
}
class SquareofNumberThread extends Thread
{ int n;
SquareofNumberThread(int x)
{ n=x;
} public void run()
{ try
{ System.out.println ("Square of the number "+ n +" is:" + n*n);
} catch (Exception e)
{ System.out.println ("Exception is caught");
} } }
class CubeofNumberThread extends Thread
{ int n;
CubeofNumberThread(int x)
{ n=x;
} public void run()
{ try
{ System.out.println ("cube of the number "+ n +" is:" + n*n*n);
} catch (Exception e)
{ System.out.println ("Exception is caught");
} } }
// Main Class
public class MultithreadDemo
{ public static void main(String[] args)
{ RandomIntegerThread object = new RandomIntegerThread();
object.start();
} }

37
Output:

Result:
Thus the implementation of multithreading has been done using three threads.
Outcome:
Thus the course outcome (CO4) has been attained by applying the concept of multithreading to
generate odd numbers and its square using Java.
Applications:
(1) Multiplication Table Printing (3,5,8th table)
(2) Printing Area of the cube, square and circle

38
Ex. No.: 12
JAVA APPLICATION FOR GENERIC MAX FINDER

Aim
To write a java program to find the maximum value from the given type of elements using a generic
function.
Procedure:
1. Start the program
2. Define the array with the elements
3. Sets the first value in the array as the current maximum
4. Find the maximum value by comparing each elements of the array
5. Display the maximum value
6. Stop the program.
Program:
import java.io.*;
class MinMaxExample
{ public static void main(String args[])
{ int array[] = new int[]{10, 11, 88, 2, 12, 120};
// Calling getMax() method for getting max value
int max = getMax(array);
System.out.println("Maximum Value is: "+max);
// Calling getMin() method for getting min value
int min = getMin(array);
System.out.println("Minimum Value is: "+min);
} // Method for getting the maximum value
public static int getMax(int[] inputArray)
{ int maxValue = inputArray[0];
for(int i=1;i < inputArray.length;i++)
{ if(inputArray[i] > maxValue)
{ maxValue = inputArray[i];
} } return maxValue;
} // Method for getting the minimum value
public static int getMin(int[] inputArray)
{ int minValue = inputArray[0];
for(int i=1;i<inputArray.length;i++)
39
{ if(inputArray[i] < minValue)
{ minValue = inputArray[i];
} }
return minValue; } }
Output:

Result:
Thus the implementation of generic function is achieved for finding the maximum value from the given
type of elements.
Outcome:
Thus the course outcome (CO4) has been attained by applying the concept of generic function to
generate maximum value and minimum value. .
Applications:
(1) Finding even values
(2) Finding the sum of values

40
Ex. No.: 13
BASIC CALCULATOR APPLICATION USING JAVA AWT PACKAGES

Aim:
To create a Basic Calculator Application Using Java AWT Packages.
Algorithm:
Step 1 Start the Process
Step 2 Display Text View and Number Pad and Option Pads
Step 3 If user presses any number get the existing numbers in Text View add them up and display
Step 4 If user press Operators
Step 4.1 Get the Text View content as Operant 1 and Set the display to null.
Step 4.2 If user pressed “ADD” button set operator as plus
Step 4.3 If user pressed “SUB” button set operator as minus
Step 4.4 If user pressed “MUL” button set operator as multiply
Step 4.5 If user pressed “DIV” button set operator as divide
Step 4.6 Goto step 3
Step 5 Repeat the process until user presses the close button then Stop the Process.
Program:
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()
41
{ //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();
} }

42
Output:

Result:

The java program for Basic Calculator Application Using Java AWT Packages was developed and
tested successfully.
Outcome:
Thus the course outcome (CO3) has been attained by applying the concept of event handling to design
basic calculator using Java.
Applications:
(1) Age calculator
(2) EB calculator

43
Ex. No.: 14
SCIENTIFIC CALCULATOR APPLICATION USING JAVA AWT PACKAGES

Aim:
To create a Java GUI application that mimics the advanced functionalities of a scientific calculator.
Algorithm:
Step 1 Start the Process
Step 2 Display Text View and Number Pad and Option Pads
Step 3 If user presses any number get the existing numbers in Text View add them up and display
Step 4 If advanced button pressed
Step 4.1 Change Operant Types [+,-,x,/ into sin, cos, tan, log] and goto step 2
Step 5 If user pressed any of the operator
Step 5.1 Get the Text View content as Operant 1 and Set the display to null.
Step 5.2 If user pressed “sin” button set display the sin value of Operant 1
Step 5.3 If user pressed “cos” button set display the cos value of Operant 1
Step 5.4 If user pressed “tan” button set display the tan value of Operant 1
Step 5.5 If user pressed “log” button set display the log value of Operant 1
Step 5.6 Goto step 4
Step 6 If advanced pressed again then revert the button changes and return back to normal
Step 7 Repeat the process until user presses the close button then Stop the Process.
Program:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class Calculator extends JFrame
{ private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20);
private JTextField textfield;
private boolean number = true;
private String equalOp = "=";
private CalculatorOp op = new CalculatorOp();
public Calculator()
{ textfield = new JTextField("", 12);
textfield.setHorizontalAlignment(JTextField.RIGHT);
textfield.setFont(BIGGER_FONT);
44
ActionListener numberListener = new NumberListener();
String buttonOrder = "1234567890 ";
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(4, 4, 4, 4));
for (int i = 0; i < buttonOrder.length(); i++)
{ String key = buttonOrder.substring(i, i+1);
if (key.equals(" "))
{ buttonPanel.add(new JLabel(""));
} else
{ JButton button = new JButton(key);
button.addActionListener(numberListener);
button.setFont(BIGGER_FONT);
buttonPanel.add(button);
} } ActionListener operatorListener = new OperatorListener();
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4, 4, 4, 4));
String[] opOrder = {"+", "-", "*", "/","=","C","sin","cos","log"};
for (int i = 0; i < opOrder.length; i++)
{ JButton button = new JButton(opOrder[i]);
button.addActionListener(operatorListener);
button.setFont(BIGGER_FONT);
panel.add(button);
} JPanel pan = new JPanel();
pan.setLayout(new BorderLayout(4, 4));
pan.add(textfield, BorderLayout.NORTH );
pan.add(buttonPanel , BorderLayout.CENTER);
pan.add(panel , BorderLayout.EAST);
this.setContentPane(pan);
this.pack();
this.setTitle("Calculator");
this.setResizable(false);
} private void action()
{ number = true;
textfield.setText("");
equalOp = "=";
45
op.setTotal("");
} class OperatorListener implements ActionListener
{ public void actionPerformed(ActionEvent e)
{ String displayText = textfield.getText();
if (e.getActionCommand().equals("sin"))
{ textfield.setText ("" + Math.sin(Double.valueOf(displayText).doubleValue()));
} else
if (e.getActionCommand().equals("cos"))
{ textfield.setText("" + Math.cos(Double.valueOf(displayText).doubleValue()));
} else
if (e.getActionCommand().equals("log"))
{ textfield.setText("" + Math.log(Double.valueOf(displayText).doubleValue()));
} else if (e.getActionCommand().equals("C"))
{ textfield.setText("");
} else
{ if (number)
{ action();
textfield.setText("");
} else
{ number = true;
if (equalOp.equals("="))
{
op.setTotal(displayText);
}else
if (equalOp.equals("+"))
{ op.add(displayText);
} else if (equalOp.equals("-"))
{ op.subtract(displayText);
} else if (equalOp.equals("*"))
{ op.multiply(displayText);
} else if (equalOp.equals("/"))
{ op.divide(displayText);
} textfield.setText("" + op.getTotalString());
equalOp = e.getActionCommand();
} } } }
46
class NumberListener implements ActionListener
{ public void actionPerformed(ActionEvent event)
{ String digit = event.getActionCommand();
if (number)
{ textfield.setText(digit);
number = false;
} else
{ textfield.setText(textfield.getText() + digit);
} } }
public class CalculatorOp
{ private int total;
public CalculatorOp()
{ total = 0;
} public String getTotalString()
{ return ""+total;
} public void setTotal(String n)
{ total = convertToNumber(n);
} public void add(String n)
{ total += convertToNumber(n);
} public void subtract(String n)
{ total -= convertToNumber(n);
} public void multiply(String n)
{ total *= convertToNumber(n);
} public void divide(String n)
{ total /= convertToNumber(n);
} private int convertToNumber(String n)
{ return Integer.parseInt(n);
} } }
class SwingCalculator
{ public static void main(String[] args)
{ JFrame frame = new Calculator();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
} }

47
Output:

Result:
Thus the implementation of generic function is achieved for finding the maximum value from the
given type of elements.
Outcome:
Thus the course outcome (CO3) has been attained by applying the concept of event handling to design
calculator using Java.
Applications:
1) Age calculator
2) EB calculator

48
Ex. No.: 15
MINI PROJECT USING JAVA APPLICATION VEHICLE MANAGEMENT SYSTEM

Aim
To design a Mini Project Using Java Application Vehicle Management System.
Procedure:
1. Start the program
2. Using the swing components design the necessary layout
3. Add the details using JDBC(Java Data Base Connectivity).
4. Get the details of vehicle number, make, Fuel type , Vehicle type ,Insurer ,Rupees per
kilometer , Cost and company from the user
5. Store it in the database and do the necessary manipulations.
6. Stop the program
Output:
//Administrator class
package com.myproject.bus.service;
import java.sql.Connection;
import java.sql.*;
import java.util.ArrayList;
import com.myproject.bus.bean.ScheduleBean;
import com.myproject.bus.dao.ScheduleDAO;
import com.myproject.bus.util.DBUtil;
import com.myproject.bus.util.InvalidInputException;
public class Administrator
{ public String addSchedule(ScheduleBean scheduleBean)
{ String source=scheduleBean.getSource();
String destination=scheduleBean.getDestination();
Try { if((scheduleBean==null)||(source=="")
||(destination=="")||(source.length()<2)||(destination.length()<2))
throw new InvalidInputException();
else if(source==destination)
return "Source and Destination Same";
else { //return "success";
String sid="";
ScheduleDAO sd=new ScheduleDAO();

49
sid=sd.generateID(source,destination);
scheduleBean.setScheduleId(sid);
String s=sd.createSchedule(scheduleBean);
return s; } }
catch(Exception e)
{ return e.toString();
} }
public ArrayList<ScheduleBean> viewSchedule(String source,String destination)
{ ArrayList<ScheduleBean> al=new ArrayList<ScheduleBean>();
ScheduleBean sb=new ScheduleBean();
Try { Connection con=DBUtil.getDBConnection();
PreparedStatement ps=con.prepareStatement("select * from schedulable where
source='"+source+"'and destination='"+destination+"'");
ResultSet rs=ps.executeQuery();
while(rs.next())
{ sb.setScheduleId(rs.getString(1));
sb.setSource(rs.getString(2));
sb.setDestination(rs.getString(3));
sb.setStartTime(rs.getString(4));
sb.setStartTime(rs.getString(5));
al.add(sb);
//System.out.println("adding"); }
} catch(Exception e)
{ e.printStackTrace();
} return al; } }
// Main servlet
package com.myproject.bus.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import com.myproject.bus.bean.ScheduleBean;
import com.myproject.bus.dao.ScheduleDAO;

50
import com.myproject.bus.service.Administrator;
public class MainServlet extends HttpServlet
{ private static final long serialVersionUID = 1L;
public String addSchedule(HttpServletRequest request)
{ ScheduleBean sb=new ScheduleBean();
//ScheduleDAO sd=new ScheduleDAO();
Administrator a=new Administrator();
String source=request.getParameter("Source");
String dest=request.getParameter("Destination");
String stime=request.getParameter("StartTime");
String atime=request.getParameter("ArrivalTime");
sb.setSource(source);
sb.setDestination(dest);
sb.setStartTime(stime);
sb.setArrivalTime(atime);
String cr=a.addSchedule(sb);
return cr;
} public ArrayList<ScheduleBean>viewSchedule(HttpServletRequest request)
{ Administrator a=new Administrator();
ArrayList<ScheduleBean> al=new ArrayList<ScheduleBean>();
//ScheduleBean sb=new ScheduleBean();
String source=request.getParameter("Source");
String dest=request.getParameter("Destination");
al=a.viewSchedule(source,dest);
return al;
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{ String res="";
ArrayList<ScheduleBean> al=new ArrayList<ScheduleBean>();
MainServlet m=new MainServlet();
String str=request.getParameter("operation");
PrintWriter out=response.getWriter();
if(str.equalsIgnoreCase("newSchedule"))
{ res=m.addSchedule(request);
if(res.equalsIgnoreCase("SUCCESS"))

51
response.sendRedirect("success.html");
else if(res.equalsIgnoreCase("FAIL"))
response.sendRedirect("errorinserting.html");
} else if(str.equalsIgnoreCase("viewSchedule"))
{ al=m.viewSchedule(request);
if(al.size()==0)
response.sendRedirect("displaySchedule.html");
else{
System.out.println("in else ");
/*request.setAttribute("busSchedule",al);
RequestDispatcher rd=request.getRequestDispatcher("displaySchedule.html");
rd.forward(request,response);*/
out.print("<html><body>"+ res+" </body></html>");
} } } }
//Addschedule.html
<!DOCTYPE html>
<html>
<head> <meta charset="ISO-8859-1">
<title>Insert title here</title>
</head> <body>
<form action="MainServlet" method="post">
<b>Enter Schedule Details</b><br> Source:
<input type="text" name="Source"><br> Destination:
<input type="text" name="Destination"><br> Starting time:
<input type="text" name="StartTime"><br> Arrival time:
<input type="text" name="ArrivalTime"><br>
<input type="submit" value="create schedule">
<br> <input type="hidden" name="operation" value="newSchedule">
</form> </body> </html>
//Viewschedule.html <!DOCTYPE html>
<html> <head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head> <body>
<form action="MainServlet" method="post"> Enter Source:

52
<input type="text" name="Source"><br> Enter destination:
<input type="text" name="Destination"><br>
<input type="submit" value="search schedule">
<input type="hidden" name="operation" value="viewSchedule">
</form> </body> </html>
//displayschedule.html <!DOCTYPE html>
<html> <head> <meta charset="ISO-8859-1">
<title>Insert title here</title> </head>
<body> <h1> No matching record </h1> </body> </html>
//errorinserting.html <!DOCTYPE html>
<html> <head> <meta charset="ISO-8859-1">
<title>Insert title here</title> </head> <body>
<form> <h1> <font color="blue">
Error in adding the record!Please try again... </font> </h1>
</form> </body> </html>
//menu.html(main html) <!DOCTYPE html>
<html> <head> <meta charset="ISO-8859-1">
<title>Insert title here</title> </head>
<body> <form action="MainServlet" method="post">
<h1> <font color="red">
BLUE SCHEDULE </font> </h1>
<h2> <a href="Addschedule.html" name="operation" value="newSchedule">
Add Schedule</a>&nbsp;&nbsp;
<a href="Viewschedule.html" name="operation" value="viewSchedule">View Schedule</a></h2>
</form> </body> </html>
//success.html <!DOCTYPE html>
<html> <head> <meta charset="ISO-8859-1">
<title>Insert title here</title>
</head> <body> <form>
<h1> <font color="green"> Added Successfully </font> </h1>
</form> </body> </html>

53
Output: Admin Page

Vehicle Details:

Result:
Thus the design of vehicle management system using Java has been successfully executed.
Outcome:
Thus the course outcome (CO5) has been attained by generating a real world GUI application using
Java.
MINIPROJECTS
1. Airline Reservation System
2. Mark sheet Preparation system
3. NAAC online application creation
4. Library Management System
5. Converting RGB image to Gray Image
6. Health Care System
7. App development
8. Income Tax System
9. Vehicle Tracking System
10. E-banking System

54

You might also like