Category Archives: Computer Science

Systematically Visit All Cells [Java]

Description: It’s harvest time and Adam must pick all of the flowers on the island. Unfortunately for Adam, he doesn’t know where the flowers are growing. Flowers could be growing anywhere on the island. In order to keep from being too exhausted, he can only visit each cell once, and he cannot try to pick from an empty cell. There are no nets, water features, or other Jeroos on the island. The purpose of this program is to find a systematic way for Adam to visit every cell exactly once, and pick the flowers from the cells that have flowers.
Download all the island files

The Maps

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.

Two Friends Meet

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

Luhn Check Assignment

Luhn Check

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.

Luhn Number Generator

 

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.

 

from : http://www.impuls-imaging.com/wp-content/uploads/2013/07/luhn_algorithm.png

from : http://www.impuls-imaging.com/wp-content/uploads/2013/07/luhn_algorithm.png

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

from http://www.moneybluebook.com/imagesvr_ce/mbb/luhn-amex-calculation.jpg

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)

Jeroo Walk The Lake with Loops

 

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.

Downloaddownload-bttn the maps

Map #1 : rectangular-lake.jev arrow_right_large
recangular-lake-if2.jev arrow_right_large  
For this one, your Jeroo should travel around the entire outer rim of the island and stop immediately before the flower.
rim-of-lake-1.jev
arrow_right_large  
rectangular-lake-bumps1.jev
arrow_right_large  
Remember Nets kill Jeroosrectangular-lake-bumps2.jev arrow_right_large  
Write a loop that makes the jeroo travel around the lake below. This loop should never end. walk-the-lake-jacks-map.jevs

Printing Digits Of Numbers in Java Assignment

Let’s write the following method

public void printDigits( int n){

}

 

Walk through of how the code should work:

the algorithm inolves

1) extract last digit

2) print last digit

3) remove last digit

keep doing this until there are no more digits

print-numbrs-screen-shot

Example :

Let’s look at printDigits( 345)

Walk through of how the code should work:

the algorithm inolves

1) extract last digit ‘5’

2) print last digit print ‘5’

3) remove last digit now n should be ’34’

do this for ‘4’ and then ‘3’ until there are no more digits

You need a while loop. Think about it. What is the value of n when there are no more digits?