Advertisement
StefanTobler

T2 Assignment 5 Main

Mar 16th, 2017
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. public class Main {
  2.   public static void main(String... params) {
  3.     Deck deck = new Deck();
  4.     Card[] hand1 = new Card[5];
  5.     Card[] hand2 = new Card[5];
  6.     for (int i = 0; i < hand1.length; i++) {
  7.       hand1[i] = deck.getTopCard();
  8.       hand2[i] = deck.getTopCard();
  9.     }
  10.     int hand1Sum = sum(hand1);
  11.     int hand2Sum = sum(hand2);
  12.     System.out.println("Hand 1 (total points " + hand1Sum + ")");
  13.     print(hand1);
  14.     System.out.println();
  15.     System.out.println("Hand 2 (total points " + hand2Sum + ")");
  16.     print(hand2);
  17.     System.out.println();
  18.     if (hand1Sum > hand2Sum) {
  19.       System.out.println("Hand 1 wins!");
  20.     } else if (hand1Sum < hand2Sum) {
  21.       System.out.println("Hand 2 wins!");
  22.     } else {
  23.       System.out.println("Draw");
  24.     }
  25.   }
  26.  
  27.   private static void print(Card[] cards) {
  28.     for (Card card : cards) {
  29.       System.out.println(card);
  30.     }
  31.   }
  32.  
  33.   private static int sum(Card[] cards) {
  34.     int sum = 0;
  35.     for (Card card : cards) {
  36.       sum += card.pointValue();
  37.     }
  38.     return sum;
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement