Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package com.joelvirux.annotations;
  2.  
  3. import java.util.Random;
  4.  
  5. import javax.annotation.PostConstruct;
  6.  
  7. import org.springframework.beans.factory.annotation.Value;
  8. import org.springframework.stereotype.Component;
  9.  
  10. @Component
  11. public class RandomFortuneService implements FortuneService {
  12.  
  13. @Value("${foo.megan_fox}")
  14. private String megan;
  15.  
  16. @Value("${foo.sam_iCarly}")
  17. private String sam;
  18.  
  19. @Value("${foo.araceli_gonzales}")
  20. private String araceli;
  21.  
  22. public String getMegan() {
  23. return megan;
  24. }
  25.  
  26. public String getSam() {
  27. return sam;
  28. }
  29.  
  30. public String getAraceli() {
  31. return araceli;
  32. }
  33.  
  34. //create an array of strings
  35. private String[] data = {
  36. "Beware of the wolf in sheep's clothing",
  37. "Diligence is the mother of good luck",
  38. "The journey is the reward"
  39. };
  40.  
  41. //create an array of girls
  42. private String[] girl;
  43.  
  44. @PostConstruct
  45. public void initGirlFriends() {
  46.  
  47. // create array
  48. girl = new String[3];
  49.  
  50. // populate array
  51. girl[0] = getMegan();
  52. girl[1] =getAraceli();
  53. girl[2] = getSam();
  54. }
  55.  
  56. //create a random number generator
  57. private Random myRandom = new Random();
  58.  
  59. @Override
  60. public String getFortune() {
  61. // pick a random string from the array
  62. int index = myRandom.nextInt(data.length);
  63. String theFortune = data[index];
  64. return theFortune;
  65. }
  66.  
  67. @Override
  68. public String getGirl() {
  69. // pick a random string from the array
  70. int index = myRandom.nextInt(girl.length);
  71. String theGirl = girl[index];
  72. return theGirl;
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement