Sequential Execution and Scripts 9 10 2010 Opening Discussion Let s talk about the interclass problem What answer did you get How did you get it Minute Essays Are there situations where people use other base systems How can you accept other bases as input and convert it to something else as output Difference between val and var You can use chmod and chown to change permissions when logged in remotely When are we going to start programming Variables It is very common to want to represent values with names A variable is a name that we use to represent a value In Scala we can declare variables using val or var val name Type expression var name Type expression A val can t change it s value a var can The colon and type generally optional Tuples Another type in Scala is the Tuple type A tuple has comma separated values in parentheses They give us a way to handle a fixed set of associated values Assignment into a tuple does pattern matching Scripts We have spent most of our time in the REPL entering one statement at a time When we want to do things repeatedly it is nice to put the commands in a file called a script We can use vi to write a script and put Scala commands in the file We can run it by specifying the file name after the command scala Alternately we can load it into the REPL Sequential Execution When you put commands into a script they are normally executed one after the other from top to bottom This is what we call sequential execution and it is the default way things happen Order can be very significant for the instructions in a program Standard Input Scala provides a whole set of functions you can call to read from standard input readInt readDouble readLine And many more This can make your scripts far more useful as they can be used with different values each time you run them Some Problems We are still a little limited in that we can only do simple math and formatting but let s try to do some things with that in scripts We ll start with formatting money Calculating hourly wages Taking averages of grades Suggestions Minute Essay What questions do you have about things On Monday I will call on two students to actually present their interclass problem solutions Interclass Problem Write a script that you enter a four digit course number into and it tells you how many hours the course is
View Full Document