User Tools

Site Tools


guess_my_rule

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
guess_my_rule [2020/05/30 15:55] frchrisguess_my_rule [2022/08/03 12:09] – [Guess My Integer Rule] frchris
Line 10: Line 10:
  
 ==== Guess My Integer Rule==== ==== Guess My Integer Rule====
 +This is best used with the BlueJ IDE where you can make an instance of a class without writing a ''main'' method.
 +<code>/**
 + * Make up your own rule
 + 
 + * @author Chris Thiel, OFMCap
 + *
 + */
 +public class GuessMyIntegerRule 
 +{
 + private String secretRule = "It must be prime";
 + public boolean DoesThisIntFollowMyRule(int n) 
 + {
 + for(int i = 2; i < n; i++)
 + if (n % i == 0)
 + return false;
 + return true;
 + }
 +
 + public String IGiveUp()
 + {
 + return secretRule;
 + }
 +}
 +</code>
 +Now Try this:
 +  - Change the code so it the number must me even
 +  - Change the code so it must be odd
 +  - Make up your own rule and try it out with your lab partner
 ==== Guess My String Rule ==== ==== Guess My String Rule ====
  
guess_my_rule.txt · Last modified: 2022/08/11 10:09 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki