Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // task 01
- package com {
- package horstman {
- object Utils1 {
- def percentOf(value: Double, rate: Double) = value * rate / 100
- }
- package impatient {
- class Employee {
- def giveRaise(rate: Double) {
- var salary: Double = Utils1.percentOf(salary: Double, rate: Double)
- }
- }
- }
- }
- }
- package com.horstman.impatient {
- class Employee {
- def giveRaise(rate: Double) {
- var salary: Double = com.horstman.Utils1.percentOf(salary: Double, rate: Double)
- }
- }
- }
- //task 02
- package com {
- package horstmann {
- object Sum {
- def sumOneTwo() = {
- 2
- }
- var i = com.horstmann.Sum.sumOneTwo()
- }
- }
- }
- package upcom {
- package com {
- package horstmann {
- object Sum {
- def sumOneTwo() = {
- -3
- }
- }
- }
- }
- }
- package upcom {
- object Result extends App {
- var i = com.horstmann.Sum.sumOneTwo()
- print(i)
- }
- }
- // task 03
- package object Random {
- var next = 1
- def nextInt(): Int = {
- next * 1664525 + 1013904223 * math.pow(2, 32).toInt
- }
- def nextDouble: Double = next
- def setSeed(seed: Int): Unit = {
- next = seed
- }
- }
- // task 06
- import java.util.{HashMap => JavaMap}
- import scala.collection.mutable.{HashMap => ScalaMap}
- object Hashmaps {
- val jMap = new JavaMap[String, Int]()
- jMap.put("As", 1)
- jMap.put("Bs", 2)
- jMap.put("Cs", 3)
- jMap.put("Ds", 4)
- val sMap = new ScalaMap[String, Int]
- val iterator = jMap.entrySet().iterator()
- while (iterator.hasNext){
- val value = iterator.next()
- sMap += (value.getKey -> value.getValue)
- }
- sMap
- }
- // task 07
- object Hashmaps {
- import java.util.{HashMap => JavaMap}
- import scala.collection.mutable.{HashMap => ScalaMap}
- val jMap = new JavaMap[String, Int]()
- jMap.put("As", 1)
- jMap.put("Bs", 2)
- jMap.put("Cs", 3)
- jMap.put("Ds", 4)
- val sMap = new ScalaMap[String, Int]
- val iterator = jMap.entrySet().iterator()
- while (iterator.hasNext) {
- val value = iterator.next()
- sMap += (value.getKey -> value.getValue)
- }
- sMap
- }
- // task 09
- import java.lang.System
- import scala.io.StdIn
- object Welcome{
- val userName = System.getProperty("user.name")
- println("Pass for " + userName + "_:")
- val password = StdIn.readLine()
- if (password.equals("pass")) print("Hello" + userName)
- else sys.error("Invalid password")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement