Create a class Matrix
int[][] add (int[][] matr1, int[][] matr2)
Description: This method returns the sum of matr1 and matr2
int[][] multiply(int[][] matr1, int[][] matr2)
Description: This method returns the product of matr1 and matr2
Create a class Matrix
int[][] add (int[][] matr1, int[][] matr2)
Description: This method returns the sum of matr1 and matr2
int[][] multiply(int[][] matr1, int[][] matr2)
Description: This method returns the product of matr1 and matr2
Add the following Methods to a class called ArrayFun2D
public void print(int[][] arr)
Description: This method prints each element in the array. This will be a useful method when you are debugging your code and want to test it out to see if it works.
| Method Call | return value |
| print({{1,2} , {3,4}, { 5, 6 } } ) | 1 2 3 4 5 6 |
public int sum(int[][] arr)
Description: This method returns the sum of all elements in the array
| Method Call | return value |
| sum({{1,2} , {3,4}, { 5, 6 } } ) | 21 ( ie 1+2+3+4+5+6) |
public String concat(String[][] strs)
Description: This method returns the concatenation of all the elements in the Array
| Method Call | return value |
| concat({{“a”,”xc” }, {“t”, “zoo”}, { “jjkj” } } ) | “axctzzoojjkj” |
public double mean( int[][] arr)
Description: This method returns the arithmetic mean of the array. Make sure you double check that you are correctly returning results that include decimal values .
| Method Call | return value |
| mean({{2,8} , {4 , 7} } ) | 5.25 ie (2+8+4+7)/4 |
public void printRow(int[][] arr, int row)
Description: This method prints all elements in
row.This can be (and should be) done with a single loop.
| Method Call | return value |
| printRow({{1,2} , {3,4}, { 5, 6 } } , 1 ) | 3, 4 |
| printRow( { 5 , 6} , {7, 12, 13 , 5 }, { 5, 6 ,0} } , 2 ) | 5 , 6, 0 |
public void printCol(int[][] arr, int col)
Description: This method prints all elements in
col.
| Method Call | return value |
| printCol({{1,2} , {3, 4}, { 5, 6 } } , 1 ) | 2 4 6 |
| printCol( { 5 , 6} , {7, 12, 13 , 5 }, { 12, 6 ,0} } , 0 ) | 5 7 12 |
| printCol( {12, 13 , 5 }, { 6, 2, 13 ,11} , {1,2 } } , 2 ) | 5 13 |
public int maxVal_inRow(int[][] arr, int row)
Description: This method returns the value of the largest number in the given row
| Method Call | return value |
| maxVal_inRow({{1,2} , {3,4}, { 5, 6 } } , 1 ) | 4 |
| maxVal_inRow ({ { 5 , 6} , {7, 12, 13 , 5 }, { 5, 6 ,0} } , 2 ) | 6 |
public int maxVal_inCol(int[][] arr, int col)
Description: This method returns the value of the largest number in the given col
| Method Call | return value |
| maxVal_inCol({{1,2} , {3,4}, { 5, 6 } } , 0 ) | 5 |
| maxVal_inCol({{1,-2} , {3,-4}, { 5, -5 } } , 1 ) | -2 |
public int[][] changeValues(int[][] table, int val)
Description:This method returns the array with all elements set to
valchangeValues(table, 5)
Original Array
1 2 3 4 5 6 Returned Array
5 5 5 5 5 5
public void print_colMajor(int[][] arr)
Description: This method prints each element in the array – using column major order
| Method Call | return value |
| print({{1,2} , {3,4}, { 5, 6 } } ) | 1 3 5 2 4 6 |
public int[][] removeVals(int[][] table, int val)
Description: This method returns a version of the 2-d array where val has been removed from all elements
removeValues(table, 5)
Original Array
{1 , 5} {3, 4} {5, 6} Returned Array
{1} {3, 4} {6}
int[] twoD_to1D(int[][] arr)
Description: This method takes an input array that is in 2 dimensions and creates a 1 d array . Assume that the array is rectangular (not jagged).
| Method Call | return value |
| twoD_to1D ( {{1,2} , {3,4}, { 5, 6 } } ) | { 1 , 2 , 3 , 4 , 5 , 6 } |
int[][] add (int[][] matr1, int[][] matr2)
Description: This method returns the sum of matr1 and matr2
** int[][] multiply(int[][] matr1, int[][] matr2)
Description: This method returns the product of matr1 and matr2
**public int[][] invertValues(int[][] matr)
Description: This method returns the paramater with its values ‘inverted’
Original Array
1 2 3 4 5 6 Returned Array
6 5 4 3 2 1
String[][] table = {
{"a","b","c"},
{"d","e","f","g"},
{"g","h"},
};
int table2[][] = {
{ 1, 4, 5},
{5,11,12},
{22, 45},
};
Warming up
public void printFactors( int n )
Description: This method prints all factors of n
| Method Call | return value/output |
| printFactors( 5) | 1
5 |
| printFactors( 6) | 1
2 3 6 |
| printFactors( 9 ) | 1 3 9 |
| printFactors( 15) | 1 3 5 15 |
public int[] getFactors( int n )
Description: This method returns an array populated with the factors on n
| Method Call | return value/output |
| getFactors( 5) | {1,5} |
| getFactors( 6) | {1,2,3,6} |
| getFactors( 9 ) | {1,3, 9} |
| getFactors( 15) | {1,3,5} |
public int[] removeZeros(int [] nums)
Description: This method returns a version of the input –with all occurrences of 0 , zero, removed
| Method Call | return value/output |
| noZeros( { 3 , 4, 0, 1} ) | { 3, 4, 1} |
| noZeros( { 0, 5 , 0, 0, 9, 0, 1 , 11} ) | { 5,9,1,11} |
** public int[] doubleUp( int [] nums, int val)
Description: This method retuns a version of the input –with all occurances of val duplicated.
| Method Call | return value/output |
| doubleUp( { 3 , 4, 0, 1} , 4 ) | { 3, 4 , 4, 0, 1} |
| doubleUp( { 1, 3 , 1, 5 , 3, 3} , 3 ) | {1 , 3, 3 , 1, 5 , 3, 3, 3, 3 } |
Similar problems on codinbat
Shunya Map 1
Shunya 4
Struhl Map:
Ryuki’s Maze
Can be done in about 20 lines
Heeyeon’s Map:
Picture at start:
Brett’s Maze 2
George’s Map : Start at ( 10,0) , facing SOUTH, Use 1 loop and pick the flower
A Different strategy
Ryuki’s Red Wind
Bismark’s Map
Directions: Pick all the flowers. Start anywhere ; end anywhere. Don’t die, Make sure the loop ends.
Objective: To use while loops to get the Jeroo to pass through each maze and get the flower. It is possible to write a solution to both of these mazes using a single while loop–albeit this loop will have several( about 5 or 6) if tests! It is important for this problem that you do NOT simply hand code this. To get an A on both of these assignments you must use 1 single while loop per maze.
Download All Island Files
island3-A
Shunya 3
Aliya’s Map
Mazes 2 (start in top left, 1 loop to pick flower)
Shunya 2
Yuna’s Original Maze
island-3-D (start in the top left, and get to the bottom right)
AlanasMessage_MAP.jev
4) ZigZag : Use 1 while loop (not infinite), follow the flowers, picking them up and use those flowers traverse over the nets. Notice where the Jeroo ends (ie your while loop condition)
5) Spell Z (Blank Map)
Last and most definitely not least:
island3-C
This is the deceptively hard and should be done last and only if you want that A+

