Sunday, July 1, 2018

How to create a method in scala


In this tutorial ill be showing you how to create a method using Scala.

The requirements are:
-Eclipse
-Latest Version of IDE

1) Once you have to install Eclipse in your machine, you ill then required to download "Scala IDE for eclipse" and "Scala worksheet".

To get this you need to open: Eclipse > Help > Install New Software as shown in the picture below
2) Afterward, a popup windows will open as shown below:
you then need to add this URL in : http://download.scala-ide.org/sdk/lithium/e47/scala212/stable/site
once the URL, has been added you need to checklist "Scala IDE for eclipse" and "Scala Worksheet" and click on next and finish.
3)When the scala has been added, the user need to create a new scala project.
once you click on a new project it will show you a popup and ask the user to name the project.
it will then create 3 items inside the project, right click on "src" and click on New > Scala WorkSheet and it will ask you to give a name for your project.

4) When a blank worksheet has been created, the user must create an object first.
in this example i created an object class and the attributes that i fill in are "carType", "cost" and "color".
i then created a method called greater, which take a parameter (c2) and define the type (which is a type car) and it return as a boolean and compares the cost of the first value to the second value "c2.cost"

I then created 2 objects which is "c1" and "c2" and gives a different values for each
After creating the objects, i would like to compare the prices between them.
i.e 100000 is greater than 3000000 shows that the result gave a false answer.

No comments:

Post a Comment