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

    • What people who support this position of LibreOffice do not understand is that EuroOffice is not made to appease the open source enthusiasts (I am also one) and evangelists. EuroOffice was made because some European companies wanted independence from Microsoft Office Suite, which is something installable on your computer. This move to independence was pushed by public institutions and governments in Europe, as well. Using a proprietary FORMAT as default, does not make you dependent on MS. The actual program does. A format can be changed with a simple update in the future in a dystopian world where MS would manipulate the format to lock others out. However, using MS Office proprietary format, guarantees that all the current documents used by companies, organizations, institutions, etc, will be compatible with EuroOffice and the suite will have the best chances at adoption, especially by slow moving organizations like governments and the public sector. It is as simple as that. For the same reason, even the UI is incredibly similar to MS Office. For the same reason (adoption) the choice was made to be open source. Not because EU particularly loves open source ideologically, but because it gives the best starting point to create trust in the project and amass developers and contributions to the project quickly, to catch up with proprietary projects like MS Office. I don't understand how people don't realize it.
    • How old is this tip? Seems 15-20 years old? Processor states for the CPU under Windows power options has been a thing for a long, long time. It certainly isn't new or hidden... Also, with laptops it doesn't make any difference what OS you are running, all of them are configured for battery longevity over performance, for obvious reasons.
    • I can't believe Starmer is still there...his party lost so big. He's a stubborn coot, but this is largely unenforceable, so I would imagine he'll be resigning soon. A key here is for parents to buy their kids phones sans Internet access--and set up the Internet at home, where mom and day can, you know, act like parents instead expecting the government to raise their kids.
    • EA launches in-game advertising platform for brands to "connect with audiences" by Pulasthi Ariyasinghe The gaming giant Electronic Arts is exploring more ways to inject real-life brands into its games. Announced today as EA Advertising, the new platform is attempting to make it easier for brands to reach out for deals with the company and put their products inside titles like EA Sports FC, Madden, NHL, Skate, or The Sims. EA revealed that its EA Sports side of the company brings in "hundreds of millions of players across console, PC, and mobile" every year. Fan engagement of these titles was also touted as being "extraordinary," with 23,000 NFL seasons worth of games being played in Madden NFL daily, while EA Sports FC sees over a billion matches a day. “Players come to EA’s games and live experiences every day to play, watch, create and connect,” said David Tinson, Chief Experiences Officer at Electronic Arts. “That gives brands a meaningful opportunity to show up in ways that add value and respect the player experience, while maintaining authenticity in the worlds our teams are building. With EA Advertising, we’re helping brands become part of those moments in ways that are relevant and built for players.” Using the new program EA Advertising, brands will be able to inject their products into games in real-time via dynamic placement. EA says partners will have access to everything from stadium signage in sports games and targeted adverts to in-game content custom-made for the brands. These are described as additions designed to "enhance, not disrupt" experiences. "In these interactive gameplay environments, brands become part of the game itself, reflecting how players engage with advertising in real-world contexts," adds the company "Brands can activate across live environments, tailoring placements to meet campaign objectives, and update campaigns with ongoing optimization informed by aggregated engagement insights." Current real-world brand partnerships EA has built into its games include Visa (EA Sports FC and College Football), Lowe's (EA Sports FC, Madden NFL, and College Football), Red Bull (EA SPORTS FC), Xfinity and Peacock (EA SPORTS FC), and Mountain Dew’s (College Football).
    • Will be surprised if there isn't a new ver of youtube just for labelled educational content
  • Recent Achievements

    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
    • One Month Later
      Leroy Jethro Gibbs earned a badge
      One Month Later
    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      512
    2. 2
      +Edouard
      204
    3. 3
      PsYcHoKiLLa
      136
    4. 4
      ATLien_0
      91
    5. 5
      Steven P.
      85
  • Tell a friend

    Love Neowin? Tell a friend!