You are on page 1of 16

EX NO : 1 PROGRAM TO GENERATE ELECTRICITY BILL

AIM

To develop a Scala application to generate Electricity bill. 

PROCEDURE 

1.Create a class with the following members

   Consumer no., consumer name, previous month reading, current month reading, type of EB 

  connection (i.e domestic or commercial)

2.Compute the bill amount using the following tariff. 

      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 

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 

3. Create the object for the created class .Invoke the methods to get the input from the

consumer   

    and display the consumer information with the generated electricity bill.
PROGRAM

class ElectricalBill{

var Consumer_no:Int=38562

var Consumer_name:String="Ram"

var connection:String=""

var current_month_reading:Double=600

var prev_month_reading:Double=300

var totalunits:Double=current_month_reading-prev_month_reading

var amount:Double=0

if(connection=="Domestic")

if(totalunits>0 && totalunits>=100)

amount=totalunits*1;

if(totalunits>100 && totalunits<=200)

amount=totalunits*2.50

if(totalunits>200 && totalunits<=500)

amount=totalunits*4.00

else

amount=totalunits*6.00

else if(connection=="Commercial")

if (totalunits>0 && totalunits>=100)

amount=totalunits*2;

if (totalunits>100 && totalunits<=200)

amount=totalunits*4.50
if (totalunits>200 && totalunits<=500)

amount=totalunits*6.00

else

amount=totalunits*7.00

def Invoke(){

println(" Electrical bill ")

println("Consumer number: "+Consumer_no)

println("Consumer name: "+Consumer_name)

println("Connection type: "+connection)

println("Current month reading: "+current_month_reading)

println("Previous month reading: "+prev_month_reading)

println("Total units: "+totalunits)

println("Bill: "+amount)

object HelloWorld {

def main(args: Array[String]) {

var a=new ElectricalBill()

a.Invoke()

}
OUTPUT

APPLICATIONS : 

(1) Payroll Processing

(2) PF Calculation

RESULT

Thus the Scala program to generate electricity bill was implemented and executed successfully.
EX NO: 3 PROGRAM TO GENERATE PAYSLIP USING INHERITANCE

AIM

To develop a Scala application to generate pay slip for different category of employees using the

concept of inheritance.

PROCEDURE

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

class Employee
{
  println("Enter the details")
  var name=scala.io.StdIn.readLine()
  var Emp_id=scala.io.StdIn.readInt()
  var address=scala.io.StdIn.readLine()
  var mail_id=scala.io.StdIn.readLine()
  var mobile_no=scala.io.StdIn.readInt()
  var deduction=2500
  
}
class Programmer extends Employee
{
  var bp=15000
  var DA=(97/100)*bp
  var HRA=(10/100)*bp
  var PF=(12/100)*bp
  var Staff_fund=(0.1/100)*bp
  var gross_salary=bp+DA+HRA+PF+Staff_fund
  var net_salary=gross_salary-deduction
  def display()
  {
    println("Programmer Payslip")
  println("********************")
  println("Name "+name+"\nEmployee_id "+Emp_id+"\nAddress "+address+"\nEmpoyee mail id
"+mail_id+"\nMobile no "+mobile_no)
  println("\nGross salary"+gross_salary+"\nNet salary "+net_salary)
  
  }
}
class Assntprofessor extends Employee
{
  var bp=25000
  var DA=(97/100)*bp
  var HRA=(10/100)*bp
  var PF=(12/100)*bp
  var Staff_fund=(0.1/100)*bp
  var gross_salary=bp+DA+HRA+PF+Staff_fund
  var net_salary=gross_salary-deduction
  def display()
  {
    println("Assntprofessor Payslip")
  println("********************")
  println("Name "+name+"\nEmployee_id "+Emp_id+"\nAddress "+address+"\nEmpoyee mail id
"+mail_id+"\nMobile no "+mobile_no)
  println("\nGross salary"+gross_salary+"\nNet salary "+net_salary)
  }
}
class Associateprofessor extends Employee
{
  var bp=35000
  var DA=(97/100)*bp
  var HRA=(10/100)*bp
  var PF=(12/100)*bp
  var Staff_fund=(0.1/100)*bp
  var gross_salary=bp+DA+HRA+PF+Staff_fund
  var net_salary=gross_salary-deduction
  def display()
  {
    println("Associateprofessor Payslip")
  println("********************")
  println("Name "+name+"\nEmployee_id "+Emp_id+"\nAddress "+address+"\nEmpoyee mail id
"+mail_id+"\nMobile no "+mobile_no)
  println("\nGross salary"+gross_salary+"\nNet salary "+net_salary)
  }
}
class Professor extends Employee
{
  var bp=45000
  var DA=(97/100)*bp
  var HRA=(10/100)*bp
  var PF=(12/100)*bp
  var Staff_fund=(0.1/100)*bp
  var gross_salary=bp+DA+HRA+PF+Staff_fund
  var net_salary=gross_salary-deduction
  def display()
  {
    println("Professor Payslip")
  println("********************")
  println("Name "+name+"\nEmployee_id "+Emp_id+"\nAddress "+address+"\nEmpoyee mail id
"+mail_id+"\nMobile no "+mobile_no)
  println("\nGross salary"+gross_salary+"\nNet salary "+net_salary)
  }
}
object Main {
def main(args: Array[String]): Unit = {
var x=new Programmer()
x.display()
var y=new Associateprofessor()
y.display()
var z=new Associateprofessor()
z.display()
var w=new Professor()
w.display()  
}
}

OUTPUT
APPLICATIONS:

 (1) EB Bill Generation 

(2) Income Tax Calculation


RESULT

Thus the  Scala application to generate pay slip for different category of employees was

implemented  using inheritance and the program was executed successfully.


EX NO: 6 SCALA PROGRAM TO CREATE ABSTRACT CLASS AND CALCULATE AREA

AIM

To implement a scala program to create an abstract class and calculate area

PROCEDURE

1.Write a scala program to 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 one of the classes contain only the method print Area( ) that prints the area of the given shape

4. Display the Result

PROGRAM:

abstract class shape

var a=10

var b=20

def printarea()

class rectangle extends shape{

def printarea()

println("Area of Rectancle"+(a*b))

class triangle extends shape{

def printarea()

println("Area of Rectancle"+(a*b)/2)

class circle extends shape{


def printarea()

println("Area of Rectancle"+(3.14*a*a))

object Main{

def main(args: Array[String]): Unit={

var r= new rectangle()

var t= new triangle()

var c= new circle()

r.printarea()

t.printarea()

c.printarea()

OUTPUT

RESULT

Thus the Scala program to create an abstract class and calculate area using it is successfully executed
EX NO: 9 PROGRAM TO SEPARATE EVEN AND ODD NUMBERS OF A GIVEN

ARRAY OF INTEGERS

AIM

To write a Scala program to separate even and odd numbers of a given array of integers

a. Append - add at end 

b. Insert – add at particular index 

c. Search 

d. List all string starts with given letter 

PROCEDURE

1. Create the class arraylistexample. Create the object for the arraylist class.

2. Initialise two index variables left = 0 and right = n-1.

3. We have to increment the left index until we see an odd number.

4. We have to decrement the right index until we see an even number.

5. If left < right then swap array[left] and array[right].

6. Display the Result

PROGRAM:

object Scala_Array {

def test(arr: Array[Int]): Array[Int] = {

var left_side = 0

var right_side = arr.length - 1;

while (left_side &lt; right_side) {

while (arr(left_side) % 2 == 0 &amp;&amp; left_side &lt; right_side) left_side += 1;

while (arr(right_side) % 2 == 1 &amp;&amp; left_side &lt; right_side) right_side -= 1;

if (left_side &lt; right_side) {

val temp = arr(left_side);


arr(left_side) = arr(right_side);

arr(right_side) = temp;

left_side += 1;

right_side -= 1;

arr;

def main(args: Array[String]): Unit = {

val nums = Array(20, 12, 23, 17, 7, 8, 10, 2, 1);

println(&quot;\nOriginal Array elements:&quot;)

for (x &lt;- nums) {

print(s&quot;${x}, &quot;)

val result = test(nums);

println(&quot;\nArray, after separating even and odd numbers:&quot;);

for (x &lt;- result) {

print(s&quot;${x}, &quot;)

RESULT

Thus the Scala program to separate even and odd numbers of a given array of integers has been

implemented and executed successfully.


EX NO : 12 PROGRAM FOR STRING HANDLING OPERATION USING SCALA

AIM:

 To Write a scala program for string handling operation

PROCEDURE
PROGRAM

object StringOperations {

   val x: String = "Scala "

   val y: String ="Programming"

   def main(args: Array[String]) {

      println(x.charAt(4))

      println(x.concat(y))

      println(x.toUpperCase())

      println(y.toLowerCase())

      println(y.substring(1,6))

      println(x.trim())

      println(y.replace('o','a'))=

      println(x.compareTo(y))

      println(y.hashCode())

      println(x.indexOf('a'))

      println(y.length())

      println(x.reverse)

      println(x.replaceAll("ca","ac"))

  

   }

}
OUTPUT

RESULT

Thus the Scala program to perform string handling operation has been implemented and

executed successfully.

You might also like