Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gameof21;
- import java.lang.Math;
- public class Cards {
- private static int num1, num2, num3, sum;
- private static boolean third;
- String getCards;
- public Cards(boolean three){
- third = three;
- }
- public double genNum() {
- double num = (13 - 1 + 1) * Math.random() + 1;
- if (num > 10) {
- num = 10;
- }
- return(num);
- }
- public int getSum() {
- num1 = (int) this.genNum();
- num2 = (int) this.genNum();
- if (third == true) {
- num3 = (int) this.genNum();
- } else {
- num3 = 0;
- }
- sum = num1 + num2 + num3;
- return(sum);
- }
- public boolean verify() {
- boolean over = false;
- if (sum > 21) {
- over = true;
- }
- return(over);
- }
- public String getCards() {
- String cards;
- if (num3 == 0) {
- cards = " got cards: " + num1 + ", " + num2 + " which add up to a total of: " + sum;
- } else {
- cards = " got cards: " + num1 + ", " + num2 + ", and " + num3 + " which add up to a total of: " + sum;
- }
- return (cards);
- }
- }
Add Comment
Please, Sign In to add comment