Day 3 Scriptgroovy
Day 3 Scriptgroovy
def m1() {
println "I am in m1 of x"
}
def m2() {
println "In m2 of x"
}
}
class y extends x{
def m1() {
println "I am in m1 of y"
super.m1()
}
}
y1=new y()
y1.m2()
y1.m1()
/*
class x {
def x() {
println "I am in constr of x"
}
def m1() {
println "I am in m1 of x"
}
def m1(a) {
println "I am in m1 of x with one arg"
}
def m1(a,b) {
println "I am in m1 of x with two arg"
}
}
x1=new x()
x1.m1()
x1.m1(10,20)
class x {
def m1()
{
println "I am in m1 of x"
}
}
class y extends x{
def m2()
{
println "I am in m2 of y"
}
}
//x1=new x()
//x1.m1()
y1=new y()
y1.m2()
y1.m1()
class Cust {
//customer application
def final cbname="SBI" //static variables
def cname
def caddr
def caccno
def cbal
def Cust(cname, caddr, caccno, cbal)
{
this.cname=cname
this.caddr=caddr //instance variables
this.caccno=caccno
this.cbal=cbal
}
def deposit(damt)
{
cbal=cbal+damt
}
def withdraw(wamt)
{
if (wamt<cbal)
{
cbal=cbal-wamt
}
else
{
println "Insufficient bal"
}
}
def balenq()
{
println cbal
}
def display()
{
println cname
println caddr
println caccno
println cbal
}
}
c1=new Cust("John","Hyd",1001,1000)
c1.balenq()
c1.deposit(2000)
c1.balenq()
c1.withdraw(5000)
c1.withdraw(1000)
c1.balenq()
c2=new Cust("siri","pune",1002,2000)
c2.balenq()
c2.display()
class x {
def x() {
println "I am in constr of x"
}
def f1() {
println "I am in f1 of x"
}
}
x1=new x()
class x {
def f1() {
println "I am in f1 of x"
}
def f2(a,b) {
println(a)
println(b)
def sum=a+b
println "sum is $sum"
}
}
x1=new x()
x1.f1()
x1.f2(10,20)
class Example {
def hello()
{
println "I am in hello method in the Example class"
}
}
x1=new Example()
x1.hello()
// GroovyScript.groovy
//Importing Java Class in Groovy
//java program need to compile first
import JavaClass
import GroovyModule
def javaInstance = new JavaClass()
javaInstance.printMessage()
def groovyInstance = new GroovyModule()
groovyInstance.greet()
import arithmatic
s1=new arithmatic().sum(10,20)
println s1
s2=new arithmatic().sub(100,20)
println s2
s3=new arithmatic().mul(10,20)
println s3
s4=new arithmatic().div(10,2)
println s4
def sum1(x,y)
{
total=x+y
return total
}
println sum1(10,20)
k=sum1(11,22)
println k
def k=200
i="groovy"
def f1()
{
println "I am in f1"
a=10
println a
def x=100
println x
println i
//println k
}
def f2()
{
println "I am in f2"
println a
//println x
}
f1()
f2()
println "outside"
println a
println k
def f1(a,b)
{
println "sum of $a and $b is: ${a + b}"
println "sub of $a and $b is: ${a - b}"
println "mul of $a and $b is: ${a * b}"
println "#"*30
}
f1(10,20)
f1(10,2)
f1(10,3)
f1(10,4)
f1(10,5)
a=10
b=20
println "sum of $a and $b is: ${a + b}"
println "sub of $a and $b is: ${a - b}"
println "mul of $a and $b is: ${a * b}"
println "#"*30
a=10
b=2
println "sum of $a and $b is: ${a + b}"
println "sub of $a and $b is: ${a - b}"
println "mul of $a and $b is: ${a * b}"
println "#"*30
a=10
b=3
println "sum of $a and $b is: ${a + b}"
println "sub of $a and $b is: ${a - b}"
println "mul of $a and $b is: ${a * b}"
println "#"*30
a=10
b=4
println "sum of $a and $b is: ${a + b}"
println "sub of $a and $b is: ${a - b}"
println "mul of $a and $b is: ${a * b}"
println "#"*30
a=10
b=5
println "sum of $a and $b is: ${a + b}"
println "sub of $a and $b is: ${a - b}"
println "mul of $a and $b is: ${a * b}"
println "#"*30
def f1(a,b)
{
println a
println b
}
f1(10,20)
def f1()
{
println "Hello functions"
println "welcome to functions"
}
f1()
f1()
f1()
f1()
f1()
a=10
def k=20
println a
println k
file1=new File('test100.txt')
for ( i in file1.readLines())
{
//if (i =~ /ab+c/)
//if (i =~ /\w+\s\w+\s\w+/)
//if (i =~ /[6-9][0-9]{9}/)
//if (i =~ /^groovy/)
if (i =~ /groovy$/)
{
println i
}
}
file1=new File('test1.txt')
for ( i in file1.readLines())
{
if (i =~ /groovy/)
{
println i
}
}
file1=new File('test100.txt')
//file1.write("groovy\npython\n")
file1.append("groovy\npython\n")
file1=new File('test1.txt')
for ( i in file1.readLines())
{
println i
}
*/