Computer Science 210
Data Structures

Fall 2016, Siena College

Lab 4: ArrayList Practice
Due: 10:00 AM, Wednesday, October 5, 2016

This week's lab is a chance to practice a bit more using custom classes and the ArrayList ADT. While it is due at the usual time, hopefully you can finish up sooner to prepare for the exam.

You may work alone or with a partner on this lab. Only one submission per group is needed.

Getting Set Up

To get your BlueJ environment set up for this week's lab assignment, start BlueJ and choose "New Project" from the "Project" menu. Navigate to your folder for this course and choose the name "Lab4" (no spaces) for the project.

Create a document where you will record your answers to the lab questions. If you use plain text, call it "lab4.txt". If it's a Word document, you can call it whatever you'd like, but when you submit, be sure you convert it to a PDF document "lab4.pdf" before you submit it.

More Matrix2D

This problem builds on the Matrix2D program from last week. Start with your version of Matrix2D.java that includes the matrix-matrix multiply method.

Practice Program: In a new class called Matrix2DList, write a main method that creates an arbitrarily-long list of matrices, then reports their sum and product. Specifics below. (20 points)

Your program should behave as follows:

  1. Prompt for and read the matrix size to be used for all of the matrices.
  2. Prompt for and read the range of values to be used to fill the first matrix with random values.
  3. Create the first matrix and add it to the matrix list (which should be an ArrayList).
  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.
  5. Once no more matrices are requested, print the number of matrices that have been created, print each matrix, then compute and print the sum of the matrices and the product of the matrices.

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 200
More matrices?  (yes or no) no
You created 3 matrices.
Matrix 0:
9.68220530639116 7.345769488480678 1.7412544053873813 2.3438316061712605
3.1944624268586654 3.9513050924461313 4.267474531699351 2.583640677971447
4.641348346843794 3.5690041627188753 3.3537004228656233 6.340187059095067
2.098098670498576 7.140456953926631 7.855035765375354 2.5806587268338586

Matrix 1:
4.806713489353562 0.4135288039878944 1.2768161447453794 -4.068342594706581
3.6280471321371586 -2.5156720232308336 4.048496011548281 4.266635696913379
-3.039326003927366 1.1870583652796984 -4.750758409032128 0.5086397570974199
2.3554889820951885 -0.6787271394749981 2.6905416351814733 2.3593801046651217

Matrix 2:
149.83228384235943 130.59594399972167 158.3705270054091 169.4955788825903
110.50901258217934 185.2866551484843 149.6145308945793 120.91463311180807
180.23028479845289 177.20036526697353 151.46037517431358 174.51331981681983
125.26086320907847 112.274872082545 158.7914846584583 172.05826577250718

Sum of your matrices:
164.32120263810415 138.35524229219024 161.38859755554185 167.771067894055
117.33152214117516 186.7222882176996 157.93050143782693 127.7649094866929
181.8323071413693 181.95642779497211 150.06331718814707 181.36214663301232
129.71445086167222 118.73660189699663 169.33706205901512 176.99830460400617

Product of your matrices:
16482.548286913046 13922.983840001521 15352.500605703277 17474.653424398755
5567.009861117915 4553.491999143645 5766.601007853109 6489.223728863248
10682.275123478916 9126.782807692354 10552.788438086425 11877.89036959422
5902.680161976161 4421.1764573063265 6724.206610818697 7652.617790407841

Programming Assignment: Enhancing the CourseGrades Example

Start by making your own copy of the CourseGrades example, and read through the existing code to make sure you understand how it all works.

It is very 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.

A memory diagram of the variables in existience after the following commands are entered:

add 100 carrie
add 87 barry
add 91.5 carrie

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.

Do not start making modifications until you understand the breakdown and memory diagram above.

You will be making several enhancements to this program:

Submitting

Before 10:00 AM, Wednesday, October 5, 2016, submit your lab for grading. There are two things to do to complete the submission: (i) Copy your file with the answers to the lab questions into your project directory. Be sure to use the correct file name. If you prepared your answers in Word, export to a PDF file and submit that. and (ii) upload a copy of your lab (a .7z or .zip file containing your project directory) to Blackboard under "Lab4". Don't forget to check your programming assignment programs for compliance with the Style Guide for CSIS 210 Programs

Grading

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

> FeatureValueScore
Matrix2DList practice program 20
CourseGrades average command 5
CourseGrades delete command 5
CourseGrades save command 5
CourseGrades load command 3
CourseGrades merge command 3
CourseGrades stats command (basic) 8
CourseGrades stats command handles ties 3
CourseGrades updates to help command 2
CourseGrades comments 5
CourseGrades naming conventions 2
CourseGrades code organization 2
CourseGrades formatting 1
Lab Question 1 4
Lab Question 2 2
Total 70