-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
247 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
Items: Books/medicines | ||
Compiute the receipt | ||
Taxes | ||
SalesTax: round down | ||
ImportDuty: only for imported items, round up | ||
|
||
SalesTax ImportDuty | ||
Books 10.8 9.4 | ||
Medicines 2.7 10.1 | ||
|
||
Billing | ||
Book1: 120.1 | ||
Book2: 1004, imported | ||
Book3: 87.8 | ||
Medicine1: 503.3 | ||
Medicine2: 19.3 | ||
|
||
Hints: | ||
Use transform method | ||
Use ceil and floor on double | ||
use sum on double sequences | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
val x = 10 | ||
|
||
def While(cond: => Boolean)(body: () => Unit): Unit = | ||
if(cond) { | ||
body | ||
While(cond)(body) | ||
} | ||
|
||
var y = 0 | ||
|
||
While(y < 10){ | ||
println(y) | ||
y = y + 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
|
||
def add(a: Int, b: Int) = a + b | ||
|
||
def adder2(b: Int) = add(2, b) | ||
def adder3(b: Int) = add(3, b) | ||
|
||
adder2(10) | ||
adder3(10) | ||
|
||
def add1(a: Int)(b: Int) = a + b | ||
val curr = add1 _ | ||
|
||
val cAdder2 = curr(2) | ||
val cAdder3 = add1(3) _ | ||
|
||
def applier(x: Int, adder: Int => Int) = | ||
adder(x) | ||
|
||
cAdder2(10) | ||
cAdder3(10) | ||
|
||
applier(10, add1(100)) | ||
applier(10, add1(101)) | ||
|
||
applier(10, x => add(100, x)) | ||
applier(10, x => add(101, x)) | ||
applier(10, x => add(101, x)) | ||
|
||
def dd(x: Int) = add(101, x) | ||
|
||
applier(10, dd) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//abstract class CanDrink1(name: String) { | ||
// def apply(age: Int): Boolean | ||
// | ||
// def isWise(age: Int) = apply(age) && age > 43 | ||
//} | ||
// | ||
//class Person1(name: String) extends CanDrink1(name + "asasd") { | ||
// def apply(age: Int) = true | ||
//} | ||
//new Person1("blah") | ||
|
||
trait CanDrink { | ||
|
||
def x: Int | ||
|
||
protected def name: String | ||
|
||
def apply(age: Int): Boolean | ||
|
||
def isWise(age: Int) = apply(age) && age > 43 | ||
|
||
} | ||
|
||
class Person1(val name: String) extends CanDrink { | ||
val x: Int = 101 | ||
def apply(age: Int) = true | ||
} | ||
|
||
new Person1("blah").name | ||
|
||
|
||
class Nitin(name: String) { | ||
private val age = name.length | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
trait A { | ||
def canDrink(age: Int): Boolean = true | ||
} | ||
|
||
trait CanDrink extends A{ | ||
// val x = 100 | ||
override def canDrink(age: Int) = | ||
age > 19 && super.canDrink(age) | ||
} | ||
trait CanRun extends A{ | ||
override def canDrink(age: Int) = age > 19 | ||
// val y = 200 | ||
def canRun(age: Int) = age < 90 | ||
} | ||
class Person extends CanDrink with CanRun | ||
class Person1 extends CanRun with CanDrink | ||
|
||
val p = new Person | ||
val p1 = new CanDrink with CanRun | ||
|
||
//p.x | ||
//p.y | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
trait A { | ||
def m: Int | ||
def n = m.toString | ||
} | ||
|
||
trait B { | ||
def n: String | ||
def m = 10 | ||
} | ||
|
||
|
||
|
||
class C extends A with B | ||
|
||
val ab: A with B = new A with B | ||
val ba: A with B = new B with A | ||
|
||
val c = new C | ||
|
||
c.m | ||
c.n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
trait A { self: B => | ||
def x = 10 | ||
def b = a + 2 | ||
} | ||
|
||
trait B { self: A => | ||
def y = x + 100 | ||
def a = 1 | ||
} | ||
|
||
new A with B | ||
new A | ||
new B | ||
|
||
class C extends A with B | ||
|
||
val c = new C | ||
c.a | ||
c.b | ||
c.x | ||
c.y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
object A { | ||
class Person private (var age: Int, val isFemale: Boolean) { | ||
// def this(age: Int) = this(age, false) | ||
def m = Person.b + 2 | ||
private def n = "n" | ||
} | ||
object Person { | ||
private val b = 10 | ||
def make(age: Int) = { | ||
val p = new Person(age, false) | ||
p.n | ||
p | ||
} | ||
} | ||
val p3 = Person.make(333) | ||
p3: p3.type | ||
|
||
val p = new Person(33, true) | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
case class Address(line1: String, pin: Int) | ||
case class Person(age: Int, isFemale: Boolean, add: Address) { | ||
def incrementedPin = copy(add = add.copy(pin = add.pin + 1)) | ||
} | ||
|
||
val p = Person(23, true, Address("baner", 21)) | ||
|
||
def increaseAge(p: Person) = | ||
p.copy(age = p.age +1) | ||
def increasePin(p: Person) = p.incrementedPin | ||
|
||
def compare(p1: Person, p2: Person) = p1 == p2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
trait CanDrink { | ||
def apply(age: Int): Boolean | ||
|
||
final def isWise(age: Int) = apply(age) && age > 43 | ||
} | ||
|
||
class X extends CanDrink { | ||
def apply(age: Int) = true | ||
|
||
override def isWise(age: Int) = { | ||
if(age > 100) true else super.isWise(age) | ||
} | ||
} | ||
|
||
new CanDrink { | ||
def apply(age: Int) = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
|
||
case class Person(name: String, age: Int) | ||
|
||
val p1 = new Person("mushtaq", 101) | ||
val p2 = new Person("ashish", 10) | ||
val p3 = new Person("ashish", 10) | ||
|
||
p1 == p2 | ||
|
||
p2 == p3 |