guess_my_rule
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
guess_my_rule [2020/05/30 15:53] – frchris | guess_my_rule [2022/08/03 12:09] – [Guess My Integer Rule] frchris | ||
---|---|---|---|
Line 5: | Line 5: | ||
In our computer version, the user asks about a certain '' | In our computer version, the user asks about a certain '' | ||
+ | |||
+ | To be fair, the secret rule cannot involve any random behavior. | ||
==== 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 '' | ||
+ | < | ||
+ | * 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; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | 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