Scala是什么?
Scala 是一门多范式(multi-paradigm)的编程言语,规划初衷是要集成面向对象编程和函数式编程的各种特性。
Scala 运转在Java虚拟机上,并兼容现有的Java程序。
Scala 源代码被编译成Java字节码,所以它可以运转于JVM之上,并可以调用现有的Java类库。
写了一个hello word的例子给大家参考。
object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
Assignment #3
CS 3060 Programming Languages
Dr. Robert Green
Scala
Assignment Setup: Create a new repository on Gitlab.com. The repository MUST be named following the con-vention
“CS3060_[YYYYYY]_A[X]_LASTNAME” where [YYYYYY] is replaced with the current term (SP, FA, SU) and four digit year (e.g. 2017) and [X] is replaced with the assignment number. Assignments that are misnamed will be given 0 credit! Add [email protected] and the TA to your project with Master project access.
Instructions: Complete the tasks below using the current programming language. Your code must consist of a single, driver file that calls the functions that you write for each solution. You may create any additional number of files, classes, functions, etc. but all functions must be called from that file to demonstrate all work that you have completed.
Grading Rubric: 90 points total. Each question in the assignment will be evaluated according to the rubric below. The number of points are listed in the format (5 Point Question)/(10 Point Questions)/(15 Point Question). For instance, if you score a “Generally Correct” on a 5 point question, you will receive 3 points while the same result on a 5 or 10 point question will result in 6 or 9 points, respectively.
• Is your repository named correctly?
– (5/10/15 Points) Perfect in all aspects
– (4/8/12 Points) Mostly perfect. Some minor errors or styling issues
– (3/6/9 Points) Generally correct, but some significant errors and/or styling issues
– (2/4/6 Points) Almost correct, significant issues preset
– (1/2/3 Points) Effort made, but incorrect and poorly styled
– (0 Points) No submission or effort evident
0. (5 points) Function #1: Write a function that prints the string “Hello, world.”
1. (5 Points) Function #2: Write a function that accepts 2 parameters: A string and a substring to find in that string. The function should find the index of substring in string and print that index.
2. (5 Points) Function #3: Write a function that accepts a single parameter – A list/array – and performs 3
actions: 1) Sort the array and print the values, 2) Sort the array in reverse order and print the values, and
3) Prints the value of each array/list item that has a ODD index. The array passed into this function must contain at least 100 randomly generated values. Where appropriate, you should apply as many functional programming techniques (map, filter, etc.) as you find appropriate.
3. (5 Points) Function #4: Generate a list/array of 100 random values. Sort the list using a Selection Sort (See Wikipedia for description of Selection Sort). The selection sort must be implemented by you.
4. (10 Points) Function #5: Implement a function to calculate the Fibonacci Numbers iteratively. Attempt to calculate as many Fibonacci numbers as possible. The Fibonacci Series is defined below with F1 Æ F2 Æ 1 and F0 Æ 0.
Fn Æ Fn¡1 ÅFn¡2
6. (10 Points) Function #6: Implement a function to calculate the Fibonacci series recursively using Guards and Pattern Matching (Day 3). Compare the computation time and lines of code with Function #5.
For this function, you must also create at least 2 helper functions – randomMatrix and printMatrix . These files may be in separate files, classes, etc. and should follow the paradigms of the current language. The randomMatrix will generate and return a matrix filled with random values and printMatrix will print a well-formatted matrix.
8. (10 Points) Function #8: The Hamming distance between two numbers is the number of bits that must be changed to make the representations of the two numbers equal. For instance, the word “Rob” and “Bob” differ by the first letter, so their Hamming distance is 1. Strings like “Rob” and “Robby” differ by 2 charac-ters, so the Hamming distance is 2.
Write a function that accepts one parameter – a filename. This file will contain two strings on each line, with each string being separated by a “ ”. Your function should read each line, calculate the Hamming distance between the two values, and then write the line back to a new file in the format Value1:Value2:HammingDistance . It is up to you to generate a test file for this function. The output file should insert the string _Output into the original filename. If the input file is “HammingData.csv” then the output file would be HammingData_Output.csv .
9. (15 Points) Function #9: Create a csvReader class that is capable of opening, reading, and accessing the data from any given CSV file. The csvReader class should use a csVRow object to store the data from each row in the CSV file. This function should contain code that demonstrates the ability of your class to read, iterate, and display the contents of a CSV file.
10. (15 Points) Task #10: Implement the equivalent of the Class diagram shown in the image below. This function should contain test code that demonstrates that you have fully implemented these structures and that the inheritance demonstrated works flawlessly.
11. (5 Points) Task #11: Include a file named README.md that includes instructions for compiling and run-ning all the solutions to all of your exercises. It would be appreciated if this file includes the exact com-mands used to compile and run your code as well as examples of the output produced by your solutions. As this is a markdown (.md) file, you may use markdown to style your instructions, though this is not required.