OOPS Lab Answers
OOPS Lab Answers
AIM
PROCEDURE
Consumer no., consumer name, previous month reading, current month reading, type of EB
If the type of the EB connection is domestic, calculate the amount to be paid as follows:
If the type of the EB connection is commercial, calculate the amount to be paid as follows:
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")
amount=totalunits*1;
amount=totalunits*2.50
amount=totalunits*4.00
else
amount=totalunits*6.00
else if(connection=="Commercial")
amount=totalunits*2;
amount=totalunits*4.50
if (totalunits>200 && totalunits<=500)
amount=totalunits*6.00
else
amount=totalunits*7.00
def Invoke(){
println("Bill: "+amount)
object HelloWorld {
a.Invoke()
}
OUTPUT
APPLICATIONS :
(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.
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.
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:
Thus the Scala application to generate pay slip for different category of employees was
AIM
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
PROGRAM:
var a=10
var b=20
def printarea()
def printarea()
println("Area of Rectancle"+(a*b))
def printarea()
println("Area of Rectancle"+(a*b)/2)
println("Area of Rectancle"+(3.14*a*a))
object Main{
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
c. Search
PROCEDURE
1. Create the class arraylistexample. Create the object for the arraylist class.
PROGRAM:
object Scala_Array {
var left_side = 0
arr(right_side) = temp;
left_side += 1;
right_side -= 1;
arr;
print(s"${x}, ")
print(s"${x}, ")
RESULT
Thus the Scala program to separate even and odd numbers of a given array of integers has been
AIM:
PROCEDURE
PROGRAM
object StringOperations {
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.