Problem Set GitHub Repository link: https://github.com/CSE-116/ProblemSet-0
To get started on this problem set, clone the starter code from the repository linked above into a new IntelliJ project.
Your code for this problem set will go in the problem.ProblemSet0 class.
To submit your project, run problem.Zipper, which will create a zip file containing the problem
set, and submit it to Autolab. Autolab will return an error if you don't at least create all 10 methods. You write
the header for all methods and stub them out (return any valid value) before submitting.
This video shows how to get started with cloning repositories, and gives an overview of the coding requirements for both the Problem Set and Game Features. https://www.youtube.com/watch?v=pvs_XXGv9lE
This problem set does not require you to write any tests. tests.TestProblemSet0 contains tests for some of the methods that you can use to verify the correctness of your code. Note that not all methods have tests written for them. You are encouraged to follow the structure of these tests to write your own tests for the remaining methods. This is not required, but might save you time since you wouldn't have to submit to Atuolab to see if your code is correct.
You can run these tests just like a Java file with a main method (Right-click the file and choose run) and you will see feedback about which test cases you've passed/failed.
Some of these tests may have been commented out so that the problem set will compile. You can uncomment the tests as you get to these methods. You can highlight multiple lines and press control+/ (command+/ on mac) to quickly comment multiple lines in/out
For this problem set you will implement following methods, as described below. All of these methods will be public and static, and all of them should be implemented in the problem.ProblemSet0 class. You can, and should, run your code and verify that it has the proper behavior on a variety of inputs.
Some of the method headers have been given to you, but are stubbed out with incomplete implementations. You must replace this with the correct implementation. For the remaining methods, you must write them from scratch.
This problem set consists of 10 methods worth 5 points each. Note that the problems are not sorted in order of difficulty. You may want to jump around and start with the ones that you find the easiest.
sumOfDigits
sumOfDigits method will take an int as a parameter and returns the sum of the digits of the input as an int
average
ArrayList of Doubles as a parameter and returns
the average of the values in the ArrayList as a
double
ArrayList is empty, the method should return
0.0
longestStringIndex
longestStringIndex method has one parameter which is an ArrayList of
Strings, and returns the index in that ArrayList of the String with
the greatest length
ArrayList is empty, this method should return -1, to signify that there
were no valid indices
Strings which share the greatest length, any of their indices can be
returned and will be accepted by the tests
countElements
countElements method will take a HashMap of Strings to
ArrayList of Integers as a parameter and returns the total number of Integers
across all the ArrayLists.
bestKey
bestKey method will take a HashMap of Strings to
Integers as a parameter and returns the key which maps to the largest
Integer
HashMap is empty, the method should return the empty StringwordCount
String as a parameter, representing the file location of the csv
file to be read. This method will return an int representing the total number of "words" in
that file, where a word is considered to be any value within that csv file that is separated by a comma or
a newline
0name,age,city Alice,30,London John,25,New York
1,2,3,4 a a,b,c
sumOfLines
String as a parameter, representing the file location of the csv
file to be read. This method will return an ArrayList of Integers, where each
element represents the sum of the values in that line of the file
Integer.ArrayList1,2,3,4,5
0 -14,2 8,16,0 1,5
factors
factors method takes an int as a parameter and returns an ArrayList of Integers
containing all the factors of the input. The values in the output may be in any order.
isPrime
isPrime method takes an int as a parameter and returns a boolean that is true if the input is a prime number, and false otherwise
primeFactorization
primeFactorization method takes an int as a parameter and returns an ArrayList of Integers
containing the prime factorization of the input. The values in the output may be in any order.