Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean simulate(){
- int distance=0;
- int numHops=0;
- //hopDistance() tells us how far teh frog hops
- //if frog reaches target numsteps<maxSteps
- //if goal reached or passed stop hopipng, if position is negative stop hopping if frog reaches max steps stop hopping
- while(distance<goalDistance&&distance>=0&&numSteps<maxHops){
- distance+=hopDistance();
- numHops++;
- }
- if(distance>=goalDistance){
- return true;
- }
- return false;
- }
- public class RandomStringChooser{
- private String[] words;
- private ArrayList<String> randomWords;
- pbulic RandomStringChooser(String[] arr){
- words=arr;
- randomWords=new ArrayList<>();
- makeCopy();
- }
- public String getNext(){
- if(randomWords.size()>0){
- return randomWords.remove((int)(Math.random()*randomWords.size()));
- }
- else{
- return "NONE";
- }
- }
- private void makeCopy(){
- for(String s: words){
- randomWords.add(s);
- }
- }
- }
- public class HiddenWord{
- private String word;
- public HiddenWord(String s){
- word=s;
- }
- public String getHint(String guess){
- String hint="";
- for(int i=0; i<guess.length();i++){
- String ch=guess.substring(i, i+1);
- if(word.indexOf(ch)>=0){
- if(word.indexOf(ch)==i){
- hint+=ch;
- }
- else{
- hint+="+";
- }
- }
- else{
- hint+="*";
- }
- }
- }
- }
- public interface NumberGroup{
- boolean contains(int n);
- }
- public class Range impliments NumberGroup{
- private int min, max;
- public Range(int min, int max){
- this.min=min;
- this.max=max;
- }
- public boolean contains(int n){
- return n>=min&&n<=max;
- }
- }
- @Override
- public boolean contains(int n){
- boolean containsN=false;
- for(NumberGroup g: groupList){
- if(g.contains(n)){
- return true;
- }
- }
- return false;
- }
- public int getValueAt(int r, int c){
- for(SparseArrayEntry e: entries){
- if(e.getRow()==r&&e.getCol()==c){
- return e.getValue();
- }
- }
- return 0;
- }
- public void removeColumn(int c){
- for(int i=0; i<entries.size(); i++){
- if(entries.get(i).getCol()==c){
- entries.remove(i);
- i--;
- }
- else if(entries.get(i).getCol()>c){
- entries.set(i, new SparseArrayEntry(entries.get(i).getRow,
- entries.get(i).getCol-1));
- }
- }
- numCols--;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement