Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement