Category Archives: Computer Science

Java Strings

Java  Strings

substrings1

Recursion in Java

Recur

bunnyEars2() (try to figure out what goes where the question marks are)

Recursion problems (bunny ears is a good, straight forward one to start with)

 

Two Friends Meet

Two Friends Meet

  • Create two different Jeroos
  • one Jeroo should start at (0,0) and be facing EAST
  • the other should start at  (0,23) and be facing west
  • they should move at “the same time” and plant flowers in the pattern shown below
  • use a single while loop
  • the isJeroo( relative_diretion) method  might be helpful
  • Note: To get 100%
    • Your loop MUST end (not infinite)
    • You can not use hasFlower()

 

 

jeroo-2-friends-meet-done

Traversing the Rim

In the prior assignment (#2b), you were asked to go around the inner lake  as shown  below. We are going to add 1 new requirement to this

  • with a flower in 6,6
  • using while loop(s) traverse around the border of the inner lake
  • For each map, you should pick the flower, after the loop is over

What is new this time?

  • You are forced to use 1 and only 1 while loop .
  • you can only use hop() (ie you can’t hop more than 1 space)
  • after the loop is done , then you can   pick()  the flower


Download the map files

recangular-lake.jev

walk-the-lake-annotated

 

 

 


 

recangular-lake-if2.jev 

Scroll down for a hint about how to handle if test #1 for this map.

rectangular_lake_if2_overview


 

A closerlook at if test #1 (how to get around that first if test)

rectangular_lake_if2_get_around_net

 


 

rectangular-lake-bumps1.jev


recangular-lake-bump3A.jev

rectangular_lake_3A2


recangular-lake-bump3B.jev ( NOT BEING GRADED, SKIP THIS)

rectangular_lake_3A2_annotated


walk-the-lake-jacks-map.jev

Write an infinite loop (1 while loop). You may NOT use isWater()

 

While Loops #2

#2 A

Create the map below

  • with a flower in 0,0
  • Jeroo to its right (0,1)
  • using while loop(s) traverse around the border of the island
  • at the end pick the flower
  • you can only use hop() (ie you can’t hop more than 1 space)

 

jeroo_walk_exterior1 jeroo_walk_exterior2 jeroo_walk_exterior3 jeroo_walk_exterior4 jeroo_walk_exterior5 jeroo_walk_exterior6 jeroo_walk_exterior7jeroo_walk_exterior8

 


#2 B

Create the map below

  • Jeroo to its right (6,6)
  • use multiple while loops
  • at the end pick the flower
  • you can only use hop() (ie you can’t hop more than 1 space)


Download Island Files

rectangular-lake.jev

1) Starting
<

2) Go around lake, until you are in front of the flower

3) Then pick the flower

finished program state1

Sorting Algorithm Assignment

Sorting Algorithm

 

Good Links

 

You will be given a sorting algorithm to research and to present to the class in a powerpoint. Your powerpoint should

  1. in general terms explain how the algo works
  2. show Java code for the algorithm
  3. have an animation demonstrating how the algorithm works (step by step)
  4.  clearly explain how the code (in each line) relates to the code (most important and easy to forget step)
  5. It’s important that you can explain each line of the code
  6. state best,worst, average case for the data and, in particular, state how the original state of data affects run time performance
    1. in order
    2. random
    3. in reverse order

Grading Rubric Algorithm Project


 

 

 

4

3

2

1

  Big Oh

(double weight)

Addresses best/worst/ave cases with clear connection to all aspects of code

 

Addresses best/worst/ave cases  but does not relate to all relevant code Addresses best/worst/ave cases  but does not connect to code/is too general Does not address all 3 cases Big Oh or does not connect to code in meaningful way
 Animation of algorithm(double weight)

 

 

 

Animation is clearly connected to all aspects of code Animation is connected to critical areas of code Animation is not clearly connected to actual code Animation and code are not related to one another
 Overview(double weight)

 

Gives a clear and enlightening overview of how the algo works in general. Overview of algorithm is technically correct and discusses most of the relevant features. Algorithm is vaguely summarized or is not well explicated. Algorithm is not explained in a meaningful way.

 

  

 

 

 

While loop with if test

Let’s write a program that solves the map below (which you should create yourself) using only 1 while loop

jeroo maps loops 24 jeroo maps loops 25

 

What is an “If Test”?

If you just want to do a single test, use an ‘if’ test, instead of a while loop

goroundwater

 

…Now we can continue hopping till we get to the end of the map

jeroo maps loops 25

 

 

Your Assignment: Create the map above and complete the program . All that you have to do use is the code at the top and then write the custom method goRoundWater()