Skip to content
Snippets Groups Projects
Commit 04d26b53 authored by Ivar Farup's avatar Ivar Farup
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #263289 failed with stages
in 32 seconds
# Files and folders to be ignored by git
# IntelliJ specific files and folders
.idea/
*.iml
out/
# Maven
target/
# Oblig 3 - Card Game
Bruk dette prosjektet som utgangspunkt for Oblig 3 i IDATG2003.
I Oppgave 1, der du får oppgitt koden til klassen PlayingCard, gjør som følger:
1. Klon dette repositoriet i GitHub til mappen på din harddisk der du ønsker å jobbe videre med denne oppgaven.
1. Følg deretter oppgaveteksten steg for steg.
**NB!** Du må endre goupID og artifactID i pom-filen til noe du mener passer.
**Tips for IntelliJ:** Gå i menyen ***"View->Tool Windows->TODO"***.
Da får du opp et TODO-vindu nederst i IntelliJ. Dette vinduet viser
samtlige steder i koden der det er skrevet inn "TODO:". En grei måte
å legge inn små "huskelapper" til seg selv.
Husk å commit-e med jevne mellomrom.
LYKKE TIL!
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- TODO: Sett din egen groupID og artifactID -->
<groupId>velg.en.fornuftig.groupID</groupId>
<artifactId>CardGame</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- TODO: Sett dine dependencies for JavaFX og JUnit5-testing -->
<!-- TODO: Sett riktig versjon av nødvendige plugins -->
</project>
package no.ntnu.idatx2003.oblig3.cardgame;
/**
* Represents a playing card. A playing card has a number (face) between
* 1 and 13, where 1 is called an Ace, 11 = Knight, 12 = Queen and 13 = King.
* The card can also be one of 4 suits: Spade, Heart, Diamonds and Clubs.
*
* @author ntnu
* @version 2021-03-13
*/
public class PlayingCard {
private final char suit; // 'S'=spade, 'H'=heart, 'D'=diamonds, 'C'=clubs
private final int face; // a number between 1 and 13
/**
* Creates an instance of a PlayingCard with a given suit and face.
* The face value is an integer between 1 and 13, where 11 represents the jack,
* 12 represents the queen and 13 represents the king. The Ace is represented by the
* number 1.
*
* <p>If the suit or face are invalid, an {@code IllegalArgumentException} is thrown.</p>
*
* @param suit The suit of the card, as a single character. 'S' for Spades,
* 'H' for Heart, 'D' for Diamonds and 'C' for clubs
* @param face The face value of the card, an integer between 1 and 13
* @throws IllegalArgumentException if suit or face have invalid values.
*/
public PlayingCard(char suit, int face) {
if (suit != 'H' && suit != 'D' && suit != 'C' && suit != 'S') {
throw new IllegalArgumentException("Parameter suit must be one of H, D, C or S");
}
if (face < 1 || face > 13) {
throw new IllegalArgumentException("Parameter face must be a number between 1 to 13");
}
this.suit = suit;
this.face = face;
}
/**
* Returns the suit and face of the card as a string.
* A 4 of hearts is returned as the string "H4".
*
* @return the suit and face of the card as a string
*/
public String getAsString() {
return String.format("%s%s", suit, face);
}
/**
* Returns the suit of the card, 'S' for Spades, 'H' for Heart,
* 'D' for Diamonds and 'C' for clubs.
*
* @return the suit of the card
*/
public char getSuit() {
return suit;
}
/**
* Returns the face of the card (value between 1 and 13).
*
* @return the face of the card
*/
public int getFace() {
return face;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PlayingCard otherCard = (PlayingCard) o;
return getSuit() == otherCard.getSuit() && getFace() == otherCard.getFace();
}
@Override
public int hashCode() {
int hash = 7;
hash = 31 * hash + getSuit();
hash = 31 * hash + getFace();
return hash;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment