Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. // task 01
  2.  
  3. package com {
  4. package horstman {
  5.  
  6. object Utils1 {
  7. def percentOf(value: Double, rate: Double) = value * rate / 100
  8. }
  9. package impatient {
  10.  
  11. class Employee {
  12. def giveRaise(rate: Double) {
  13. var salary: Double = Utils1.percentOf(salary: Double, rate: Double)
  14. }
  15.  
  16. }
  17.  
  18. }
  19.  
  20. }
  21.  
  22. }
  23.  
  24.  
  25. package com.horstman.impatient {
  26.  
  27. class Employee {
  28. def giveRaise(rate: Double) {
  29. var salary: Double = com.horstman.Utils1.percentOf(salary: Double, rate: Double)
  30. }
  31. }
  32.  
  33. }
  34.  
  35. //task 02
  36.  
  37. package com {
  38. package horstmann {
  39.  
  40. object Sum {
  41. def sumOneTwo() = {
  42. 2
  43. }
  44.  
  45. var i = com.horstmann.Sum.sumOneTwo()
  46. }
  47.  
  48. }
  49.  
  50. }
  51.  
  52. package upcom {
  53. package com {
  54. package horstmann {
  55.  
  56. object Sum {
  57. def sumOneTwo() = {
  58. -3
  59. }
  60. }
  61.  
  62. }
  63.  
  64. }
  65.  
  66. }
  67.  
  68. package upcom {
  69.  
  70. object Result extends App {
  71. var i = com.horstmann.Sum.sumOneTwo()
  72. print(i)
  73. }
  74.  
  75. }
  76.  
  77. // task 03
  78.  
  79. package object Random {
  80. var next = 1
  81.  
  82. def nextInt(): Int = {
  83. next * 1664525 + 1013904223 * math.pow(2, 32).toInt
  84. }
  85.  
  86. def nextDouble: Double = next
  87.  
  88. def setSeed(seed: Int): Unit = {
  89. next = seed
  90. }
  91. }
  92.  
  93. // task 06
  94.  
  95. import java.util.{HashMap => JavaMap}
  96. import scala.collection.mutable.{HashMap => ScalaMap}
  97.  
  98. object Hashmaps {
  99. val jMap = new JavaMap[String, Int]()
  100. jMap.put("As", 1)
  101. jMap.put("Bs", 2)
  102. jMap.put("Cs", 3)
  103. jMap.put("Ds", 4)
  104. val sMap = new ScalaMap[String, Int]
  105. val iterator = jMap.entrySet().iterator()
  106. while (iterator.hasNext){
  107. val value = iterator.next()
  108. sMap += (value.getKey -> value.getValue)
  109.  
  110. }
  111. sMap
  112. }
  113.  
  114. // task 07
  115.  
  116. object Hashmaps {
  117.  
  118. import java.util.{HashMap => JavaMap}
  119. import scala.collection.mutable.{HashMap => ScalaMap}
  120.  
  121. val jMap = new JavaMap[String, Int]()
  122. jMap.put("As", 1)
  123. jMap.put("Bs", 2)
  124. jMap.put("Cs", 3)
  125. jMap.put("Ds", 4)
  126. val sMap = new ScalaMap[String, Int]
  127. val iterator = jMap.entrySet().iterator()
  128. while (iterator.hasNext) {
  129. val value = iterator.next()
  130. sMap += (value.getKey -> value.getValue)
  131.  
  132. }
  133. sMap
  134. }
  135. // task 09
  136.  
  137. import java.lang.System
  138.  
  139. import scala.io.StdIn
  140.  
  141. object Welcome{
  142. val userName = System.getProperty("user.name")
  143. println("Pass for " + userName + "_:")
  144. val password = StdIn.readLine()
  145. if (password.equals("pass")) print("Hello" + userName)
  146. else sys.error("Invalid password")
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement