REG NO:211018104 NAME:
TO GENERATE ELECTRICITY BILL
import java.util.*;
class Ebill
{
int cno;
String cname,type;
double current,previous,unit,tbill;
Scanner in=new Scanner(System.in);
Scanner in=new Scanner(System.in);
{
System.out.println("Enter cno");
cno=in.nextInt();
System.out.println("Enter cname");
cname=inp.nextLine();
System.out.println("Enter type");
type=inp.nextLine();
System.out.println("Enter current reading");
current=in.nextDouble();
System.out.println("Enter previous reading");
previous=in.nextDouble();
}
void calc()
{
unit=current-previous;
REG NO:211018104 NAME:
if(type.equals("D"))
{
if (unit<=100)
tbill=1*unit;
else if(unit<=200)
tbill=2.50*unit;
else if(unit<=500)
tbill=4*unit;
else
tbill=6*unit;
}
else
{
if(unit<=100)
tbill=2*unit;
else if(unit<=200)
tbill=4.50*unit;
else if(unit<=500)
tbill=6*unit;
else
tbill=7*unit;
}
}
void display()
{
System.
out.println("\ncustomer no is"+cno);
REG NO:211018104 NAME:
System.out.println("customer name is "+cname);
System.out.println("\nusage type is "+type);
System.out.println("\ncurrent reading"+current);
System.out.println("\nprevious month reading"+previous);
System.out.println("\nunits of current "+unit);
System.out.println("\ntotal current "+tbill);
}
}
class eb
{
public static void main(String args[])
{
Ebill e=new Ebill();
e.getinput();
e.calc();
e.display();
}
}
REG NO:211018104 NAME:
CURRENCY CONVERTER
import java.util.*;
class Converter
{
REG NO:211018104 NAME:
double d,i,e,y;
Scanner in=new Scanner(System.in);
void dtoi()
{
System.out.println("enter in dollars");
d=in.nextDouble();
i=d*68.56;
System.out.println("the indian rupees is"+i);
}
void itod()
{
System.out.println("enter in rupees");
i=in.nextDouble();
d=i/68.56;
System.out.println("the dollar is"+d);
}
void etoi()
{
System.out.println("enter in euro");
e=in.nextDouble();
i=e*77.39;
System.out.println("the indian rupee is"+i);
}
void itoe()
{
System.out.println("enter in rupees");
i=in.nextDouble();
REG NO:211018104 NAME:
e=i/77.39;
System.out.println("the euro is"+e);
}
void ytoi()
{
System.out.println("enter in yens");
y=in.nextDouble();
i=y*0.64;
System.out.println("the rupees is"+i);
}
void itoy()
{
System.out.println("enter in rupees");
i=in.nextDouble();
y=i/0.64;
System.out.println("the yen is"+y);
}
}
class Currency
{
public static void main(String args[])
{
int ch;
String a;
Scanner in=new Scanner(System.in);
Scanner i=new Scanner(System.in);
do
REG NO:211018104 NAME:
{
System.out.println("\n1.dollar to inr\n2.inr to dollar\n3.euro to dollar\n4.inrto euro\n5.yen to inr\n6.inr to yen");
System.out.println("enter your choice");
ch=in.nextInt();
Converter c=new Converter();
switch(ch)
{
case 1:
c.dtoi();
break;
case 2:
c.itod();
break;
case 3:
c.etoi();
break;
case 4:
c.itoe();
break;
case 5:
c.ytoi();
break;
case 6:
c.itoy();
break;
default:
System.out.println("enter correct choice");
REG NO:211018104 NAME:
}
System.out.println("do you want to continue");
a=i.nextLine();
}
while(a.equals("Y"));
}
}
OUTPUT:
REG NO:211018104 NAME:
REG NO:211018104 NAME:
TIME CONVERTER
import java.util.*;
class converter
{
double h,m,s;
Scanner in=new Scanner(System.in);
void htom()
{
System.out.println("enter time in hours");
h=in.nextDouble();
m=h*60;
System.out.println("the time in minutes is"+m);
REG NO:211018104 NAME:
}
void mtoh()
{
System.out.println("the time in minutes");
m=in.nextDouble();
h=m/60;
System.out.println("the time in hours is"+h);
}
void htos()
{
System.out.println("enter the time in hours");
h=in.nextDouble();
s=h*3600;
System.out.println("the time in seconds is"+s);
}
void stoh()
{
System.out.println(" enter the time in seconds");
s=in.nextDouble();
h=s/3600;
System.out.println("the time in hours is"+h);
}
}
class Time
{
public static void main(String args[])
{
REG NO:211018104 NAME:
int ch;
String a;
Scanner in=new Scanner(System.in);
Scanner i=new Scanner(System.in);
do
{
System.out.println("\n1.hours to minutes\n2.minutes to hours\n3.hours to seconds\n4.seconds to hours");
System.out.println("enter your choise");
ch=in.nextInt();
converter c=new converter();
switch(ch)
{
case 1:
c.htom();
break;
case 2:
c.mtoh();
break;
case 3:
c.htos();
break;
case 4:
c.stoh();
break;
default:
System.out.println("enter correct choice");
}
REG NO:211018104 NAME:
System.out.println("do you want to continue");
a=i.nextLine();
}
while(a.equals("y"));
}
}
OUTPUT:
REG NO:211018104 NAME:
Distance convertor
import java.util.*;
class Converter1
{
double m,k,mi;
Scanner in=new Scanner(System.in);
void mtok()
{
System.out.println("enter distance in meter");
m=in.nextDouble();
k=m/1000;
REG NO:211018104 NAME:
System.out.println("the distance in kilometer is"+k);
}
void ktom()
{
System.out.println("enter distance in kilometer");
k=in.nextDouble();
m=k*1000;
System.out.println("the distance in meter is"+m);
}
void mitok()
{
System.out.println("enter distance in miles");
mi=in.nextDouble();
k=mi*1.609;
System.out.println("the distance in kilometer is"+k);
}
void ktomi()
{
System.out.println("enter distance in kilometer");
k=in.nextDouble();
mi=k/1.609;
System.out.println("the distance in miles is"+mi);
}
}
class Distance
{
public static void main(String args[])
REG NO:211018104 NAME:
{
int ch;
String g;
Scanner in=new Scanner(System.in);
Scanner i=new Scanner(System .in);
do
{
System.out.println("\n1.meter to kilometer\n2.kilometer to meter\n3.miles to kilometer\n4.kilometer to miles");
System.out.println("enter your choice");
ch=in.nextInt();
Converter1 c=new Converter1();
switch (ch)
{
case 1:
c.mtok();
break;
case 2:
c.ktom();
break;
case 3:
c.mitok();
break;
case 4:
c.ktomi();
break;
default:
System.out.println ("enter the correct choice");
REG NO:211018104 NAME:
}
System.out.println("do you want to continue");
g=i.nextLine();
}
while(g.equals("Y"));
}
OUTPUT:
REG NO:211018104 NAME:
TO GENERATE EMPLOYEE PAYSLIP
import java.util.*;
class Employee
{
int emp_id;
String emp_name;
Scanner in =new Scanner(System.in);
Scanner i =new Scanner(System.in);
void getinput()
{
System.out.println("enter employee number");
emp_id=in.nextInt();
System.out.println("enter employee name");
emp_name=i.nextLine();
}
}
class Professer extends Employee
{
void compute()
{
double pf,bp,hra,ns;
System.out.println("enter basic pay");
bp=in.nextDouble();
hra=(bp*15/100);
pf=(bp*10/100);
REG NO:211018104 NAME:
ns=bp+hra-pf;
System.out.println("HRA"+hra);
System.out.println("Your pf"+pf);
System.out.println("Net pay"+ns);
}
}
class Associate_professer extends Employee
{
void compute()
{
double pf,bp,hra,ns;
System.out.println("enter basic pay");
bp=in.nextDouble();
hra=(bp*10/100);
pf=(bp*10/100);
ns=bp+hra-pf;
System.out.println("HRA"+hra);
System.out.println("Your pf"+pf);
System.out.println("Net pay"+ns);
}
}
class Assistant_professer extends Employee
{
void compute()
{
double pf,bp,hra,ns;
System.out.println("enter basic pay");
REG NO:211018104 NAME:
bp=in.nextDouble();
hra=(bp*5/100);
pf=(bp*5/100);
TSystem.out.println("HRA"+hra);
System.out.println("Your pf"+pf);
System.out.println("Net pay"+ns);
}
}
class Payslip
{
public static void main(String args[])
{
Professer p=new Professer();
System.out.println("======PROFESSER=======");
p.getinput();
p.compute();
Assistant_professer a=new Assistant_professer();
System.out.println("======ASSISTANT PROFESSER=======");
p.getinput();
p.compute();
Associate_professer b=new Associate_professer();
System.out.println("======ASSOCIATE PROFESSER=======");
b.getinput();
b.compute();
}
}
REG NO:211018104 NAME:
OUTPUT:
Stack ADTimport java.util.*;
REG NO:211018104 NAME:
interface inter1
{
void push(int element);
void pop();
}
class Operation implements inter1
{
int size;
int[] s;
int top;
Scanner in=new Scanner(System.in);
Operation(int max)
{
size=max;
s=new int[size];
top=-1;
}
public void push(int element)
{
if(top==size-1)
System.out.println("stack is full!!!insertion not possible");
else
top++;
s[top]=element;
}
public void pop()
{
REG NO:211018104 NAME:
int item;
if(top==-1)
System.out.println("stack is empty!!!!deletion not possible");
else
item=s[top];
top--;
}
void display()
{
System.out.println("the stack elements are");
if(top==-1)
System.out.println("stack is empty");
else
{
for(int i=top;i>=0;i--)
System.out.println(s[i]);
}
}
}
class Adtstack
{
public static void main(String args[])
{
int ch;
String g;
Scanner in=new Scanner(System.in);
Scanner i=new Scanner(System.in);
REG NO:211018104 NAME:
Operation o=new Operation(4);
do
{
System.out.println("**********stack operations***************");
System.out.println("1.push\n2.pop\n3.display\nenter your choice");
ch=in.nextInt();
switch(ch)
{
case 1:
o.push(10);
o.push(20);
o.push(30);
o.push(40);
break;
case 2:
o.pop();
break;
case 3:
o.display();
break;
default:
System.out.println("enter correct choice");
}
System.out.println("do you want to continue");
g=i.nextLine();
}while(g.equals("y"));
}
REG NO:211018104 NAME:
}
import java.util.*;
interface inter1
{
void push(int element);
void pop();
}
Class Operation implements inter1
{
int size;
int[] s;
int top;
Scanner in=new Scanner(System.in);
Operation(int max)
{
size=max;
s=new int[size];
top=-1;
}
public void push(int element)
{
if(top==size-1)
System.out.println("stack is full!!!insertion not possible");
else
top++;
s[top]=element;
}
REG NO:211018104 NAME:
public void pop()
{
int item;
if(top==-1)
System.out.println("stack is empty!!!!deletion not possible");
else
item=s[top];
top--;
}
void display()
{
System.out.println("the stack elements are");
if(top==-1)
System.out.println("stack is empty");
else
{
for(int i=top;i>=0;i--)
System.out.println(s[i]);
}
}
}
class Adtstack
{
public static void main(String args[])
{
int ch;
String g;
REG NO:211018104 NAME:
Scanner in=new Scanner(System.in);
Scanner i=new Scanner(System.in);
Operation o=new Operation(4);
do
{
System.out.println("**********stack operations***************");
System.out.println("1.push\n2.pop\n3.display\nenter your choice");
ch=in.nextInt();
switch(ch)
{
case 1:
o.push(10);
o.push(20);
o.push(30);
o.push(40);
break;
case 2:
o.pop();
break;
case 3:
o.display();
break;
default:
System.out.println("enter correct choice");
}
System.out.println("do you want to continue");
g=i.nextLine();
REG NO:211018104 NAME:
}while(g.equals("y"));
}
}
OUTPUT:
REG NO:211018104 NAME:
Array list
Import java.util.*;
class StringOperation
{
String s;
Scanner in=new Scanner(System.in);
Scanner i=new Scanner(System.in);
ArrayList<String> al=new ArrayList<String>();
void append()
{
System.out.println("enter the string to append" );
s=in.nextLine();
al.add(s);
System.out.println("the array list elements are\n");
for(String i:al)
System.out.println(i);
}
void insert()
{
int pos;
System.out.println("enter the string to insert" );
s=in.nextLine();
System.out.println("enter the position to insert" );
pos=i.nextInt();
REG NO:211018104 NAME:
al.add(pos,s);
System.out.println("the array list elemnts are");
for(String i:al)
System.out.println(i);
}
void search()
{
int i;
System.out.println("enter the string to search" );
s=in.nextLine();
System.out.println("the string found at" +(al.indexOf(s)+1));
}
void listStrings()
{
String a;
System.out.println("enter the starting letter of the string" );
a=in.nextLine();
for(String i:al)
if(i.startsWith(a))
System.out.println(i);
}
void remove()
{
String b;
System.out.println("enter the element to remove");
b=in.nextLine();
al.remove(b);
REG NO:211018104 NAME:
System.out.println("the array list elements are");
for(String i:al)
System.out.println(i);
}
}
class Array
{
public static void main(String args[])
{
int choice;
String g;
//ArrayList<String> al=new ArrayList<String>();
StringOperation st=new StringOperation();
Scanner in=new Scanner(System.in);
Scanner i=new Scanner(System.in);
do
{
System.out.println(" *****************MAIN MENU***********************" );
System.out.println("1.append\n2.insert\n3.search\n4.list strings\n5.remove\nenter your choice" );
choice=in.nextInt();
switch(choice)
{
case 1:
st.append();
break;
case 2:
st.insert();
REG NO:211018104 NAME:
break;
case 3:
st.search();
break;
case 4:
st.listStrings();
break;
case 5:
st.remove();
break;
default:
System.out.println(" enter the correct choice" );
}
System.out.println(" do you want to continue" );
g=i.nextLine();
}while(g.equals("y"));
}
}
OUTPUT:
REG NO:211018104 NAME:
REG NO:211018104 NAME:
Abstract classimport java.util.*;
abstract class Shapes
{
double a,b;
abstract void printArea();
}
class Rectangle extends Shapes
{
double area;
Scanner in=new Scanner(System.in);
public void printArea()
{
System.out.println("enter the lenght and breadth of the rectangle");
a=in.nextDouble();
b=in.nextDouble();
REG NO:211018104 NAME:
area=a*b;
System.out.println("the area of the rectangle is" +area+" square units");
}
}
class Circle extends Shapes
{
double area;
Scanner in=new Scanner(System.in);
public void printArea()
{
System.out.println("enter the radius of the circle");
a=in.nextDouble();
area=3.14*a*a;
System.out.println("the area of the circle is" +area+" square units");
}
}
class Triangle extends Shapes
{
double area;
Scanner in=new Scanner(System.in);
public void printArea()
{
System.out.println("enter the height and breadth of the triangle");
a=in.nextDouble();
b=in.nextDouble();
area=0.5*a*b;
System.out.println("the area of the triangle is" +area+" square units");
REG NO:211018104 NAME:
}
}
class Ab
{
public static void main(String args[])
{
int choice;
String g;
Scanner in=new Scanner(System.in);
Scanner i=new Scanner(System.in);
do
{
System.out.println("the shapes are");
System.out.println("1.rectangle\n2.circle\n3.triangle\nenter your choice");
choice=in.nextInt();
switch(choice)
{
case 1:
Shapes r=new Rectangle();
r.printArea();
break;
case 2:
Shapes c=new Circle();
c.printArea();
break;
case 3:
Shapes t=new Triangle();
REG NO:211018104 NAME:
t.printArea();
break;
default:
System.out.println("enter corect choice");
}
System.out.println("do you want to continue");
g=i.nextLine();
}while(g.equals("y"));
}
}
OUTPUT:
REG NO:211018104 NAME:
Exception handlingimport java.util.*;
class ValueTooSmallException extends Exception
{
ValueTooSmallException(String msg)
{
super(msg);
}
}
class NotValidException extends Exception
{
NotValidException(String s)
{
super(s);
}
}
class User1
{
public static void main(String args[])
{
int n;
String g;
Scanner in=new Scanner(System.in);
Scanner i=new Scanner(System.in);
System.out.println("enter your username");
g=in.nextLine();
System.out.println("enter the pin number");
REG NO:211018104 NAME:
n=in.nextInt();
try
{
if(g.length()<6)
throw new NotValidException("your username must have 6 characters");
else
System.out.println("user name:"+g);
}
catch(NotValidException d)
{
System.out.println(d);
}
try
{
if(n<100)
throw new ValueTooSmallException("enter the pin number in three digits");
else
System.out.println("pin number:"+n);
}
catch(ValueTooSmallException e)
{
System.out.println(e);
}
}
}
REG NO:211018104 NAME:
OUTPUT:
File operationsimport java.util.Scanner;
import java.io.File;
class FileDemo
{
public static void main(String args[])
{
System.out.println("enter the name of the file");
Scanner input=new Scanner(System.in);
REG NO:211018104 NAME:
String s=input.nextLine();
File f1=new File(s);
System.out.println("______________");
System.out.println("file name:"+f1.getName());
System.out.println("path:"+f1.getPath());
System.out.println("Abs path:"+f1.getAbsolutePath());
System.out.println("this file:"+(f1.exists()?"Exists":"Does not exists"));
System.out.println("Is file:"+f1.isFile());
System.out.println("Is directory:"+f1.isDirectory());
System.out.println("Is readable:"+f1.canRead());
System.out.println("Is writeable:"+f1.canWrite());
System.out.println("Is absolute:"+f1.isAbsolute());
System.out.println("File size:"+f1.length()+"bytes");
System.out.println("Is Hidden:"+f1.isHidden());
}
}
REG NO:211018104 NAME:
MULTI THREADING
import java.util.*;
class NumberGenerate
{
private int value;
private boolean flag;
public synchronized void put()
{
while(flag)
{
try{
wait();
}
catch(InterruptedException e){ }
REG NO:211018104 NAME:
}
flag=true;
Random random=new Random();
this.value=random.nextInt(10);
System.out.println("the generated number is:"+value);
notifyAll();
}
public synchronized void get1()
{
while(!flag)
{
try{
wait();
}
catch(InterruptedException e){ }
}
if(value%2==0)
{
System.out.println("second is executing now....");
int ans=value*value;
System.out.println(value+"is even number and its square is:"+ans);
}
flag=false;
notifyAll();
}
public synchronized void get2()
{
while(!flag)
{
REG NO:211018104 NAME:
try
{
wait();
}
catch(InterruptedException e){ }
}
if(value%2!=0)
{
System.out.println("third thread is executing now.....");
int ans=value*value*value;
System.out.println(value+"is odd number and its cube is:"+ans);
}
flag=false;
notifyAll();
}
}
public class TestNumber
{
public static void main(String args[])
{
final NumberGenerate obj=new NumberGenerate();
Thread producerThread=new Thread()
{
public void run()
{
for(int i=1;i<=6;i++)
{
System.out.println("main thread started....");
obj.put();
REG NO:211018104 NAME:
try
{
Thread.sleep(1000);
}
catch(InterruptedException e){ }
}
}
};
Thread consumerThread1=new Thread()
{
public void run()
{
for(int i=1;i<=3;i++)
{
obj.get1();
try
{
Thread.sleep(2000);
}
catch(InterruptedException e){ }
}
}
};
Thread consumerThread2=new Thread()
{
public void run()
{
for(int i=1;i<=3;i++)
{
REG NO:211018104 NAME:
obj.get2();
try
{
Thread.sleep(3000);
}
catch(InterruptedException e){ }
}
}
};
producerThread.start();
consumerThread1.start();
consumerThread2.start();
}