Author Archives: Mr. M

Array Fun 2 [2021]

Complete all the methods below. When you are done, copy and paste the testmethods.v4  into your class and run it to see if you have any obvious errors.

int sumEveryN(int[] nums, int n)

Description: This method returns the sum of every n elements of nums..

Method Call return value/output
sumEveryN( {1 , 2 , 3 , 4 }, 2 ) 4( ie 1 +3)
sumEveryN( {13 , 42, 15, 33 , 44 , 16 , 52} ,3) 98 ( ie 13 + 33+ 52)

String[] doubleArr(String[] strs)

Description: This method returns a new version of strs in which each element now appears twice. This can be done with a for-each loop, which I believe is easier and more intuitive.

Method Call return value/output
doubleArr( {“a”,”b”,”c”} ) {“a”,”a”,”b”,”b”, “c” , “c”}
doubleArr( {“math”,”ware”,”house”,”.com” }) {“math”,”math”,”ware”,”ware”,”house”,”house”,”.com”, “.com”}

int  indexOf5(int[] nums )

Description:This returns the index of the first occurrence element 5  or -1 if 5 does not appear anywhere in the array.

Method Call return value/output
indexOf5( { 2 , 3 , 5 , 4 } ) 2
indexOf5( { 2 , 3 , 5 , 4, 5  } ) 2
indexOf5( { 2 , 3 ,7  , 4, 3,   } ) -1

More Sample calls and return vals

screenshot.41


int indexOf(int[] nums, int num)

Description: This method returns the index value of the first appearance of num or -1 if num is not an element of nums .

Method Call return value/output
indexOf( {6,4 ,7,3, 4 }, 4) 1
indexOf( {6,4 7 ,3,2,7}, 7) 2
indexOf( {6,4 ,2,3}, 22) -1

 


int[] randos(int start, int end, int howMany)

Description:  This method returns an array of random numbers between [start,end] . Note make sure that each element in the new array attempts to make a new random int.

 randos_loop
 More example calls and returns :
randos2

double meanBetween(int[] nums, int min, int max)

Description:  This method returns the mean of nums ; however, this method only counts values within the range (min,max) as shown in the examples below:

screenshot.12

int secondSmallest(int[] nums )

Description: This method returns the element of nums with the second smallest value.

Note: You may not modify the input array. For instance, you may not put nums in order,  which would be bad because you were not asked to modify the array.

@precondition: nums.length >= 2

Note: You will lose credit if you use a constant to represent the smallest or second smallest number. See pseudocode 

Method Call return value/output
secondSmallest( { 2 , 18 , 22, 4 , 6 } ) 4
secondSmallest( { 3 , 7 , 15 , 1 ,101} ) 3


 The question below is extra credit .
** int[] add(int[] num1, int[] num2, int base) throws ArithmeticException
@precondition 1 < base < 11
@precondition num1.length = 5 and num2.length = 5
@postcondition: the returned array has 5 elements representing the sum or an ArithmeticException is thrown

Description: This method attempts to replicate addition. Consider both num1 and num2 represent the five digits of a number. Each element in the array stores one of the digits. For instance, the number 143 would be represented as {0,0,1,4,3 }. Numbers can be in any base between 2 and 10 inclusive , and the number 101102 in binary would appear in an arrays as : {1, 0, 1 , 1, 0 } . Let’s assume the numbers are positive. You should return an array representing the digits of the sum of num1 and num2.  You may not do any math besides addition. You may not use any external libraries for any math or base conversions.   If the number of digits in the sum exceeds the maximum number of digits (5) , you should throw an arithmetic exception as shown in the code below:

Note: You may not use any kind of helper or utility methods that are built into pre-defined Java classes for converting numbers between bases. Only use techniques taught in this class.

Method Call return value/output
add( {0,0,0 ,4,2},{0,0,0,5,1}, 10) {0, 0, 0, 9, 3} ie (42 + 51 = 93)
add( {0, 0, 0 ,7,2},{0,0,0,5,1}, 10) {0, 0 , 1 , 2, 3} ie (72 + 51 = 123)
add( {0, 0 , 0 , 1 , 1}, { 0 , 0 , 0 , 1 }, 2) {0, 0 , 1 , 0 , 0} ie ( 112 + 12= 1002 )

Old versions:

Array Fun 1 

Array F un 2 (v 1)

 

Array Fun 3 (resizing included)

String 1 and Array 1 Exercises

Exercises for String 1 and Array 1 (no loops)

When you are done, you can copy and past the score() method below into your class. It will test some (but, by no means all) of the things that your code should do

Create a class called StrArr1 and add each method below into it.

screenshot.1

 

 

For the absVals()  method below use the Math.abs() Java method.

screenshot.3

screenshot.1

 

screenshot.4

For the  randos1to10()   method below use the  Math.random()  Java method. Create a new array to store random integers. Each integer should be [1,10]

screenshot.5

So, you want to Skip CS II

It is very rare that I recommend anyone skip from the Intro class, the easiest CS class,  to SUPA, the hardest CS class , without the foundation that we build in Computer Science II.

The path to skipping

If you  really want to try to skip CS II, the path would be to complete the online component of CS II curriculum during the school year and to then sit down with me for an interview. If I am satisfied that you are ready to skip CS II, I will then make the recommendation.

Much, though not all, of the CS II curriculum is online and so can be completed at a student’s convenience.

Please know, that most of the students who have followed this path and who found the Intro to CS class too easy and who then skipped into SUPA have ended up regretting this and, more often than not, they have had to drop the SUPA class.

