Computer Science 210
Data Structures

Fall 2018, Siena College

Problem Set 2
Due: 4:00 PM, Monday, October 1, 2018

You may work alone or with a partner on this assignment. However, in order to make sure you learn the material and are well-prepared for the exams, you should work through non-coding problems on your own before discussing them with your partner, should you choose to work with someone. Also, be sure every programming task is a team effort. In particular, the "you do these and I'll do these" approach is sure to leave you unprepared for the exams.

All GitHub repositories must be created with all group members having write access and all group member names specified in the README.md file by 4:00 PM, Monday, September 24, 2018. This applies to those who choose to work alone as well!

There is a significant amount of work to be done here, and you are sure to have questions. It will be difficult if not impossible to complete the assignment if you wait until the last minute. A slow and steady approach will be much more effective.

Getting Set Up

You will receive an email with the link to follow to set up your GitHub repository for this problem set (ps2-yourgitname). One member of the group should follow the link to set up the repository on GitHub, then that person should email the instructor with the other group members' GitHub usernames so they can be granted access. This will allow all members of the group to clone the repository and commit and push changes to the origin on GitHub.

More Matrix2D Enhancements

Practice Program: Your task is to add the functionality listed below to the Matrix2D example and write code to test it in the main method there.

The functionality you are to add:

You can expect to have to write a method similar to one of these or the max method you wrote in lab for an upcoming quiz or exam.

Methods with ArrayLists

Practice Program: Create a class ArrayListTests that includes the methods below and a main method to test them thoroughly.

The above are good examples of the kind of methods you might see to write (on paper) for the first exam.

Working with Matrix2D and ArrayLists

Practice Program: In the class Matrix2DList, complete the main method so that it creates an arbitrarily-long list of matrices, then reports information about the list of matrices, including their sum and product. Specifics follow. (17 points)

Your program should behave as follows:

  1. Prompt for and read the matrix size to be used for all of the matrices. (Done by starter code.)
  2. Prompt for and read the range of values to be used to fill the first matrix with random values. (Done by starter code.)
  3. Create the first matrix and add it to the matrix list (which should be an ArrayList). (Starter code creates the Matrix2D object but does not add it to the list.)
  4. Ask repeatedly if more matrices should be created, and as long as there should be more, prompt again for the next range of values, create a matrix with values in that range, and add it to the matrix list. (Starter code prompts and creates the Matrix2D objects but does not add them to the list.)
  5. Once no more matrices are requested, print the following information, using only the ArrayList in which you have been storing the Matrix2D objects: (The starter code does none of this.)

A sample run of the program follows:

What size should the matrices be? 4
Enter upper and lower bounds for values of the next matrix: 0 10
More matrices?  (yes or no) yes
Enter upper and lower bounds for values of the next matrix: -5 5
More matrices?  (yes or no) yes
Enter upper and lower bounds for values of the next matrix: 100 1000
More matrices?  (yes or no) no
You created 3 matrices.
Matrix 0:
3.1446718232384363 8.903162109361647 6.572639506694643 9.411167855838547
3.9576692338913553 3.036466469570256 2.882164051987268 7.878830142793147
0.37334414421281603 1.848322408778147 9.00459393873155 3.049493102231743
1.5407520792899199 9.46042381998735 3.540809447693386 9.788365191490355

Matrix 1:
-4.559865880159107 0.6291806500763286 1.0509700801099298 0.8178647751293671
3.9108069694191645 -3.3177025187941567 1.8256956973298912 3.1095583829430744
3.8029647799578044 -0.7924572257049824 2.394953330369538 -1.5242502832680929
1.5657404338568481 -1.3043698146796956 -4.379616646485256 -0.6519814183197914

Matrix 2:
656.8003249089386 734.8743060987506 929.6682570160574 586.4958117693284
141.76300614174164 634.278617280476 280.3411001673913 696.8632576871072
468.28855483559204 531.6301318604899 881.6724838298471 740.6011613187118
138.39443915176548 909.9372820343589 641.7058647921483 852.9217247520166

Sum of your matrices:
655.3851308520179 744.4066488581885 937.291866602862 596.7248444002963
149.63148234505215 633.9973812312521 285.04895991670844 707.8516462128434
472.46486375976264 532.685997043563 893.0720310989482 742.1264041376754
141.50093166491226 918.0933360396665 640.8670575933564 862.0581085251872

Product of your matrices:
32341.55753282696 25363.66446740007 47181.03848455002 11570.231300415671
445.4436419039385 -6843.498976159701 -3488.095298326223 -14565.559997021226
31117.243150853817 19522.023465712155 41003.513058813616 14901.525177420528
27434.24649173172 22970.548236054085 40201.078541088675 7056.7357512357885

Reverse product of your matrices:
1875.170476793529 40667.697168365936 37151.878749240015 28157.029744590596
1557.8464545383433 35412.862903365276 11770.702704385545 21311.188337583473
2057.015525273084 32751.784682379333 23977.3616193639 20306.318428118004
5084.92322843422 58456.994888280315 32394.971073511217 39806.82682147663

A Memory Diagram with ArrayLists

For a little more practice making memory diagrams, we will use the CourseGrades example.

Before making a diagram, it is important to make sure you understand which parts of the program are responsible for which computation and for storing the data. There are three major sections of the program:

  1. The main method in CourseGrades is static, meaning it has no access to the instance variable of the class. Therefore, it created an instance of CourseGrades, storing it in its local variable cg. main is then responsible for creating prompting the user for each command, parsing that command, and, in the case of a valid command, calling a method of its instance of CourseGrades (cg) that can then access the instance variable to perform the requested action.
  2. The non-static methods of CourseGrades are responsible for the access and modifications to the studentList instance variable. In most cases, it looks up an existing or creates a new instance of StudentGrades, then calls one or more methods of the StudentGrades object that represents the information about the student being considered.
  3. The StudentGrades class, which has instance variables and methods responsible for maintaining the information about one student.

Question 1: Draw a memory diagram of the variables in existence in the situation described below. (25 points)

Suppose the following commands are entered:

add 83.5 linus
add 95 snoopy
add 91 linus

and the program is currently executing the line

    cg.add(name, grade);

in main, the (second) line

    sg.addGrade(grade);

in the add method of CourseGrades, and has just finished the line

    grades.add(grade);

in the addGrade method of StudentGrades for the addition of the second "linus" grade.

Note: for the purposes of this diagram, we will represent an ArrayList with its internal array and its size inside a box. So an ArrayList<Integer> named a declared in main with 3 values, 8, 2, and 4, would look like this:

Submitting

Your diagram may be submitted in hard copy or you may include it in electronic form in your repository.

Your submission requires that all required code deliverables are committed and pushed to the master for your repository's origin on GitHub. That's it! If you see everything you intend to submit when you visit your repository's page on GitHub, you're set.

Grading

This assignment is worth 80 points, which are distributed as follows:

> FeatureValueScore
Matrix2D scale method 5
Matrix2D multiply method 10
Matrix2D tests in main 5
ArrayList largest value method 5
ArrayList largest value tests 2
ArrayList multiples only method 6
ArrayList multiples only tests 2
Matrix2DList create and populate the list 5
Matrix2DList report count and print matrices 2
Matrix2DList compute and print sum and products 10
Question 1 memory diagram 25
Git commit frequency and message quality 3
Total 80