Docsity

Java Program for Electricity Bill Calculation and File I/O Operations, Exercises of Manufacturing Processes

Toggle sidebar
bg1
Ex. No.:1 ELECTRICITY BILL GENERATION
PROGRAM:
import java.util.*;
class ComputeElectricityBill1
{
public static void main(String args[])
{
long pmr,cmr,units;
int connection,cno;
String cname;
System.out.println("*************WELCOME TO TNEB**************");
System.out.println("*************PAY YOUR BILL HERE***********");
Scanner sc=new Scanner(System.in);
System.out.println("enter customer number please");
cno=sc.nextInt();
System.out.println("enter customer name please");
cname=sc.next();
System.out.println("enter the type of EB connection Domestic(1)/commercial(2)");
connection=sc.nextInt();
System.out.println("enter previous month reading in units");
pmr=sc.nextLong();
System.out.println("enter next month reading in units");
cmr=sc.nextLong();
units=cmr-pmr;
double billpay=0;
if(connection==1)
{
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f

Partial preview of the text

Download Java Program for Electricity Bill Calculation and File I/O Operations and more Exercises Manufacturing Processes in PDF only on Docsity!

Ex. No.:1 ELECTRICITY BILL GENERATION PROGRAM: import java.util.*; class ComputeElectricityBill { public static void main(String args[]) { long pmr,cmr,units; int connection,cno; String cname; System.out.println("*************WELCOME TO TNEB**************"); System.out.println("*************PAY YOUR BILL HERE***********"); Scanner sc=new Scanner(System.in); System.out.println("enter customer number please"); cno=sc.nextInt(); System.out.println("enter customer name please"); cname=sc.next(); System.out.println("enter the type of EB connection Domestic(1)/commercial(2)"); connection=sc.nextInt(); System.out.println("enter previous month reading in units"); pmr=sc.nextLong(); System.out.println("enter next month reading in units"); cmr=sc.nextLong(); units=cmr-pmr; double billpay=0; if(connection==1) {

if(units<=100) billpay=units*1.00;

else if(units>101 && units<=200) billpay=1001.00+(units-100)2.50;

else if(units>201 && units<=500) billpay=1001.00+1002.50+(units-200)4.00; else if(units>=500) billpay=1001.00+1002.50+1004.00+(units-300)*6.00; System.out.println("Bill to pay : " + billpay); }

if(connection==2) { if(units<=100) billpay=units*2.00;

else if(units>101 && units<=200) billpay=1002.00+(units-100)4.50;

else if(units>201 && units<=500) billpay=1002.00+1004.50+(units-200)6.00; else if(units>=500) billpay=1002.00+1004.50+1006.00+(units-300)*7.00; System.out.println("Bill to pay : " + billpay); }

Bill to pay : 1490. D:\csejava>

Ex. No.:2 Currency Converter, Distance Converter and Time Converter Program:

Currency.java package mypack; public class Currency { double c=100.0; public void display() { System.out.println("Currency value is 100"); System.out.println(" Dollar to INR : "+c*70.0); System.out.println(" INR to Dollar : "+c/70.0); } }

Distance.java package mypack; public class Distance { double c=15.0; public void display() {

Ex. No.:3 PAYROLL PROCESSING PROGRAM: employee1.java import java.util.Scanner; class Employee { int empid,mnum; String empname, address,mailid; double bsalary,gsalary,nsalary; final double da=97; final double hra=12; final double cfund=0.1; final double pf=12; String designation; Scanner get = new Scanner(System.in); void get_Details() { System.out.println("Enter id of the Employee:"); empid = get.nextInt(); System.out.println("Enter Name of the Employee:"); empname = get.next(); System.out.println("Enter mailid of the Employee:"); mailid = get.next(); System.out.println("Enter Address of the Employee:"); address = get.next(); System.out.println("Enter Mobile number:"); mnum = get.nextInt();

void calculatepay() { gsalary=bsalary+(bsalary(da/100)+bsalary(hra/100)); nsalary=gsalary-(bsalary(pf/100)-bsalary(cfund/100)); } void display() { System.out.println("Employee id: "+empid); System.out.println("Employee Name: "+empname); System.out.println("Mail id: "+mailid); System.out.println("Mobile Number: "+mnum); System.out.println("Address: "+address); System.out.println("Designation: "+designation); System.out.println("Gross Salary: "+gsalary); System.out.println("Net Salary: "+nsalary);

class professor extends Employee { professor(float bs,String des) { bsalary=bs; designation=des; } }

public static void main(String args[]) { System.out.println("================================"+"\n"+"Enter Full Time Employee Details"+"\n"+"================================"+"\n"); professor ob1 = new professor(50000,"Prof"); ob1.get_Details(); ob1.calculatepay(); Asstprof ob2 = new Asstprof(30000,"AsstProf"); ob2.get_Details(); ob2.calculatepay(); Assoprof ob3 = new Assoprof(40000,"AssoProf"); ob3.get_Details(); ob3.calculatepay(); Programmer ob4 = new Programmer(20000,"Prog"); ob4.get_Details(); ob4.calculatepay(); ob1.display(); ob2.display(); ob3.display(); ob4.display(); } } OUTPUT: D:\csejava>java employee ================================ Enter Full Time Employee Details

Enter id of the Employee: 110 Enter Name of the Employee: Ashwin Enter mailid of the Employee: [email protected] Enter Address of the Employee: Chennai Enter Mobile number: 9999999 Enter id of the Employee: 200 Enter Name of the Employee: Christy Enter mailid of the Employee: [email protected] Enter Address of the Employee: Bombay Enter Mobile number: 8888888 Enter id of the Employee: 500 Enter Name of the Employee: Srividhya Enter mailid of the Employee:

Address: Bombay Designation: AsstProf Gross Salary: 62700. Net Salary: 59130. Employee id: 500 Employee Name: Srividhya Mail id: [email protected] Mobile Number: 777777 Address: Vellore Designation: AssoProf Gross Salary: 83600. Net Salary: 78840. Employee id: 800 Employee Name: Ajay Mail id: [email protected] Mobile Number: 888999 Address: MAdurai Designation: Prog Gross Salary: 41800. Net Salary: 39420. D:\csejava>

Ex. No.:4 ADT STACK StackDemo.java import java.io.; import java.util.; interface interface { void push(int item); int pop(); } class ArrStack implements interface { int size; int[]st; private int top; private int items_count; public ArrStack(int Max) { size = Max; st=new int[size]; top=-1; } public void push(int item) { try {

if(top==-1) System.out.println("Stack is empty"); else if(size == top) System.out.println("Stack is Full"); else System.out.println(" "+st[i]); } } } class StackDemo { public static void main(String[]args) { ArrStack obj=new ArrStack(10); System.out.println("\n--------------------------"); System.out.println("\n Stack Using Array"); System.out.println("\n--------------------------"); obj.push(10); obj.push(20); obj.push(30); obj.display(); System.out.println("--------------------------"); System.out.println(" The popped item is : "+obj.pop()); System.out.println("--------------------------"); obj.display(); System.out.println("\n--------------------------");

OUTPUT:

D:\csejava>javac StackDemo.java

D:\csejava>java StackDemo

Stack Using Array

Stack Contains:

30 20 10


The popped item is : 30

Stack Contains:

20 10


D:\csejava>

obj.remove("sandy"); System.out.println("the element are list:"+obj); System.out.println("The element'abcc'in:"+obj.indexOf("abcc")); System.out.println("The element'abcc'in:"+obj.contains("abcc")); } } OUTPUT: D:\csejava>javac Arraylistex.java D:\csejava>java Arraylistex the element in the list are:[vicky, stanly, rajesh, balaji, sandy] the element are list:[vicky, stanly, rajesh, balaji] The element'abcc'in:- The element'abcc'in:false

Ex. No.:6 ABSTRACT CLASS import java.util.*;

abstract class shape { public int a,b; abstract public void print_area(); } class rectangle extends shape { public int area_rect; public void print_area() { area_rect=a*b; System.out.println("The area of rectangle is:"+area_rect); }

class triangle extends shape { int area_tri; public void print_area() { area_tri=(int) (0.5ab); System.out.println("The area of triangle is:"+area_tri); } }

class circle extends shape {