Introduction to Software Development
GWU Computer Science
By the end of this module, you will:
If you do not have your Codio course ready, use any text editor or simple IDE. Some possibilities are:
Before we move forward, let's catch up (complete any remaining work from the previous module)
In this case, make sure we've got:
There are two common ways of interpreting and visualizing a 2D array:
String[][] A = { {"(0,0)", "(0,1)", "(0,2)", "(0,3)", "(0,4)"}, {"(1,0)", "(1,1)", "(1,2)", "(1,3)", "(1,4)"}, {"(2,0)", "(2,1)", "(2,2)", "(2,3)", "(2,4)"}, {"(3,0)", "(3,1)", "(3,2)", "(3,3)", "(3,4)"}, };
String[][] A = { {"(0,0)", "(0,1)", "(0,2)", "(0,3)", "(0,4)"}, {"(1,0)", "(1,1)", "(1,2)", "(1,3)", "(1,4)"}, {"(2,0)", "(2,1)", "(2,2)", "(2,3)", "(2,4)"}, {"(3,0)", "(3,1)", "(3,2)", "(3,3)", "(3,4)"}, };and column 3 (fourth column) is exactly where we expect it to be:
String[][] A = { {"(0,0)", "(0,1)", "(0,2)", "(0,3)", "(0,4)"}, {"(1,0)", "(1,1)", "(1,2)", "(1,3)", "(1,4)"}, {"(2,0)", "(2,1)", "(2,2)", "(2,3)", "(2,4)"}, {"(3,0)", "(3,1)", "(3,2)", "(3,3)", "(3,4)"}, };
Of course, the whole string in each array element is the element.
For example, the elements in column 3 are:
String[][] A = {
{"(0,0)", "(0,1)", "(0,2)", "(0,3)", "(0,4)"},
{"(1,0)", "(1,1)", "(1,2)", "(1,3)", "(1,4)"},
{"(2,0)", "(2,1)", "(2,2)", "(2,3)", "(2,4)"},
{"(3,0)", "(3,1)", "(3,2)", "(3,3)", "(3,4)"},
};
// Normal array print: for (int i=0; i<A.length; i++) { for (int j=0; j<A[i].length; j++) { System.out.printf (" %6s", A[i][j]); } System.out.println (); }
System.out.printf (" %6s", A[i][j]);(It was "d" for integers, "f" for double's).
// Cartesian print: for (int y=A[0].length-1; y>=0; y--) { for (int x=0; x<A.length; x++) { System.out.printf (" %6s", A[x][y]); } System.out.println (); }
(0,4) (1,4) (2,4) (3,4) (0,3) (1,3) (2,3) (3,3) (0,2) (1,2) (2,2) (3,2) (0,1) (1,1) (2,1) (3,1) (0,0) (1,0) (2,0) (3,0)
(0,4) (1,4) (2,4) (3,4) (0,3) (1,3) (2,3) (3,3) (0,2) (1,2) (2,2) (3,2) (0,1) (1,1) (2,1) (3,1) (0,0) (1,0) (2,0) (3,0)Here, the x-coordinate is increasing from 0, 1, 2, ... while the y-coordinate is 0.
| | (0,4) (1,4) (2,4) (3,4) y=3 | (0,3) (1,3) (2,3) (3,3) | (0,2) (1,2) (2,2) (3,2) | (0,1) (1,1) (2,1) (3,1) | (0,0) (1,0) (2,0) (3,0) __|________________________________________ | x=2
public class GradingSpreadsheet {
public static void main(String[] argv) {
double[][] studentGrades = {{4, 3, 5, 2, 10},
{8, 9, 9.5, 8, 0},
{10, 10, 9, 9.5, 0}};
String[] studentNames = {"Larry", "Curly", "Moe"};
// your code here!
}
}
A simple
spreadsheet app -- you have an array of student grades (each row
contains the grades for each homework), and the student names. You
can see that Larry did something mischievous on the last
assignment. Lets do some simple processing:
Activity 3:
Add code to print each student's name, and their average grade over all homeworks.
Activity 4:
Add code to print the average grade for each homework.
Activity 5:
Create an array
double[] weights = {0.2, 0.1, 0.2, 0.3, 0.2};with the same length as the number of homeworks. Compute a weighted grade, where the final grade for the student is determined by these weights on the homeworks. The formula for each final grade should be:
Conways Game of Life is a simple cellular automaton, defined in Mathworld as:
"A cellular automaton is a collection of "colored" cells on a grid of specified shape that evolves through a number of discrete time steps according to a set of rules based on the states of neighboring cells. The rules are then applied iteratively for as many time steps as desired"
Look at a visual repesentation of the rules
Look at this video:
Epic GOL
Play with this GOL simulator
Check out XKCD's post in honor of John Conway