1

Hi I am very new to Scala (complete beginner). I have created a package ( I am using sublime text for now)

// TheRoyalty.scala

package royals

class Royalty(name:String, characteristic:String) {

  def title():String = {"Sir " + characteristic + "alot" }

  def fancyTitle():String = {"Sir " + name + " " + characteristic + "alot"}
}

Then compiled that in Shell

scalac TheRoyalty.scala

a new directory with the same name as the package WAS created. I can see the folder and the royals.class in it. Then I create a new script that needs to use a class from the package

// ImportRoyalty.scala

import royals.Royalty

val royal = new Royalty("Henry", "Laughs")
val title = royal.title()
assert("Sir Laughsalot" == title,
  "Expected Sir Laughsalot, Got " + title)

When I try to run the scrip from the shell the following error occurs:

PS C:\Users\olyan_000\Desktop\BBK\SDP_2016\SCALA> scala ImportRoyalty.scala

C:\Users\olyan_000\Desktop\BBK\SDP_2016\SCALA\ImportRoyalty.scala:2: error: not found: value royals import royals.Royalty ^ C:\Users\olyan_000\Desktop\BBK\SDP_2016\SCALA\ImportRoyalty.scala:4: error: not found: type Royalty val royal = new Royalty("Henry", "Laughs") ^ two errors found PS C:\Users\olyan_000\Desktop\BBK\SDP_2016\SCALA>

I don't understand why and I am stuck.Can you please help?

O.Nicholls
  • 11
  • 2
  • Possible duplicate for: http://stackoverflow.com/questions/7383436/load-scala-file-into-interpreter-to-use-functions Check this answer with `:load ` command please. – Nikita Jan 17 '16 at 16:58

0 Answers0