Skip to content

Instantly share code, notes, and snippets.

@darbyluv2code
Created June 22, 2017 15:52
Show Gist options
  • Select an option

  • Save darbyluv2code/50820f94011a6053e990a02bd4be340c to your computer and use it in GitHub Desktop.

Select an option

Save darbyluv2code/50820f94011a6053e990a02bd4be340c to your computer and use it in GitHub Desktop.
RandomFortuneService - girlfriends
package com.joelvirux.annotations;
import java.util.Random;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class RandomFortuneService implements FortuneService {
@Value("${foo.megan_fox}")
private String megan;
@Value("${foo.sam_iCarly}")
private String sam;
@Value("${foo.araceli_gonzales}")
private String araceli;
public String getMegan() {
return megan;
}
public String getSam() {
return sam;
}
public String getAraceli() {
return araceli;
}
//create an array of strings
private String[] data = {
"Beware of the wolf in sheep's clothing",
"Diligence is the mother of good luck",
"The journey is the reward"
};
//create an array of girls
private String[] girl;
@PostConstruct
public void initGirlFriends() {
// create array
girl = new String[3];
// populate array
girl[0] = getMegan();
girl[1] =getAraceli();
girl[2] = getSam();
}
//create a random number generator
private Random myRandom = new Random();
@Override
public String getFortune() {
// pick a random string from the array
int index = myRandom.nextInt(data.length);
String theFortune = data[index];
return theFortune;
}
@Override
public String getGirl() {
// pick a random string from the array
int index = myRandom.nextInt(girl.length);
String theGirl = girl[index];
return theGirl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment