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

    • I think you meant the "ntfs3" driver, but yes there have been a lot of fixes for it in this release and previous releases, not 100% sure if the issue you mentioned is fixed though. In any case, the new "ntfs" driver in 7.1 doesn't have that issue (at least, no reports of such have come thru), but your kernel needs to explicitly enable support for the new driver first (like how CachyOS kernel has it), and you need to edit your mount points in /etc/fstab to use "ntfs" instead of the other drivers.
    • Epic Games says Unreal Engine 6 will help developers "build content faster" using AI models by Pulasthi Ariyasinghe Epic Games is rolling out the latest major update to Unreal Engine 5 today, and at the same time, the company also dropped some information on the next-generation version of the product, Unreal Engine 6. This was already revealed a few weeks ago alongside the new Rocket League upgrade reveal. The company says it is combining the features of Unreal Engine and Unreal Editor for Fortnite to create this new version of its popular media creation tool. On top of creating entire games, the new engine will also focus on letting developers operate large-scale live service titles more easily, whether by shipping content into their own ecosystems or into Fortnite. The use of large language models is also mentioned here, with Epic saying it will be a core part of the engine. "We see LLMs, generative AI models, and tools like Claude and Codex playing a central role in helping you build content faster while maintaining the creative control you need," adds the company. Here is the rundown of what's new about version 6 of Unreal Engine: With all these changes to the programming model, portability upgrades, and generative AI integration, Epic says the new version of the engine will "change a lot about how games are made." The company aims to ship Unreal Engine 6 into early access in late 2027, with a full release planned for 12-18 months later. Epic Games also dropped a lengthy blog post about the new Unreal Engine 5.8 update for game developers over here. The release is focused on delivering better performance, customization, and streamlined workflows for development teams. This will be the final major update for this version of the engine before Epic switches to focus fully on Unreal Engine 6's early access launch.
    • Watch Louis Rossmann's recent experience on YouTube about trying to get a warranty replacement from Samsung. It's crazy.
    • That is the thing, how many of these people don't realise they are using AI? If they use Google Search they have no choice but to use AI. So yes, maybe half of American adults do use and I expect a lot of Uk adults do to, but I bet most of them don't realise it. Myself, i avoid the rubbish.
    • They use FREE AI. They aren't paying for this meme-generating slopware...
  • Recent Achievements

    • One Month Later
      Vincian earned a badge
      One Month Later
    • First Post
      Jocimo earned a badge
      First Post
    • Week One Done
      suprememobiles48 earned a badge
      Week One Done
    • One Month Later
      Windows Guy earned a badge
      One Month Later
    • One Month Later
      Prasann earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      500
    2. 2
      +Edouard
      162
    3. 3
      PsYcHoKiLLa
      88
    4. 4
      Steven P.
      68
    5. 5
      neufuse
      65
  • Tell a friend

    Love Neowin? Tell a friend!