import java.util.*;
class EBBill
{
public static void main(String args[])
{
String type;
long LastReading, CurrentReading;
long units;
double bill=0;
units=CurrentReading-LastReading;
if(type.compareToIgnoreCase("domestic")==0)
{
if(units<=100)
bill=units;
else if(units<=200)
bill=100 + (units-100)*2.50;
else if(units<=500)
bill=100+(100*2.50)+(units-200)*4;
else
bill=100+(100*2.50)+(300*4)+(units-500)*6;
}
else if(type.compareToIgnoreCase("commercial")==0)
{
if(units<=100)
bill=units*2;
else if(units<=200)
bill=100*2 + (units-100)*4.50;
else if(units<=500)
bill=100*2 +(100*4.50)+(units-200)*6;
else
bill=100*2 +(100*4.50)+(300*6)+(units-
500)*7;
}
else
System.out.println("\nInvalid entry");
}
}
OUTPUT:
PROGRAM CODE:
/*
DolINR.java
Exp2 - Conversion using packages
*/
package convert.currency;
package convert.currency;
package convert.currency;
package convert.distance;
package convert.distance;
package convert.time;
import java.util.*;
import convert.time.*;
import convert.distance.*;
import convert.currency.*;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
HourMinSec t=new HourMinSec();
MetKm mek=new MetKm();
MileKm mik=new MileKm();
DolINR di=new DolINR();
EuroINR ei=new EuroINR();
YenINR yi=new YenINR();
double hour;
double met,mile,km;
double inr, dol, yen, euro;
System.out.println("TIME CONVERSION");
System.out.println("Hours: ");
hour=sc.nextDouble();
System.out.println("Hours to Minutes:
"+t.HourtoMin(hour));
System.out.println("Hours to Seconds:
"+t.HourtoSec(hour));
System.out.println("\n\nDISTANCE CONVERSION");
System.out.println("Kilometres: ");
km=sc.nextDouble();
System.out.println("Kilometres to metres:
"+mek.KmtoMet(km));
System.out.println("Kilometres to miles:
"+mik.KmtoMile(km));
System.out.println("\nMiles: ");
mile=sc.nextDouble();
System.out.println("Miles to kilometres:
"+mik.MiletoKm(mile));
System.out.println("\nMetres: ");
met=sc.nextDouble();
System.out.println("Metres to kilometres:
"+mek.MettoKm(met));
System.out.println("\n\nCURRENCY CONVERSION");
System.out.println("INR: ");
inr=sc.nextDouble();
System.out.println("INR to Dollar:
"+di.INRtoDol(inr));
System.out.println("INR to Euro:
"+ei.INRtoEuro(inr));
System.out.println("INR to Yen: "+yi.INRtoYen(inr));
System.out.println("Dollar: ");
dol=sc.nextDouble();
System.out.println("Dollar to INR:
"+di.DoltoINR(dol));
System.out.println("Euro: ");
euro=sc.nextDouble();
System.out.println("Euro to INR:
"+ei.EurotoINR(euro));
System.out.println("Yen: ");
yen=sc.nextDouble();
System.out.println("Yen to INR: "+yi.YentoINR(yen));
}
};
OUTPUT:
PROGRAM CODE:
import java.util.*;
import java.io.*;
class Employee
{
String empName;
String empID;
String address;
String mailID;
long mobile;
double DA;
double HRA;
double PF;
double StaffClubFund;
double GrossPay;
double NetPay;
void getDetails()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter your details");
System.out.println("Name: ");
empName=sc.nextLine();
System.out.println("Employee ID: ");
empID=sc.nextLine();
System.out.println("Address: ");
address=sc.nextLine();
System.out.println("Mail ID: ");
mailID=sc.nextLine();
System.out.println("Mobile Number: ");
mobile=sc.nextLong();
}
System.out.println("Name: "+empName);
System.out.println("ID: "+empID);
System.out.println("Address: "+address);
System.out.println("Mail ID: "+mailID);
System.out.println("Mobile number: "+mobile);
public Programmer()
{
Scanner sc=new Scanner(System.in);
System.out.println("\nEnter the programmer's
basic pay: ");
BP=sc.nextDouble();
getDetails();
calc(BP);
printSlip(BP);
}
};
class AsstProfessor extends Employee
{
double BP;
public AsstProfessor()
{
Scanner sc=new Scanner(System.in);
System.out.println("\nEnter the assistant
professor's basic pay: ");
BP=sc.nextDouble();
getDetails();
calc(BP);
printSlip(BP);
}
};
public AssoProfessor()
{
Scanner sc=new Scanner(System.in);
System.out.println("\nEnter the associate
professor's basic pay: ");
BP=sc.nextDouble();
getDetails();
calc(BP);
printSlip(BP);
}
};
case 2:
AsstProfessor astProf=new
AsstProfessor();
break;
case 3:
AssoProfessor asoProf=new
AssoProfessor();
break;
default:
System.out.println("Invalid
choice");
}
};
OUTPUT:
PROGRAM CODE:
/*
StackOperations.java
*/
interface StackOperations
{
public void push(int val);
public void pop();
public void display();
};
/*
Stack.java
*/
import java.util.*;
Stack()
{
length=0;
}
do
{
System.out.println("\n\n1. Push\n2. Pop\n3.
Display\n4. Exit\nEnter your choice ");
ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Enter the element
to be pushed ");
val=sc.nextInt();
st.push(val);
break;
case 2:
st.pop();
break;
case 3:
st.display();
break;
case 4:
break;
default:
System.out.println("Invalid choice");
}
}while(ch>0&&ch<4);
}
};
OUTPUT:
PROGRAM CODE:
import java.util.*;
case 2:
System.out.println("Enter a string
");
s=sc.next();
System.out.println("Position of
insertion: ");
int pos=sc.nextInt();
strings.add(pos,s);
System.out.println("ArrayList has
been updated");
System.out.println(strings);
break;
case 3:
System.out.println("Enter the string
you are searching for ");
s=sc.next();
if(strings.contains(s))
System.out.println(s+" is
present in the ArrayList");
else
System.out.println("String not
found");
break;
case 4:
System.out.println("Starting letter:
");
char letter=sc.next().charAt(0);
for(int i=0;i<strings.size();i++)
{
if(strings.get(i).charAt(0)==letter)
{
System.out.println(strings.get(i));
}
}
break;
}
}while(ch>=0&&ch<=4);
}
};
OUTPUT:
PROGRAM CODE:
import java.util.*;
class Areas
{
public static void main(String args[])
{
Rectangle r=new Rectangle(2,3);
r.printArea();
import java.util.*;
NException(String msg)
{
this.msg=msg;
}
try
{
System.out.println("Enter a number ");
i=sc.nextInt();
if(i<0)
{
NException e = new NException("Negative
numbers are not permitted");
throw e;
}
else
{
System.out.println("The number has been
accepted");
}
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
System.out.println("Exception, if generated,
has been handled.");
}
}
};
OUTPUT:
PROGRAM CODE:
/*
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.
*/
import java.util.*;
import java.io.*;
try
{
File f=new File(filename);
}
catch(Exception e)
{
System.out.println(e);
}
}
};
OUTPUT:
PROGRAM CODE:
/*
Java program that implements a multi-threaded application that
has three threads. First thread generates a random integer
every 1 second and if the value is even, second thread
computes the square of the number and prints. If the value is
odd, the third thread will print the value of cube of the
number.
*/
import java.util.Random;
import java.util.*;
import java.lang.*;
EvenSquare(int num)
{
n=num;
}
OddCube(int num)
{
n=num;
}
import java.util.*;
import java.lang.*;
class Gen
{
import java.awt.*;
import java.awt.event.*;
Calculator()
{
Frame f = new Frame("Calculator");
f.setBounds(500,200,200,300);
f.setLayout(new FlowLayout());
txt=new TextField(20);
f.add(txt);
//txt.setBounds(100,30,20,20);
//txt.setText("It works!");
b9=new Button("9");
b9.addActionListener(this);
p.add(b9);
b8=new Button("8");
b8.addActionListener(this);
p.add(b8);
b7=new Button("7");
b7.addActionListener(this);
p.add(b7);
b6=new Button("6");
b6.addActionListener(this);
p.add(b6);
b5=new Button("5");
b5.addActionListener(this);
p.add(b5);
b4=new Button("4");
b4.addActionListener(this);
p.add(b4);
b3=new Button("3");
b3.addActionListener(this);
p.add(b3);
b2=new Button("2");
b2.addActionListener(this);
p.add(b2);
b1=new Button("1");
b1.addActionListener(this);
p.add(b1);
b0=new Button("0");
b0.addActionListener(this);
p.add(b0);
ba=new Button("+");
ba.addActionListener(this);
p.add(ba);
bs=new Button("-");
bs.addActionListener(this);
p.add(bs);
bm=new Button("x");
bm.addActionListener(this);
p.add(bm);
bd=new Button("/");
bd.addActionListener(this);
p.add(bd);
be=new Button("=");
be.addActionListener(this);
p.add(be);
bc=new Button("CLR");
bc.addActionListener(this);
p.add(bc);
f.add(p);
f.setVisible(true);
}
if(e.getSource()==b1)
{
temp=txt.getText();
temp+="1";
txt.setText(temp);
}
if(e.getSource()==b2)
{
temp=txt.getText();
temp+="2";
txt.setText(temp);
}
if(e.getSource()==b3)
{
temp=txt.getText();
temp+="3";
txt.setText(temp);
}
if(e.getSource()==b4)
{
temp=txt.getText();
temp+="4";
txt.setText(temp);
}
if(e.getSource()==b5)
{
temp=txt.getText();
temp+="5";
txt.setText(temp);
}
if(e.getSource()==b6)
{
temp=txt.getText();
temp+="6";
txt.setText(temp);
}
if(e.getSource()==b7)
{
temp=txt.getText();
temp+="7";
txt.setText(temp);
}
if(e.getSource()==b8)
{
temp=txt.getText();
temp+="8";
txt.setText(temp);
}
if(e.getSource()==b9)
{
temp=txt.getText();
temp+="9";
txt.setText(temp);
}
if(e.getSource()==bc)
{
txt.setText("");
num1="0";
}
if(e.getSource()==ba)
{
num1=txt.getText();
op=1;
txt.setText(num1+"+");
}
if(e.getSource()==bs)
{
num1=txt.getText();
op=2;
txt.setText(num1+"-");
}
if(e.getSource()==bm)
{
num1=txt.getText();
op=3;
txt.setText(num1+"x");
}
if(e.getSource()==bd)
{
num1=txt.getText();
op=4;
txt.setText(temp+"/");
}
if(e.getSource()==be)
{
if(op==1)
{
temp=txt.getText();
index=temp.lastIndexOf('+');
num2=temp.substring(index+1);
result=Integer.parseInt(num1)+Integer.parseInt(num2);
r=Integer.toString(result);
txt.setText(r);
}
if(op==2)
{
temp=txt.getText();
index=temp.lastIndexOf('-');
num2=temp.substring(index+1);
result=Integer.parseInt(num1)-
Integer.parseInt(num2);
r=Integer.toString(result);
txt.setText(r);
}
if(op==3)
{
temp=txt.getText();
index=temp.lastIndexOf('x');
num2=temp.substring(index+1);
result=Integer.parseInt(num1)*Integer.parseInt(num2);
r=Integer.toString(result);
txt.setText(r);
}
if(op==4)
{
temp=txt.getText();
index=temp.lastIndexOf('/');
num2=temp.substring(index+1);
result=Integer.parseInt(num1)/Integer.parseInt(num2);
r=Integer.toString(result);
txt.setText(r);
}
}
}