Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VildeOblig3
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vilde Enger Gravdal
VildeOblig3
Commits
04d26b53
Commit
04d26b53
authored
10 months ago
by
Ivar Farup
Browse files
Options
Downloads
Patches
Plain Diff
initial commit
parents
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Master
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+9
-0
9 additions, 0 deletions
.gitignore
README.md
+17
-0
17 additions, 0 deletions
README.md
pom.xml
+22
-0
22 additions, 0 deletions
pom.xml
src/main/java/no/ntnu/idatx2003/oblig3/cardgame/PlayingCard.java
+90
-0
90 additions, 0 deletions
...n/java/no/ntnu/idatx2003/oblig3/cardgame/PlayingCard.java
with
138 additions
and
0 deletions
.gitignore
0 → 100644
+
9
−
0
View file @
04d26b53
# Files and folders to be ignored by git
# IntelliJ specific files and folders
.idea/
*.iml
out/
# Maven
target/
This diff is collapsed.
Click to expand it.
README.md
0 → 100644
+
17
−
0
View file @
04d26b53
# 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!
This diff is collapsed.
Click to expand it.
pom.xml
0 → 100644
+
22
−
0
View file @
04d26b53
<?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>
This diff is collapsed.
Click to expand it.
src/main/java/no/ntnu/idatx2003/oblig3/cardgame/PlayingCard.java
0 → 100644
+
90
−
0
View file @
04d26b53
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
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment