Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DeckOfCards
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
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
Steven Ha
DeckOfCards
Merge requests
!2
Created PlayingCard class
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Created PlayingCard class
master
into
main
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Steven Ha
requested to merge
master
into
main
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
38dd76d2
1 commit,
1 year ago
1 file
+
82
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/main/java/edu/ntnu/idatt2003/PlayingCard.java
0 → 100644
+
82
−
0
Options
package
edu.ntnu.idatt2003
;
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
;
}
}
\ No newline at end of file
Loading