首页 > > 详细

辅导 JavaObject-Oriented Programming

SoftEng 281: Object-Oriented Programming
Assignment 3 (15% of final grade)
Due: 9:00pm, 16th May 2022 (Start of Week 10)
Learning outcomes
The purpose of this assignment is to target the following learning outcomes:
• Gain confidence modelling an object-oriented programming (OOP) problem.
• Gain confidence in applying OO Design Patterns
• Apply OOP concepts such as inheritance, polymorphism, and encapsulation (information hiding).
1 The SOFTENG 281 Black Jack
In this assignment, you will implement a BlackJack game! You will also implement some Artificial Intelligence (AI)
that will play against you! Can you implement an AI smarter than a Human player? Let’s find out in this assignment.
We will implement a very simplified (and modified) version of BlackJack (no doubling or splitting). The rules are
as follows:
1. The goal of blackjack is to defeat the Dealer’s hand without going over 21.
2. We play with a standard 52 cards deck, which has 13 cards of each suit, namely clubs (♣), diamonds (♢),
hearts (♡) and spades (♠). Each suit has 13 cards: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King.
3. Jack, Queen, King are worth 10 (rank = 10). Aces are worth 1 or 11, whichever makes a better hand. The
ranks of the remaining cards are their corresponding numbers.
4. The game has 4 participants: 3 players (“Player1”, “Bot1”,“Bot2’) and one dealer. The three players are
you and two AI Bots. At each round the players will play in the given order: “Player1”, “Bot1”,“Bot2”, and
“Dealer”.
5. Before the hand starts, a player bets between 1 and 100 chips.
6. Each player’s hand starts with two cards. The ranks of these two cards are summed together. This is the
current score of the hand. For example:
7. Then the player can ’hit’ to ask for another card, or ’hold’ to hold the total and end the turn.
8. If the total goes over 21, the player is busted, and the player losses regardless of the Dealer’s hand.
The total score is 24 (>21), the player is busted and loses the bet. No matter if also the Dealer
will be busted, the player losses anyway.
9. If the player has 21 from the start:
this a BlackJack and the player wins only if the Dealer will not
also get a BlackJack. If both the player and the Dealer get BlackJack (21 with exactly two cards) the Dealer
will win. If the player gets BlackJack and the Dealer gets a score of 21 with 3 or more cards the player wins.
10. Expect the case mentioned above (player has blackjack and Dealer has a total score of 21 with three or more
cards), if the player has a hand with an equal or smaller score than the one of the Dealer AND the Dealer is
not busted, the Dealer will win.
11. Then is the turn of the other players.
12. When all the players finish their turn, the Dealer plays. When the Dealer finishes playing the hand, we need
to check which players won against the Dealer. After that, a new round will start (if the user decides so).
You have been given an incomplete (but working) version of the game. We implemented the command line interface
for you and some utilities classes (creating the Deck of cards, checking the current score, asking for user inputs,
etc...). You need to use Object-Oriented Programming to implement the bots’ and Dealer’s AI, and print the Game
statistics, following the instructions given in this handout.
More specifically, you have three tasks to complete. Some classes should not be modified, but you need to inspect
them to understand how the game is implemented. Other classes (when specified) should be modified. You are
encouraged to add helper methods or instance fields to these classes where necessary to structure and simplify code,
but you should not change any existing method declarations (except when specified). Note that you also
need to add new classes to implement the different behaviours of the bots and the Dealer.
We recommend using Eclipse for doing the assignment (see Section 3), and using the Maven wrapper before submitting
to check that everything compiles fine and the test cases pass. Let’s begin!
2 Files provided
maven wrapper ( mvnw for Unix/Mac OS and mvnw.cmd for Windows). This file will allow you to build and run this
assignment. We will use a Maven wrapper to guarantee that we all have a common configuration to run and
test the assignment. You can either build and run the code in your machine with the Maven wrapper via the
command line or in Eclipse (https://softeng281.digitaledu.ac.nz/resources/maven-wrapper-eclipse).
Ultimately, once you finish your project and before you submit, you will want to ensure that your project
compiles without errors and passes the test cases using the Maven wrapper via the command line. This is how
your project will be marked. There are four main Maven commands relevant to this assignment:
clean ( ./mvnw clean for Unix/Mac OS and .\mvnw.cmd clean for Windows) Removes the Java binary files
(*.class) by clearing the target directory into which Maven normally builds your project. Running clean
periodically is useful, for example to remove those .class files referring to deleted or renamed Java source
files.
compile ( ./mvnw compile for Unix/Mac OS and .\mvnw.cmd compile for Windows) Compiles the Java
classes (will only compile the Java source files that have changed from the previous build). Run this
command before starting the assignment to make sure that is compiling correctly. You should see a Build
Success:
2
[ INFO ] ------------------------------------------------
[ INFO ] BUILD SUCCESS
[ INFO ] ------------------------------------------------
[ INFO ] Total time : 1.007 s
[ INFO ] Finished at : 2022 -02 -13 T16 :06:39+08:00
[ INFO ] ------------------------------------------------
test ( ./mvnw test for Unix/Mac OS and .\mvnw.cmd test for Windows) Compiles the Java classes and
runs the test cases (will only compile the files that have changed from the previous build).
exec:java ( ./mvnw exec:java for Unix/Mac OS and .\mvnw.cmd exec:java for Windows) Compiles the
Java classes and executes the Main class, which will launch the application.
Note that the first time you run the wrapper might take some time (a couple of minutes) to download
the required libraries and dependencies.
You can append commands together. For example, ./mvnw clean test for Unix/Mac OS and
.\mvnw.cmd clean test for Windows execute the clean command followed by the test command.
For more information about Maven, visit the related page in our course website https://softeng281.
digitaledu.ac.nz/topics/development-environment/.
src/main/java/nz/ac/auckland/se281/a3/BlackJack.java This class is the entry point of the game. You may add
to this file if you want to, but do not change the existing methods unless it is specified. You must modify
this class to complete all the three tasks.
src/main/java/nz/ac/auckland/se281/a3/Card.java This class declares a Card instance, which is composed of a
rank and a suit. Note that the class relies on Enums. For defining constants, Java Enums are usually preferable
instead of static final int or String variables. This leads to less error-prone code because with enum only
the applicable values can be used. Instead, if we use Strings for constants, any (wrong) String value can be
erroneously used. You are not allowed to modify this class.
src/main/java/nz/ac/auckland/se281/a3/Deck.java This class defines the Deck of cards and allows basic operations
like drawing a card and shuffling the deck. You are not allowed to modify this class.
src/main/java/nz/ac/auckland/se281/a3/Participant.java This class defines a Participant of the game, who
can be either a Player or a Dealer. The class is abstract, and thus cannot be instantiated. This means that
you cannot do Participant p = new Participant();. The purpose of this abstract class is to function as a
base class implementing common behaviours (to avoid repeated code) and defining a common interface (with
abstract methods). The classes Player and Dealer extend the Participant class inheriting its functionalities.
You are not allowed to modify this class.
src/main/java/nz/ac/auckland/se281/a3/Player.java This class defines a player of the game, which can be either
a Human (you) or a Bot. The Dealer is not a player, it is a game participant. You can (and should) add new
fields and/or methods
src/main/java/nz/ac/auckland/se281/a3/Human.java This class defines the Human player of the game. It decides
the actions based on the input from the command line. You are not allowed to modify this class.
src/main/java/nz/ac/auckland/se281/a3/bot/Bot.java This class defines a bot that plays automatically. The
Bot has the same objective as you, defeating the Dealer. You must modify this class to complete Task 1.
src/main/java/nz/ac/auckland/se281/a3/dealer/Dealer.java The goal of the Dealer is to defeat the players. You
must modify this class to complete Task 2.
src/main/java/nz/ac/auckland/se281/a3/Hand.java This class represents a hand of the game. Each participant
of the game has associated the current hand. Each hand is unique to a participant and contains information
about the amount of chip that the corresponding player has bet. You are not allowed to modify this class.
src/test/java/nz/ac/auckland/se281/a3/BlackJackTestSuite.java This Java file contains the JUnit test cases
for this assignment. These test cases make sure that you have implemented most of the assignment correctly.
3
Making sure that your program passes all of the tests you have been given will not guarantee that you will
get full marks for this assignment, but it will mean that you get at least half of the marks for the parts
that work according to those tests. In fact, we only provided to you half of the test cases that we will use
for marking your assignment. Because we wanted to give you freedom in designing the application following
object-oriented concepts, these are not traditional JUnit test cases like those used in assignment 1. They do
not directly invoke the code (as we don’t know how you are going to implement it, which classes and methods
you will create, etc...). Instead, they test the application from the command line interface, simulating a player
typing the commands with the keyboard and observing the result shown on the screen.
Writing your own tests or extending the ones you have been given is recommended. Add them inside
BlackJackTestSuite.YourTests, which you can find at the bottom of the test class. You also need to
uncomment each Test Suite Classes near the top of the BlackJackTestSuite.java file.
@RunWith ( Suite . class )
@SuiteClasses ({ BlackJackTestSuite . Task1Test .class , //
BlackJackTestSuite . Task21Test .class , //
BlackJackTestSuite . Task3Test .class , //
// BlackJackTestSuite . YourTest . class // <- UNCOMMENT HERE
})
You can have a look at the existing tests to understand how to write your own tests.
Note that we also provide additional “hidden” files (those starting with “.”)—you need to change the folder options
to be able to see them. We provide a .gitignore file that specifies intentionally untracked files that Git should
ignore, and .mvn a folder containing the Maven wrapper. You should not change these files, and you should not
delete them.
3 Hot Tip: Eclipse JUnit Integration
While you still need to check that your code works using the Maven wrapper, you can work more efficiently in
Eclipse using its JUnit integration. In particular, you can execute test cases individually. See the course website on
how to use the JUnit GUI in Eclipse https://softeng281.digitaledu.ac.nz/resources/junit-eclipse/.
Important: If you want to run the test case with the debug mode of Eclipse, you need to temporarily comment
the check if the test cases cannot run more than 10 seconds. Just comment the following two lines of code in the
abstract TaskTes class in BlackJackTestSuite.java.
public abstract static class TaskTest {
...
// as mentioned in the handout , your test cannot run more than 10 seconds
@Rule // comment if you want to run the debug
public Timeout timeout = new Timeout (10 , TimeUnit . SECONDS ) ; // comment if you want
to run the debug
Remember to restore them before the final submission to check that all of your test cases run within 10 seconds.
4 Object-Oriented Programming and Design Patterns
For this assignment, you should use the OO programming concepts and (two) Design Patterns that we covered in
class. As such, you should create appropriate classes and objects. We are giving you complete freedom on how to do
the OO design. You will decide how many and which Java classes to create. However, to be sure that you are using
design patterns, you are requested to do the following.
4
Your should use the Strategy design pattern to implement the different Bot’s
behaviours. Also you should use the Factory design pattern to initialize the
Strategy of the bot based on the user input
————————————– AND ————————————–
Your should use the Strategy design pattern to implement the different
Dealer’s behaviours and change them at runtime.
Later sections of this handout will provide more information. You can choose to use either “interfaces” or “abstract
classes”; it is up to you. You can choose the one that you think is more suitable for your implementation!
5 Tasks
Before proceeding with the tasks, read the code provided to you and start to familiarise yourself with the commandline
interface, and play the game. To run the application in Eclipse, run the Main class. With the Maven wrapper
( ./mvnw exec:java for Unix/Mac OS and .\mvnw.cmd exec:java for Windows) or with Eclipse by right-clicking
the class Main.java → run As → Java Application.
The version of the game that was given to you is a working version, but the Dealer and bots naively always HOLD
after getting two cards. So it is very easy to defeat the Dealer, and perform better than the two bots.
Let’s play together a round.
Figure 1:
Let’s bet 30 chips. The first two randomly picked cards. They have a total score of 6 (2+4), which is
quite far from 21. As such, we decide to HIT and get another card, by typing the command “hit” and press “Enter”.
5
The third card is
J

J
. The total score is 16 (not that bad). We know that the bots and the Dealer are not that
smart, so we decide to HOLD by entering “hold” so we will not risk going over 21 with another card.
Then, it is the turn of the two bots. In the current implementation, they always HOLD no matter which cards they
receive.
Figure 2:
Then, it is the turn of the Dealer. In the current implementation, it always HOLD no matter which cards it receives.
Figure 3:
The dealer’s score is greater than the ones of the bots, so the Dealer wins against both of the Bots. However, the
dealer score is 13, which is less than our score of 16. So we win! It is not very funny... the game is too easy :( Let’s
make the bots and the Dealer smarter with the help of OO and Design Patterns!
6
5.1 Add Bot Behavior [Task 1: 3%]
As soon as you compile and run the tests (using Eclipse to run the BlackJackTestSuite class), you will notice the
following output:
With the Maven wrapper:
[INFO]
[ERROR] Tests run: 7, Failures: 7, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.576 s
[INFO] Finished at: 2022-04-08T17:59:56+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.0:test (default-test)
on project a3-student: There are test failures.
With the JUnit integration of Eclipse:
This is telling you that 7 test cases were ran, none of them passed, and all of them failed. In the output, you will
find more details on which particular tests failed.
You can get the information about what is the expected behavior of each test case by reading the test case
implementation or by reading the console output of the test case.
You will see that in the file nz.ac.auckland.se281.a3.bot.Bot.java, the BOTs always return HOLD and always bet
1.
/** you should change this class for TASK 1 */
public class Bot extends Player {
public Bot ( String name ) {
super ( name ) ;
}
@Override
public Action decideAction ( Hand hand ) {
return Action . HOLD ;
}
@Override
public int makeABet () {
return 1;
}
}
7
You should implement three strategies for the bots.
• Random The Bot randomly chooses the action HOLD and HIT and it randomly bets between 1 and 100 chips
(inclusive). (HINT: You should use the JDK java.util.Random class )
• LowRisk It “holds"" if the current hand has a score of at least 17, “hits” otherwise. It bets from 10 to 50
chips (inclusive).
• HighRisk It “holds"" if the current hand has a score of at least 19, “hits” otherwise. It bets from 50 to 100
chips (inclusive).
Note that the game stores the players in the players instance field of the BlackJack instance.
public BlackJack ( Deck deck ) {
this . deck = deck ;
players = new ArrayList < >() ;
players . add ( new Human (" Player1 ") ) ; // add the Human player first .
}
The bots are created and inserted in the players list in the method initBots.
/**
* TODO This method initializes the Bots , you should change this method for
* Task1
*/
protected void initBots () {
Bot bot1 = new Bot (" Bot1 ") ;
Bot bot2 = new Bot (" Bot2 ") ;
// String botStrategyString = getBotStrategy (); // UNCOMMENT THIS FOR TASK 1
players . add ( bot1 ) ; // do not remove or change this
players . add ( bot2 ) ; // do not remove or change this
}
Note that the other of the player in the list is important, do not change it. The order is "Player1", "Bot1", and
"Bot2". If you uncomment the line String botStrategyString = getBotStrategy(); the game now asks for the
Bot strategy right at the beginning.
Note that you can change the order of the line String botStrategyString = getBotStrategy(); . For example:
/**
* TODO This method initializes the Bots , you should change this method for
* Task1
*/
protected void initBots () {
String botStrategyString = getBotStrategy () ;
Bot bot1 = new Bot (" Bot1 ") ;
Bot bot2 = new Bot (" Bot2 ") ;
players . add ( bot1 ) ; // do not remove or change this
players . add ( bot2 ) ; // do not remove or change this
}
8
The game asks for the strategy only once as it will be the same for both Bots and will never change across rounds.
You need to implement the three different strategies using the Strategy Design Pattern as discussed in class. In
other words, the Bot.java class needs to decide the action and amount of bet based on the selected strategy. Note
that the strategies will not change at runtime. However, we want to use still use the Strategy pattern as in the
future (not for this assignment) you might decide to change the strategy at runtime.
Also, you need to use the Factory Design Pattern to create the Strategy instance based on the user input: random
(“R”), low risk (“LR”), or high risk (“HR”).
When the test cases for Task 1 pass and you are confident you implemented the strategy correctly you can move on
to the second Task.
5.2 Add Dealer Behavior [Task 2: 4%]
Go to the top of BlackJackTestSuite.java, and uncomment BlackJackTestSuiteTestSuite.Task2Test.class.
@RunWith ( Suite . class )
@SuiteClasses ({ BlackJackTestSuite . Task1Test .class , //
BlackJackTestSuite . Task2Test .class , //
// BlackJackTestSuite . Task3Test .class , //
// BlackJackTestSuite . YourTest . class //
})
You will get 10 failing test cases. Currently, the Dealer always holds no matter what. Note that the Dealer does not
bet because it is not a player of the game.
public class Dealer extends Participant {
public Dealer ( String name ) {
super ( name ) ;
}
@Override
public Action decideAction ( Hand hand ) {
return Action . HOLD ;
}
}
You need to implement two strategies for the Dealer (following the Strategy Design Pattern). Note that, at
each round, the Dealer plays after all three players, so it knows the hands of the players (the Dealer strategies need
to have access to the instance field players of BlackJack) .
• Target the Highest Bidder The Dealer wants to win the player with the highest bet. If multiple bots have
placed the same highest bet, the Dealer chooses the player as ordered in the players list (the order is "Player1",
9
"Bot1", and "Bot2"). For example, let’s say that "Player1" bet 5, "Bot1" 56, and "Bot2" 20 chips. Then, the
Dealer wants to defeat "Bot1" because is the one with the highest bet. As another example, "Player1" bet 90,
"Bot1" 90, and "Bot2" 89 chips. Then, the Dealer wants to defeat "Player1" because is the one with the highest
bet and comes before "Bot1" in the players list (which bet the same amount of chips in the current round).
• Target the Top Winner The game has multiple rounds, and terminates when the player decides so. In each
round, there could be only two outcomes for a given Player, a Player wins or losses. After each round we can
then compute the net-wins = # rounds won - # rounds lost. This strategy targets the player with the
highest net-wins. Like the previous strategy, if two or three players have the same highest net-wins, the
Dealer selects a player based on their order in the players list. For example, if "Player1" won 5 games and
lost 3, his/her net-wins is 2. Let’s say that "Bot1" also won 5 games and lost 3 and "Bot2" won 1 and lost 7.
Then, Dealer wants to defeat "Player1" in this round because it is the highest net-wins and comes before
"Bot1" in the players list ("Bot1" won and lost the same number of rounds pf "Palyer1").
For example, let’s assume that the Dealer strategy is Targeting the Highest Bidder. We play 100 chips and
decide to hold after two cards.
"Bot1" decides to "hit" and got busted (the score is greater than 21).
"Bot2" holds when reaching 19.
10
Now is the turn of the Dealer, which knows the results of all three hands. The highest bidder is "Player1" so it only
cares about defeating him. Because the Dealer has the same score with "Player1" it decides to HOLD because when
a player and a dealer have the same score the Dealer always wins.
Note that the Dealer does not care about the scores of the other two players (indeed, if the Dealer holds at 12, them
it losses against "Bot2"). Let’s assume that "Player1" was busted the Dealer would have also HOLD because it is
already winning "Player1".
For both strategies, it could be the case that the targeted player did BlackJack and the Dealer first two cards did
not give blackjack. In such a case, it is impossible for the Dealer to win. According to our game rules (see the first
two pages of the handout), if the Dealer gets 21 with more than two cards and the player gets BlackJack, the
player always wins. In such a case, the Dealer will hold if its total score is at least 17, HIT otherwise.
Differently from the Bot strategies, the dealer strategies are not chosen by the user via command line. At the
beginning of the game, Dealer uses the Targeting the Highest Bidder. The game changes the strategy to
Target the Top Winner whenever there is at least one player with a net-wins greater than or equal to 2. It will
go back to the Targeting the Highest Bidder strategy, if no longer there is a player with a net-wins greater
than or equal 2. For example, let’s consider the following game.
----- The dealer starts with "Targeting the Highest Bidder" strategy
Round 1: Player1 lost $100
Round 1: Bot1 lost $85
Round 1: Bot2 won $58
----- highest net-wins is 1 (Bot1) the strategy does not change
Round 2: Player1 won $90
Round 2: Bot1 lost $8
11
Round 2: Bot2 lost $7
---- highest net-wins is 0 (Player1 and Bot1) the strategy does not change
Round 3: Player1 won $90
Round 3: Bot1 won $2
Round 3: Bot2 lost $23
---- highest net-wins is 1 (Player1) the strategy does not change
Round 4: Player1 won $4
Round 4: Bot1 won $9
Round 4: Bot2 lost $24
---- highest net-wins is 2 (Player1) is >=2 so next round the strategy of the
---- Dealer will change to "Target the Top Winner" (Player1 in this case)
Round 5: Player1 lost $100
Round 5: Bot1 won $90
Round 5: Bot2 lost $5
---- Player1 lost, so her/his net-wins is 1.
---- However, Bot1 won and its net-wins is now 2, which is >=2 so next round the strategy remains
---- "Target the Top Winner" (Bot1 in this case)
Round 6: Player1 lost $4
Round 6: Bot1 lost $7
Round 6: Bot2 won $5
---- Bot1 lost so the Dealer wll go back to the strategy
---- "Targeting the Highest Bidder" because the highest net-wins is now < 2.
In the method initDealer in the class BlackJack you should set the initial strategy. This method is invoked only
once at the beginning of the game.
/**
* TODO This method initializes the Dealer , you should change this method for
* Task2
*/
protected void initDealer () {
// set the initial strategy using the Strategy pattern
dealer = new Dealer (" Dealer ") ;
}
In the method of the class BlackJack you should update the net-wins counts and decide if the strategy of the Dealer
should be changed or not.
/**
* TODO This method prints and updates the results ( wins and losses ) you should
* change this method for Task 2 and Task 3
*/
protected void printAndUpdateResults (int round ) {
}
IMPORTANT: For Task 2 and 3, you need to implement the logic to determine which "player" has won It is not
implemented in the code that we provided you. You have to follow the rules of the game explained on the first two
pages of this handout.
5.3 Print Statistics [Task 3: 2%]
Go to the top of BlackJackTestSuite.java, and uncomment BlackJackTestSuiteTestSuite.Task3Test.class.
12
@RunWith ( Suite . class )
@SuiteClasses ({ BlackJackTestSuite . Task1Test .class , //
BlackJackTestSuite . Task2Test .class , //
BlackJackTestSuite . Task3Test .class , //
// BlackJackTestSuite . YourTest . class //
})
You will get six failing tests cases.
The last task is to print some statistics about the game. After each round you need to print, for each player, the
amount of chip win or lost.
For example,
Round 5: Player1 lost 5 chips
Round 5: Bot1 lost 99 chips
Round 5: Bot2 lost 79 chip
The result of each round should be print exactly like this
"Round" white space round number : white space “Player1” white space “lost” or “won” amount of bet white space “chips”
"Round" white space round number : white space “Bot1” white space “lost” or “won” amount of bet white space “chips”
"Round" white space round number : white space “Bot2” white space “lost” or “won” amount of bet white space “chips”
Note that “Player1”, “Bot1”, and “Bot2” are the name attribute of the class Participant (you should not hardcode
them). You can print the above inside the method printAnUpdateResults, which already give you the current round
number.
/**
* TODO This method print and update the results ( wins and losses ) you should
* change this method for Task 2 and Task 3
*/
protected void printAnUpdateResults (int round ) {
}
Also, you should print the game statistics at the end, when the user decides not to continue to play. You should give
the total amount of won and lost games for each player. For example,
Player1 won 1 times and lost 2 times
Bot1 won 0 times and lost 3 times
Bot2 won 2 times and lost 1 times
The summary of all rounds should be print exactly like this
“Player1 won” # times won white space “times and lost” white space # times lost white space “times”
“Bot1 won” # times won white space “times and lost” white space # times lost white space “times”
“Bot1 won” # times won white space “times and lost” white space # times lost white space “times”
You should print the game statistics inside the method printGameStatistics, which is invoked when the game ends.
/**
* TODO This method should print the statistic of the game when it ends
*/
protected void printGameStatistics () {
}
13
6 Hot Tip: StackOverflow.com
The website www.StackOverflow.com (SO) is the best friend of every software developer, no matter if you are a
novice or an expert developer. Even expert developers visit SO many times per day! You are encouraged to do so.
For example, for the Random strategy, you need to return a random integer between 1 and 100 (inclusive). You
can take inspiration from https://stackoverflow.com/a/5271613, which is answering a similar question, using the
class java.util.Random.
Important. While you are encouraged to use StackOverflow to find inspiration to resolve common and general
programming problems, you should consider the following:
• If you reuse/adapt some code snippets from StackOverflow you have to put an attribution. For example, by
adding the comment:
// code adapted from https :// stackoverflow .com /a /5271613
This is not only a good practice, but it also protects your code from being flagged as plagiarized.
• It is very important to always read the description of the code carefully and always try and test the code
before using it. Especially in Stackoverflow.com, never just copy and paste code. Often there are multiple
answers to the same question, you need to understand the one that is suitable in your case. Likely, you also
need to adapt the solution. For example, the beginning of the answer says that
You could use e . g . r . nextInt (101)
This is not the right solution in our case because it would return a number between 0 and 100 (inclusive),
while we want a number between 1 and 100 (inclusive). Also, in general r is not a good name for a variable;
rnd or random are better choices in this case.
7 Important: Rules and remarks
1. See the “Final Submission” section below for details you need to follow to ensure your code is submitted
correctly.
2. Your code will be marked using a semi-automated setup. If you fail to follow the setup given, your code will
not be marked. All submitted files must compile without requiring any editing. Use the provided tests and
maven wrapper to ensure your code compiles and runs without errors. Any tests that run for longer than 10
seconds will be terminated and will be recorded as failed.
3. We encourage you to write high-quality code by following good Java code conventions. In this assignment, we
will mark your code style. On our website, you can find what are the aspects of code style that we will mark
https://softeng281.digitaledu.ac.nz/resources/code-conventions-best-practices/.
4. Do not move any existing code files to a new directory.
5. You cannot add and use external libraries. You can only use external classes that belong to the JDK (the
import statement starts with java, for example import java.util.ArrayList;).
6. To check if you implemented the design patterns correctly, we will make sure that all classes you have created
are used by the test cases. Creating classes that are not invoked by the application will not help you reach the
requirements.
7. Make sure that you do not modify the given test cases. Your code must still work with the original version of
the BlackJackTestSuiteTestSuite.java file.
8. Do not change the pom.xml file, and do not change any of the hidden files (those starting with ".").
14
9. You can create static methods (The Factory pattern requires a static method), but you should not use
static fields. The reason is twofold. First, public static fields allow to easily access variables in any method.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!