Done all of the maps? Start on the next set here


Note: Do not be fooled by how similar the next map is. You will probably have to rewrite some code to complete the next one.




One Saturday morning, two friends, Bugs and Daffy, decide to meet and plant flowers to beautify Santong island. Daffy starts in the Northwest corner facing East with 90 flowers in his pouch. Bugs starts in the Northeast corner facing West with 90 flowers in his pouch. Bugs and Daffy begin hopping toward one another. As they hop, each plants exactly one flower at every location it enters, including its starting location. They meet, facing each other, roughly in the middle of row 0. After a handshake and a little small talk, Bugs and Daffy both turn toward the south and continue planting flowers all the way to the southern edge of the island. When both reach the South Sea, the say goodbye and part. Daffy turns west and plants flowers all the way to the Western Ocean. Bugs turns east and plants flowers all the way to the Eastern Ocean. This is where our story ends. Your task is to write a Jeroo program that will illustrate this story.
One possible solution to this project is represented in the picture below

It is possible to tell if a number could be a valid credit card. Credit cards numbers can be validated against an algorithm known as a Luhn. Read this first.
http://www.datagenetics.com/blog/july42013/index.html
Counting from the check digit, which is the rightmost, and moving left, double the value of every second digit.
Sum the digits of the products together with the undoubled digits from the original number.
If the total ends in 0 (put another way, if the total modulo 10 is congruent to 0), then the number is valid according to the Luhn formula; else it is not valid.
Image from http://www.impuls-imaging.com/wp-content/uploads/2013/07/luhn_algorithm.png
Mod 10+5 Variant Some credit cards use the “Mod 10 plus 5” variant to extend the space of valid card numbers.[citation needed] In this variant, if the sum ends in 0 or 5, the number is considered valid.
from http://www.moneybluebook.com/imagesvr_ce/mbb/luhn-amex-calculation.jpg
A more extensive analysis with good images and an online Luhn Checker (currently blocked by Harrison network filter)
Original Project Descriptions is here
Acknowledgement This problem is adapted from one that was created originally by Erica Eddy of The University of Wisconsin – Parkside.
Your jeroo is exploring the outer perimeter of the lake. It starts next to a flower and travels the entire way around the lake. Have your jeroo stop immediately before the flower (using a loop) and then, after the loop is over, your jeroo should pick the flower.
Download
the maps
Map #1 : rectangular-lake.jev![]() |
![]() |
![]() |
recangular-lake-if2.jev![]() |
![]() |
![]() |
|
![]() |
![]() |
rectangular-lake-bumps1.jev![]() |
![]() |
![]() |
Remember Nets kill Jeroosrectangular-lake-bumps2.jev![]() |
![]() |
![]() |
Write a loop that makes the jeroo travel around the lake below. This loop should never end. walk-the-lake-jacks-map.jev![]() |