Ask yourself– Would you skip Calculus I and instead jump right to Calculus II?

Probably not.

And it’s not much different here;  while it has been done,  for the most part it has only been successfully pulled off by students who are “hardcore” programmers and who have voluminous experience coding outside the classroom. Kids who have made their own apps and learned how to do real programming on their own.

Now, if that describes you and you have made real apps that you can show, then maybe this is the right move, but otherwise, this jump almost never is.

So, what students should do is this – Have your guidance counsellor sign you up for CS II for next year.   If you complete the online  part of the CS II curriculum, by June, then we can sit down and I will have an assessment of your readiness to make this radical jump.

Mini Open Ended Project

Normally we dedicate an entire quarter to a project. We will instead be dedicating about 2/3 of the quarter.

The parameters are similar but not quite so grand in scope. To get an A, you must create a complex web product . This could be a single interactive application or multiple pages . Simple ideas to get to that point include:

  • a multipage form validation product
    • Multiple pages like the login form
      • validate other things – maybe credit cards
  • A to do list that uses jQuery for animation
  • a game that uses Phaser.io ( not trivial,  but fun)
  • Learn php and mysql to create a simple login system. This would only be for those of you who have been able to successfully setup apache, mysql –probably only the windows users.

Ways to add complexity:

  • include loops
  • include arrays
  • include a 3rd party javascript library like jQuery, Vue  etc..
  • I know  jQuery or undescore , if you want something where I can add somequick tidbits when you’re stuck

 

Everybody must use git and have at least 20 commits over the span of the rest of the quarter.

 

Examples of finished product and grades:

  1. Advanced Form Validation
    • credit card validation using luhn algorithm
    • registration page
      • email
      • password
      • confirm password
      • gender
      • etc..
  2. 1-3 calculators. The # should depend on the complexity
  3. 2 or 3 pages that involve form validation
    • Example : https://directpay.irs.gov/directpay/payment?execution=e1s2
    • Maybe not the most fun but closes to what we have done in class
  4. Come up with something that you want to do and make it happen.

Mr Morris, I just want to pass.

  • then, do a multi page layout that makes use of foundation instead of bootstrap. Foundation is a similar css  framework, No javascript needed but grade ceiling will be low.

Quarter 4 Project

Objective: To create a complex, industry level, project that builds off the skills we learned this year. You must learn at least one new technology . Your grade will be based on the level of complexity of your final project. I have listed some examples of technologies to learn and rated their general complexity. Ultimately, complexity will be evaluated by me and you are welcome to ask for feedback on where the complexity of your project will land you.

Projects from last class

Links and Resources for learning Phaser

Note: I am not familiar with many of the technologies below.  The purpose here is for you to learn something, yourself, as web developers are often forced to do in the real world. If you think you will need help, I suggest going with Phaser because most students will do it and you can help each other . I have limited knowledge of Phaser.

Technologies

Phaser ( The most popular 4th quarter project topic is to create phaser games housed in a bootstrap based website). There is a great range in complexity that using Phaser allows for

Example Projects, probable complexity and grade.

The table below lists technologies you can use and provides a general guideline for its complexity and likely grade outcome. If something is classified as an “add-on,” then it is a way to increase complexity but should not, in and of itself, be considered complex enough on its own.

Often the grades are a “range” because it depends on what, ultimately your project does. Take “vue” for instance. This is a very popular, very modern javascript framework so it can be quite complex, but ultimately it depends on what your program actually does that will determine the final grade.

Technology Complexity Complexity lvl Grade
Phaser (meh) Edits one of the pre-built games on phaser.io, nothing much new very low C
Phaser (moderate) Creates one new game, but it is relatively simple (asteroids) and submits 1 page website that uses bootstrap Moderate B-
Phaser (good) Creates completely new complex game (maybe uses physics or other unique coding) moderate-high B+/ A
Node.js/Gulp   Learns how to use nodejs and employs Gulp to improve workflow Moderate add on
 Remote git Learns how to push and pull from remote git repo on github low add-on
 Vue Learns how to use the vue.js framework for javascript development high B /A-
Foundation Learn a bootstrap alternative and create several web pages moderately low C+
Angular Creates a multi page website with the angular .js framework high B/A
Mathjax Learns how to integrate the Mathjax math library for rendering professional looking mathematics low add-on
Vim Consistently edits with Vim . I will quiz you on how to use VIM and I will expect to see you editing with VIM during class moderate add on

List of other utitlites and libraries to use:

 

Notes: these can be combined to add complexity and professionalism. For instance, you can create a multipage website based on Vue and some of the pages can house phaser games that you create. This has the potential of an A+, assuming the Phaser games are original.

Not comfortable with Programming? Here is a multi technology example that will get a B:

This is an example that will get people who are not very comfortable with programming into the “B” range: Learn how to use Foundation, or another bootstrap alternative, and also how to integrate Mathjax to display math equations. You can create a multi page math website full of equations. You could add using remote git or Gulp to get the grade up even a bit more.

Javascript framework comparisons : https://www.codeinwp.com/blog/angular-vs-vue-vs-react/

Phaser 3 Links

Phaser

http://phaser.io/learn/  ( Where you should start)

Medium To Advanced Level Links (not to start, but once you have a clue)

  • Emmanuele Feronato – amazing blog about game dev and lots of phaser stuff here .
  • Ourcade Co – great, albeit advanced and very professional, tutorials/tips on phaser dev – here .

Great YouTube Videos

  • Zeneva
    • https://youtu.be/hI_LS8bdkM4 – Setting up Phaser, local server, files, creating scenes . Does not use Classes so easier for most to understand