Monty374

Card Class

Nov 22nd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package gameof21;
  2.  
  3. import java.lang.Math;
  4.  
  5. public class Cards {
  6. private static int num1, num2, num3, sum;
  7. private static boolean third;
  8. String getCards;
  9.  
  10. public Cards(boolean three){
  11. third = three;
  12. }
  13.  
  14. public double genNum() {
  15. double num = (13 - 1 + 1) * Math.random() + 1;
  16. if (num > 10) {
  17. num = 10;
  18. }
  19. return(num);
  20. }
  21.  
  22. public int getSum() {
  23. num1 = (int) this.genNum();
  24. num2 = (int) this.genNum();
  25. if (third == true) {
  26. num3 = (int) this.genNum();
  27. } else {
  28. num3 = 0;
  29. }
  30. sum = num1 + num2 + num3;
  31. return(sum);
  32. }
  33.  
  34. public boolean verify() {
  35. boolean over = false;
  36. if (sum > 21) {
  37. over = true;
  38. }
  39. return(over);
  40. }
  41.  
  42. public String getCards() {
  43. String cards;
  44. if (num3 == 0) {
  45. cards = " got cards: " + num1 + ", " + num2 + " which add up to a total of: " + sum;
  46. } else {
  47. cards = " got cards: " + num1 + ", " + num2 + ", and " + num3 + " which add up to a total of: " + sum;
  48. }
  49. return (cards);
  50. }
  51. }
Add Comment
Please, Sign In to add comment