Paste what's on your clipboard thread


Recommended Posts


package domainmodel;
/**
* De klasse kaart stelt een kaart voor van een bepaald type
* (Harten/Klaveren/Ruiten/Schoppen) en een bepaald nummer (1-13, waar 1 = Aas,
* 11 = Boer, 12 = Dame, 13 = Koning)
*
* @author Ambroos
*
*/
/**
* @author Ambroos
*
*/
public class Kaart {
private String type = "Harten";
private int nummer = 1;
private boolean omgedraaid = true;
/**
* Maakt een nieuwe kaart aan met een bepaald type en een bepaald nummer.
*
* @param type
* Het type van de kaart, moet Harten/Klaveren/Ruiten/Schoppen
* zijn.
* @param nummer
* Het nummer van de kaart, moet 1-13 zijn. (1 = Aas, 11 = Boer,
* 12 = Dame, 13 = Koning)
* @throws IllegalArgumentException
* Wanneer het type of het nummer van de kaart ongeldig is.
*/
public Kaart(String type, int nummer) throws IllegalArgumentException {
this.setType(type);
this.setNummer(nummer);
}
private void setType(String type) throws IllegalArgumentException {
if (type == null)
throw new IllegalArgumentException("Type mag niet null zijn.");
if (!(type.equals("Harten") || type.equals("Ruiten")
|| type.equals("Schoppen") || type.equals("Klaveren")))
throw new IllegalArgumentException(
"Kaarttype moet Harten, Koeken, Schoppen of Klaveren zijn. Hoofdlettergevoelig.");
this.type = type;
}
/**
* Geeft het type van de kaart. (Harten/Klaveren/Ruiten/Schoppen)
*
* @return Het type van de kaart.
*/
public String getType() {
return type;
}
private void setNummer(int nummer) throws IllegalArgumentException {
if (nummer < 1 || nummer > 13)
throw new IllegalArgumentException(
"Kaartnummer moet tussen 1 en 13 liggen.\n11 = Boer\n12 = Dame\n13 = Koning");
this.nummer = nummer;
}
/**
* Geeft het nummer van de kaart. 1 = Aas, 11 = Boer, 12 = Dame, 13 =
* Koning.
*
* @return Het nummer van de kaart;
*/
public int getNummer() {
return nummer;
}
/**
* Draait de kaart om. Omgedraaide kaarten worden ont-omgedraaid. Ofzo.
*/
public void draaiOm() {
setOmgedraaid(!isOmgedraaid());
}
private void setOmgedraaid(boolean isOmgedraaid) {
this.omgedraaid = isOmgedraaid;
}
/**
* Geeft terug of de kaart is omgedraaid.
*
* @return True wanneer de kaart is omgedraaid.
*/
public boolean isOmgedraaid() {
return omgedraaid;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
String result = null;
String teken = "" + getNummer();
if (nummer == 1) {
teken = "Aas";
} else if (nummer == 11) {
teken = "Boer";
} else if (nummer == 12) {
teken = "Dame";
} else if (nummer == 13) {
teken = "Koning";
}
if (isOmgedraaid()) {
result = getType() + " " + teken;
} else {
result = "--";
}
return result;
}
/**
* Kijkt of een kaart op gebied van nummer en type gelijk is aan een andere
* kaart. Of de kaarten dezelfde omdraaistatus hebben maakt niet uit.
*
* @param kaart
* De kaart om te vergelijken met de oproepende kaart.
* @return True wanneer beide kaarten hetzelfde type en hetzelfde nummer
* hebben.
*/
public boolean equals(Object o) {
boolean result = false;
if (o != null && o instanceof Kaart) {
Kaart kaart = (Kaart) o;
if (kaart.getNummer() == this.getNummer()
&& kaart.getType().equals(this.getType()))
result = true;
}
return result;
}
/**
* Interprets human input (such as "hartenaas" or "klaverenboer" or
* "Harten tien" and almost all other possible valid inputs to return the
* right card and maximize usability.
*
* @param input
* any string input that might contain enough information to form
* a card
* @return the card the user put in
* @throws IllegalArgumentException
* when the input could not be interpreted properly or was
* invalid
*/
public static Kaart humanInput(String input)
throws IllegalArgumentException {
int nummer = 0;
String type = null;
if (input == null || input.length() == 0) {
throw new IllegalArgumentException("De invoer is ongeldig.");
}
input = input.toLowerCase();
// Check all possible number inputs.
if (input.contains("1") || input.contains("een")
|| input.contains("aas"))
nummer = 1;
if (input.contains("2") || input.contains("twee"))
nummer = 2;
if (input.contains("3") || input.contains("drie"))
nummer = 3;
if (input.contains("4") || input.contains("vier"))
nummer = 4;
if (input.contains("5") || input.contains("vijf"))
nummer = 5;
if (input.contains("6") || input.contains("zes"))
nummer = 6;
if (input.contains("7") || input.contains("zeven"))
nummer = 7;
if (input.contains("8") || input.contains("acht"))
nummer = 8;
if (input.contains("9") || input.contains("negen"))
nummer = 9;
if (input.contains("10") || input.contains("tien"))
nummer = 10;
if (input.contains("boer") || input.contains("11"))
nummer = 11;
if (input.contains("dame") || input.contains("koningin")
|| input.contains("12"))
nummer = 12;
if (input.contains("koning") || input.contains("heer")
|| input.contains("13"))
nummer = 13;
// Check all possible type inputs
if (input.contains("hart")) {
type = "Harten";
}
if (input.contains("klaver")) {
type = "Klaveren";
}
if (input.contains("schop") || input.contains("schup")) {
type = "Schoppen";
}
if (input.contains("ruit") || input.contains("koek")) {
type = "Ruiten";
}
if (nummer == 0 || type == null)
throw new IllegalArgumentException("De invoer is ongeldig.");
return new Kaart(type, nummer);
}
/**
* Vergelijkt twee kaarten op gebied van nummer, type en eventueel null of
* niet. Deze methode kan gebruikt worden bij het sorteren. De
* vergelijkingsvolgorde is de standaardvolgorde van de kaarten.
* (Aas-2...10-Boer-Dame-Koning, Harten/Klaveren/Ruiten/Schoppen)
*
* @param kaart
* De kaart om mee te vergelijken.
* @return Een positief cijfer als de oproepende kaart juist staat tegenover
* de parameterkaart.
*/
public int compareTo(Kaart kaart) {
int verschil = 0;
if (kaart == null) {
verschil = -1;
} else {
verschil = getType().compareTo(kaart.getType());
}
if (verschil == 0) {
verschil = getNummer() - kaart.getNummer();
}
return verschil;
}
}
[/CODE]

