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

    • You can enable the Nova redesign in Firefox 152 stable, under about:config.
    • You can enable the Nova redesign in Firefox 152, under about:config
    • As long as Manifest v2 extensions keep working. I always enable compact mode from about:config. I hope I won't have to switch to LibreWolf or WaterFox anytime soon.
    • Threads scales past half a billion users, brings deeper community and feed controls by Fiza Ali Meta has announced Threads crossing a major milestone of 500 million monthly active users. And, at the heart of this growth sits something simple: communities. From books to basketball, parenting to music, Threads says its rise has been powered by people clustering around shared interests and, in turn, giving the platform its identity. In response, the platform is expanding its Communities feature beyond beta and introducing a set of new tools designed to make participation easier and more engaging. A redesigned Communities Hub will now appear in the main navigation menu, allowing users to jump between groups without leaving their feed. Each community will also receive a distinct Community Icon, giving them clearer visual identity and making them easier to recognise across the platform. Then there’s Community Progress, which is a kind of live gauge showing how close a topic is to becoming a full-fledged community, alongside guidance on how users can contribute to its development. In addition, Meta is also expanding its Community Champions programme, recognising more users who actively contribute to community engagement. And then things go more local; Local Communities is already available in 100 countries, including North America, South America, Asia, and Europe but are now rolling out with native-language tags starting in Japan, South Korea, and Taiwan. The platform is also expanding Live Chats to more communities in the coming weeks, adding features such as co-hosting and the ability to quote moments directly into users’ feeds. Beyond communities, Meta is tightening the loop between users and their feeds. Earlier this year came "Dear Algo," a feature that lets people tell Threads what they want more or less of. Now it’s being paired with a new tool, "Your Algo." It allows people to adjust how frequently certain topics appear, with options lasting one, three, or seven days. Meta says these preferences remain private and can be managed alongside “Dear Algo” in a unified settings hub. The rollout begins in the US, Canada, UK, Australia, and New Zealand. Finally, the company says these changes are part of an ongoing effort to refine Threads based on user feedback and that further updates will continue as the platform evolves.
  • Recent Achievements

    • One Year In
      Console General earned a badge
      One Year In
    • One Year In
      Twozo Technologies earned a badge
      One Year In
    • One Month Later
      Twozo Technologies earned a badge
      One Month Later
    • Week One Done
      Twozo Technologies earned a badge
      Week One Done
    • Veteran
      branfont went up a rank
      Veteran
  • Popular Contributors

    1. 1
      +primortal
      520
    2. 2
      +Edouard
      196
    3. 3
      PsYcHoKiLLa
      110
    4. 4
      Steven P.
      89
    5. 5
      Nick H.
      71
  • Tell a friend

    Love Neowin? Tell a friend!