Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RosmaryFC #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/abbr/Abbreviate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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."));

}

}
50 changes: 47 additions & 3 deletions src/cardgame/Dealer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cardgame;

import java.text.Format;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -28,7 +29,7 @@ public static <T> void shuffle(List<T> list) {
* A list containing all cards, in a random order.
*/
public static List<Card> getShuffledDeck() {
final List<Card> deck = new ArrayList<>();
final List<Card> deck = new ArrayList<Card>();
// Add all cards to the deck, in order.
for (Card.Suit suit : Card.Suit.values())
for (Card.Number number : Card.Number.values())
Expand Down Expand Up @@ -58,17 +59,60 @@ public static List<List<Card>> 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<Card> shuffledDeck = getShuffledDeck();

//adds numPlayers amount of hands
List<List<Card>> hands = new ArrayList<List<Card>>();

int counterPlayers = 0;
int counterCards = 0;
while (counterPlayers < numPlayers){
List <Card> currentHandsCards = new ArrayList<Card>();

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<List<Card>> 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<List<Card>> hands1 = deal(10, 6);

}

}
22 changes: 22 additions & 0 deletions src/radiobutton/RadioButtonGroup.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,6 +12,9 @@
*/
public class RadioButtonGroup {

HashMap<Integer, Boolean> radioButtons;


/**
* Creates a group of radio buttons.
*
Expand All @@ -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<Integer, Boolean>();
for(int i = 0; i < numButtons; i ++){

if(numButtons == initial){
radioButtons.put(i, true);
}else {
radioButtons.put(i, false);
}
}
}

/**
Expand All @@ -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);
}

/**
Expand Down