You asked for it...

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Marshall Major V Bluetooth headphones are now up to 47% off on Amazon by Ivan Jenic The Marshall Major V in Midnight Blue is currently $89.99 on Amazon, down from $169.99. That's 47% off and $80 saved on a pair of wireless on-ear headphones from one of the most recognizable names in audio. The Major V is Marshall's take on a long-lasting everyday headphone. The headphones deliver 100+ hours of wireless playtime, which puts them in a completely different category from most Bluetooth headphones that hover around 30-40 hours. You’re charging this thing once a week at most, and with wireless charging supported, you don’t have to worry about additional cables. Marshall promises its signature sound profile, with strong bass, smooth mids, and clear highs. There’s a customizable M-button, which you can set to quickly access Spotify Tap, your EQ settings, or a voice assistant. The design is foldable and lightweight at 186 grams, so it’s easy to pack for travel. And finally, the faux leather finish gives the Major V a sleek, premium look. At $89.99, the Major V Midnight Blue is a genuinely strong buy for anyone who wants a reliable daily headphone without paying premium prices. It’s also worth mentioning that the Cream and Brown variants are also discounted to $89.99, though from a lower original price of $99.99. Marshall Major V Midnight Blue - $89.99 | 47% off on Amazon This Amazon deal is US-specific and not available in other regions unless specified. This is a first-party seller link (at the time of article publishing); ensure that you also purchase from a first-party seller link only. If you don't like it or want to look at more options, check out the previous deals that we have covered, OR you can also visit Amazon US deals page. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • +1 on XVI. I still use it. 
    • Age 16, old enough to get a full-time job, your own bank account, a passport, get married, even join the military and go to war. But talking to your friends on the internet? Oh hell no!
    • I remember when all games had demos; it was a normal thing, not a limited time promotion.
  • Recent Achievements

    • Reacting Well
      Almohandis earned a badge
      Reacting Well
    • First Post
      Cosminus earned a badge
      First Post
    • One Year In
      ThatGuyOnline earned a badge
      One Year In
    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      483
    2. 2
      +Edouard
      185
    3. 3
      PsYcHoKiLLa
      122
    4. 4
      Steven P.
      84
    5. 5
      neufuse
      73
  • Tell a friend

    Love Neowin? Tell a friend!