diff --git a/src/abbr/Abbreviate.java b/src/abbr/Abbreviate.java index c06c041..257b9d8 100644 --- a/src/abbr/Abbreviate.java +++ b/src/abbr/Abbreviate.java @@ -9,13 +9,33 @@ public class Abbreviate { * lower case, removed. Other characters are unmodified. */ public static String abbreviate(String string) { - // TODO: Write this method. - return null; + String abbreviatedString = ""; + for(int i = 0; i < string.length(); i ++){ + if (! isVowel(string.toLowerCase().charAt(i))){ + abbreviatedString += string.charAt(i); + } + } + + return abbreviatedString; + } + + public static boolean isVowel(char letter){ + String vowels = "aeiou"; + for(int i = 0; i < vowels.length(); i ++){ + if (letter == vowels.charAt(i)){ + return true; + } + } + return false; } public static void main(String[] args) { + String s = "The quick brown fox jumped over the lazy dogs."; + System.out.println(abbreviate(s.toUpperCase())); + System.out.println(abbreviate("The quick brown fox jumped over the lazy dogs.")); System.out.println(abbreviate("It was the best of times, it was the worst of times.")); + } } diff --git a/src/cardgame/Dealer.java b/src/cardgame/Dealer.java index 9210bf1..ab31d73 100644 --- a/src/cardgame/Dealer.java +++ b/src/cardgame/Dealer.java @@ -1,5 +1,6 @@ package cardgame; +import java.text.Format; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -28,7 +29,7 @@ public static void shuffle(List list) { * A list containing all cards, in a random order. */ public static List getShuffledDeck() { - final List deck = new ArrayList<>(); + final List deck = new ArrayList(); // Add all cards to the deck, in order. for (Card.Suit suit : Card.Suit.values()) for (Card.Number number : Card.Number.values()) @@ -58,17 +59,60 @@ public static List> deal(int numPlayers, int numCards) { // - Add cards to the hand, removing them from the deck. // - Add the hand to the list of hands. // - Return the list of hands. - return null; + + if(numPlayers * numCards > 52) { + try + { + throw new Exception("There are insufficient cards to deal evenly"); + } + catch(Exception e) + { + e.printStackTrace(); + } + return null; + } + + //NEW shuffled Deck + List shuffledDeck = getShuffledDeck(); + + //adds numPlayers amount of hands + List> hands = new ArrayList>(); + + int counterPlayers = 0; + int counterCards = 0; + while (counterPlayers < numPlayers){ + List currentHandsCards = new ArrayList(); + + for (int i = shuffledDeck.size() - 1; i >= 0;){ + + while (counterCards < numCards){ + currentHandsCards.add(shuffledDeck.get(i)); + shuffledDeck.remove(i); + counterCards ++; + i --; + } + hands.add(currentHandsCards); + counterCards = 0; + counterPlayers ++; + break; + } + } + + + return hands; } public static void main(String[] args) { // Deal four 5-card hands, and print them out. List> hands = deal(4, 5); for (int h = 0; h < hands.size(); ++h) { - System.out.println("player " + h + " holds:"); + System.out.println("player " + (h+1) + " holds:"); for (Card c : hands.get(h)) System.out.println(" " + c); } + + List> hands1 = deal(10, 6); + } } diff --git a/src/radiobutton/RadioButtonGroup.java b/src/radiobutton/RadioButtonGroup.java index ef82d60..b62b423 100644 --- a/src/radiobutton/RadioButtonGroup.java +++ b/src/radiobutton/RadioButtonGroup.java @@ -1,5 +1,7 @@ package radiobutton; +import java.util.HashMap; + /** * Represents a group of "radio buttons": toggle buttons for which exactly one is selected * at a given time. If a different button is selected, the previously-selected button is @@ -10,6 +12,9 @@ */ public class RadioButtonGroup { + HashMap radioButtons; + + /** * Creates a group of radio buttons. * @@ -22,6 +27,20 @@ public class RadioButtonGroup { */ public RadioButtonGroup(int numButtons, int initial) { // TODO: Implement this method. + + if(initial > numButtons || initial < 1){ + throw new RuntimeException("The initial button number is invalid"); + } + + radioButtons = new HashMap(); + for(int i = 0; i < numButtons; i ++){ + + if(numButtons == initial){ + radioButtons.put(i, true); + }else { + radioButtons.put(i, false); + } + } } /** @@ -40,6 +59,9 @@ public RadioButtonGroup(int numButtons) { */ public void select(int button) { // TODO: Implement this method. + for (int btn : radioButtons.) + + radioButtons.put(button, true); } /**