Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CardGame
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
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
Nathalie Graidy Andreassen
CardGame
Merge requests
!3
Resolve "Oppgave 2"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Oppgave 2"
2-oppgave-2
into
main
Overview
0
Commits
2
Pipelines
0
Changes
1
Merged
Nathalie Graidy Andreassen
requested to merge
2-oppgave-2
into
main
1 year ago
Overview
0
Commits
2
Pipelines
0
Changes
1
Expand
Closes
#2 (closed)
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
a09d3f68
2 commits,
1 year ago
1 file
+
37
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/main/java/no/ntnu/idatt2003/demo/DeckOfCards.java
0 → 100644
+
37
−
0
Options
package
no.ntnu.idatt2003.demo
;
import
java.util.ArrayList
;
import
java.util.Collections
;
/**
* Represents a Deck of cards, in an arraylist containing playing cards.
*/
public
class
DeckOfCards
{
private
final
ArrayList
<
PlayingCard
>
deckOfCards
;
/**
* Instantiates a new Deck of cards.
*/
public
DeckOfCards
()
{
deckOfCards
=
new
ArrayList
<
PlayingCard
>();
}
/**
* Fills deck array list, with playing card objects. The method uses a two-dimensional loop to
* through every possible combinations of playing cards and adds them to the deck of cards.
* The method uses Collections shuffle to make sure the order of the playing cards are random.
*
* @return deckOfCards (array list)
*/
public
ArrayList
<
PlayingCard
>
FillDeck
()
{
char
[]
suits
=
{
'S'
,
'H'
,
'D'
,
'C'
};
for
(
char
suit
:
suits
)
{
for
(
int
value
=
1
;
value
<=
13
;
value
++)
{
deckOfCards
.
add
(
new
PlayingCard
(
suit
,
value
));
}
}
Collections
.
shuffle
(
deckOfCards
);
return
deckOfCards
;
}
}
Loading