ACS-1903-050-F2023 Assignment 3
pdf
keyboard_arrow_up
School
University of Winnipeg *
*We aren’t endorsed by this school
Course
1903
Subject
Computer Science
Date
Jan 9, 2024
Type
Pages
13
Uploaded by BaronDinosaur975
ACS-1903
Assignment 3
Due by Monday, December 4 at 11:59 pm
-
Submit your .java files via Nexus
Notes:
Concepts that have not been covered in class cannot be used, for example, arrays,
BufferedReader, methods that have not been introduced (e.g. String, Collections, etc.), the
use of break (except in switch statements), exception handling except for throwing
FileNotFoundException, regular expressions, System.exit(), a return in the main method, etc.
While(true) is not acceptable, the use of a flag in the conditional statement of a loop is not
acceptable. For example, while(!isFinished).
Check with your instructor or TA if you have concerns.
Use meaningful names for variables; you must follow the camelCase naming standard.
Make sure to include a multi-line comment at the top of your code with your name and
student number.
Format your code so it is easy to read and use comments to provide extra information and
details about your code.
Ensure you have followed standard indentation practices
–
consider
using the Auto-layout feature in BlueJ. Avoid excessive use of blank lines.
Your code must scale to work for any valid input.
Total marks: 50
1.
(15 marks)
LottoMax
is a Canadian Lottery game.
7 winning numbers are chosen from a possible 1-
50, and a bonus number is also selected.
Prizes are awarded if a ticket matches at least
3 of these numbers.
Additional prize tiers are also awarded if a ticket has a match with
the bonus number
i.e., prizes are awarded for the following matches: 3 numbers, 3 numbers + bonus, 4
numbers, 4 numbers + bonus, 5 numbers, 5 numbers + bonus, 6 numbers, 6 numbers +
bonus, 7 numbers, 7 numbers + bonus. e.g.:
Winning numbers:
2, 5, 18, 26, 27, 38, 44, bonus 28
Ticket 1:
2
, 16,
18
,
26
,
38
, 42,
44
winner: 5 matches
Ticket 2:
1,
5
, 14,
26
,
28
,
38
, 49
winner: 3 matches + bonus
Ticket 3:
1, 7,
18
,
28
, 41,
44
, 46
no win (less than 3 matches)
Note that a bonus number is not a winning number e.g. for Ticket 3, there are 2 winning
number matches + 1 bonus, and NOT 3 winning number matches.
Create a program named
LottoTicketChecker
that generates a set of 7 winning
lottery numbers plus a bonus number and allows the user to check their tickets against
the winning numbers.
Simulate the selection of winning numbers, ensuring that there are no duplicates among
them.
Store these numbers in an
ArrayList
and display the numbers in ascending
order.
Select an 8th number which is considered the “bonus” number.
Your program must ask the user to enter their ticket numbers, check them against the
winning numbers, and then determine if the ticket is a winner based on the prize tiers
listed above.
Inform the user if they have a winning ticket, indicating the number of
winning number matches (+ bonus if applicable).
Include a method named
checkTicket()
that accepts the list of winning numbers,
prompts the user for their selected numbers, and displays the status: win (3 or more
winning number matches) or lose (less than 3 winning number matches).
Only display a
bonus match if they have a winning ticket.
Sample output 1:
Winning numbers: [8, 12, 22, 24, 34, 46, 48] bonus: 38
Enter your 7 ticket numbers:
3 12 22 32 33 46 48
Winner! 4 numbers
Sample output 2:
Winning numbers: [6, 15, 19, 28, 32, 33, 34] bonus: 41
Enter your 7 ticket numbers:
6 8 19 28 29 39 41
Winner! 3 numbers + bonus
Sample output 3:
Winning numbers: [1, 10, 11, 17, 22, 33, 47] bonus: 20
Enter your 7 ticket numbers:
1 9 14 19 20 33 49
Not a winning ticket :(
2.
(15 marks)
PetDriver.java
,
GrumpyCatData.txt
The Grumpy Cat Pet Rescue Shelter is updating its computerized pet tracking system.
They have asked you to write a new app that will allow them to catalogue all of the pets
that come into the shelter. Complete the following to create the pet tracking app.
a)
Create a class called
Pet.java
that will be used to instantiate objects representing
pets that are brought to the shelter. The class will include the following;
•
Five instance fields;
o
Strings
name
, and
species
.
o
boolean
vaccinated
,
true
if the pet has been vaccinated
false
otherwise. Note that snakes and fish will always be unvaccinated.
o
int
age
o
An automatically generated String
id
.
▪
All pet IDs have 7 characters, with the first 3 characters coded
by species and the last 4 characters a 4-digit auto-number, e.g.
DOG1001, CAT4803 (start auto-numbering at 1000)
Code
Species
CAT
cat
DOG
dog
HAM
hamster
SNK
snake
FIS
fish
OTH
other
•
Two constructors
o
Include both a no-arg and a parameterized constructor.
o
Note that when the species of a pet is set it should be assigned a new
id
.
•
Getters and setters for all fields.
•
Include an
equals()
method. Two pets are considered equal if they share
the same
id
.
•
Override the
toString()
method to match the sample output found
below.
b)
Add the following code to the driver file
•
Create an ArrayList of
Pet
objects called
pets
. The data file
“GrumpyCatData.txt” contains the records of
n
pets. Create and add to
the ArrayList a new Pet object from each record in the file.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
•
Print the entire ArrayList, see the sample output below. Use an enhanced
for loop to accomplish this task.
•
For code re-use and because various lists will be printed several
times create a static method to print an ArrayList of Type <Pet>
•
The following pets have been adopted. Note, that these names will be
entered from the keyboard all at once. See the sample output below.
Rufles, Lassie, Fritz, Freddy, Fluffy, Boa, Kaa, Bernard, PonderStibbins
•
Add another ArrayList to your driver code called
adopted
and move the
adopted pets from the
pets
ArrayList to the
adopted
ArrayList. Note
that your code should work for any length list of adopted pets.
•
Use a loop to get the name of each adopted pet and move it to
the
ArrayList
•
Print the list of adopted pets. See the sample output below.
•
Someone has come into the shelter and wants to adopt a dog
•
Print a list of all of the dogs who are still available for adoption.
See the sample output below.
•
The next person wants either a cat or a fish.
•
This person has decided to adopt all of the available cats and fish.
The adoption fee for cats is $100 if they are vaccinated and $50 if
they are unvaccinated, the fee for fish is $75.
o
You need not move the pet to the adopted ArrayList. But if
you want some extra challenge you can add this feature.
•
Print the list of the pets to be adopted along with the total
adoption fee. See the sample output below.
Sample output:
---------------------------------------------
Grumpy Cat Pet Rescue Pet Guest List
---------------------------------------------
DOG1000: Rufles, dog, 1, Not vaccinated
DOG1001: Lassie, dog, 2, Vaccinated
HAM1002: MacBeth, hamster, 1, Vaccinated
CAT1003: Fritz, cat, 3, Vaccinated
CAT1004: Freddy, cat, 2, Not vaccinated
SNK1005: Boa, snake, 15, Not vaccinated
FIS1006: Nemo, fish, 2, Not vaccinated
FIS1007: Ahab, fish, 2, Not vaccinated
SNK1008: Kaa, snake, 4, Not vaccinated
DOG1009: Bernard, dog, 3, Vaccinated
CAT1010: Boudica, cat, 4, Not vaccinated
CAT1011: Rincewind, cat, 1, Vaccinated
CAT1012: PonderStibbins, cat, 1, Vaccinated
DOG1013: Vimes, dog, 4, Vaccinated
DOG1014: Leela, dog, 3, Not vaccinated
---------------------------------------------
Grumpy Cat Pet Rescue
Update adopted database
---------------------------------------------
Enter the list of adopted pets
rufles lassie fritz freddy fluffy boa kaa bernard
ponderstibbins
rufles has been adopted.
lassie has been adopted.
fritz has been adopted.
freddy has been adopted.
fluffy Pet not found
boa has been adopted.
kaa has been adopted.
bernard has been adopted.
ponderstibbins has been adopted.
---------------------------------------------
Grumpy Cat Pet Rescue Adopted Alumni
---------------------------------------------
DOG1000: Rufles, dog, 1, Not vaccinated
DOG1001: Lassie, dog, 2, Vaccinated
CAT1003: Fritz, cat, 3, Vaccinated
CAT1004: Freddy, cat, 2, Not vaccinated
SNK1005: Boa, snake, 15, Not vaccinated
SNK1008: Kaa, snake, 4, Not vaccinated
DOG1009: Bernard, dog, 3, Vaccinated
CAT1012: PonderStibbins, cat, 1, Vaccinated
---------------------------------------------
Grumpy Cat Pet Rescue
Dogs available for adoption
---------------------------------------------
DOG1013: Vimes, dog, 4, Vaccinated
DOG1014: Leela, dog, 3, Not vaccinated
---------------------------------------------
Grumpy Cat Pet Rescue
Available Cats and Fish and adoption fee
---------------------------------------------
FIS1006: Nemo, fish, 2, Not vaccinated
FIS1007: Ahab, fish, 2, Not vaccinated
CAT1010: Boudica, cat, 4, Not vaccinated
CAT1011: Rincewind, cat, 1, Vaccinated
---------------------------------------------
Your total adoption fee is: $300
---------------------------------------------
end of program
Requirements and restrictions:
•
Use only Scanner variations discussed in class to get input.
•
All input should be non-case-sensitive.
•
You may use static methods to facilitate code re-use.
•
Use enhanced for loops wherever possible.
•
See the additional general notes at the top of the assignment document
3.
(15 marks)
Write a program named
PiratePlunder
that simulates a dice-roll game, where
players take turns throwing 2 dice awarding points as follows:
•
Add the rolls together
•
If the sum of the rolls is less than 4, roll a third dice and add that score
The game will continue until a player’s total score across all rolls is 50 or more.
If two
players reach a score of 50 or more, the player with the highest score wins.
If a tie
occurs, of the players with the highest scores, pick a winning player at random.
Any number of players can play this game at a time, prompting the user to enter player
names until they enter
done
.
Then, display all players who are playing the game before
it begins.
Lastly, for every round of the game, display the following:
•
The round number
•
The results of the dice throw of each player in the round, ordered from highest
to lowest score
•
Current standings of the total score per player
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Your solution
must
use parallel ArrayLists
playerName
,
roundScore
, and
totalScore.
Sample output:
Enter player names until you enter 'done'
Luffy
Enter player names until you enter 'done'
Nami
Enter player names until you enter 'done'
Zoro
Enter player names until you enter 'done'
Usopp
Enter player names until you enter 'done'
done
----------------------
Welcome: Luffy Nami Zoro Usopp
----------------------
Round 1
----------------------
Round Results:
Nami: 11
Luffy: 10
Zoro: 10
Usopp: 6
----------------------
Current Standings:
Luffy: 10
Nami: 11
Zoro: 10
Usopp: 6
----------------------
Round 2
----------------------
Round Results:
Luffy: 10
Usopp: 9
Nami: 6
Zoro: 5
----------------------
Current Standings:
Luffy: 20
Nami: 17
Zoro: 15
Usopp: 15
----------------------
Round 3
----------------------
Round Results:
Usopp: 7
Luffy: 6
Nami: 4
Zoro: 4
----------------------
Current Standings:
Luffy: 26
Nami: 21
Zoro: 19
Usopp: 22
----------------------
Round 4
----------------------
Round Results:
Zoro: 10
Usopp: 8
Luffy: 6
Nami: 5
----------------------
Current Standings:
Luffy: 32
Nami: 26
Zoro: 29
Usopp: 30
----------------------
Round 5
----------------------
Round Results:
Nami: 12
Zoro: 6
Luffy: 5
Usopp: 5
----------------------
Current Standings:
Luffy: 37
Nami: 38
Zoro: 35
Usopp: 35
----------------------
Round 6
----------------------
Round Results:
Nami: 11
Zoro: 8
Usopp: 7
Luffy: 4
----------------------
Current Standings:
Luffy: 41
Nami: 49
Zoro: 43
Usopp: 42
----------------------
Round 7
----------------------
Round Results:
Usopp: 8
Luffy: 7
Nami: 6
Zoro: 5
----------------------
Current Standings:
Luffy: 48
Nami: 55
Zoro: 48
Usopp: 50
----------------------
The winner is:
Nami with 55 points!
4.
(5 marks)
CFLDriver.java
,
cfl.txt
Develop 2 classes:
Player
and
Team
organized as
a)
The
Player
class has fields
jerseyNumber, firstName, lastName,
position, status, height, weight,
and
age
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
b)
The
Team
class has fields
code, location,
and
name
c)
Each class must have:
•
necessary constructors, getters and setters for fields as required for the program
•
a
toString()
method:
o
Player will include jersey number, first and last name
e.g.
#20 Brady Oliveira
o
Team will include location and name
e.g.
Winnipeg Blue Bombers
•
fields and methods required for the association
•
a
displayInfo()
method that displays information about each instance;
please refer to the sample output below
Complete the program
CFLDriver
that reads player data from a file and provides the
user with a search function.
Prompt the user to choose an option to search by (player or team) and info for each
according to the sample below.
Sample output:
Canadian Football League - Search
---------------------------------
Make a selection:
[A] Search for player
[B] Search for team
[C] Quit
A
Enter the team code and jersey number:
WPG 20
#20 Brady Oliveira, Winnipeg Blue Bombers
Position: Running Back
Status: National
5'10, 222 lbs., 26 years old
Make a selection:
[A] Search for player
[B] Search for team
[C] Quit
A
Enter the team code and jersey number:
EDM 87
#87 Eugene Lewis, Edmonton Elks
Position: Wide Receiver
Status: American
6'1, 208 lbs, 30 years old
Make a selection:
[A] Search for player
[B] Search for team
[C] Quit
B
Enter the team code:
WPG
Winnipeg Blue Bombers
Average height: 6'0
Average weight: 230
Average age: 29
Roster:
#37 Brandon Alexander
#27 Johnny Augustine
#88 Rasheed Bailey
#98 Anthony Bennett
#40 Mike Benson
#4 Adam Bighill
#34 Jesse Briggs
#6 Dru Brown
#66 Stanley Bryant
#47 Tanner Cadwallader
#14 Sergio Castillo
#33 Malik Clements
#41 Brian Cole
#8 Zach Collaros
#10 Nic Demski
#64 Liam Dobson
#65 Asotui Eli
#39 Kerfalla Exumé
#44 Shayne Gauthier
#80 Janarion Grant
#68 Geoff Gray
#21 Nick Hallett
#3 Thiadric Hansen
#51 Jermarcus Hardrick
#31 Evan Holm
#35 Demerio Houston
#48 Damian Jackson
#94 Jackson Jeffcoat
#5 Willie Jefferson
#67 Chris Kolankowski
#17 Redha Kramdi
#89 Kenny Lawler
#99 Cameron Lawson
#29 Greg McCrae
#53 Patrick Neufeld
#1 Deatrick Nichols
#20 Brady Oliveira
#84 Brendan O’Leary
-Orange
#7 Jamal Parker
#12 Dakota Prukop
#18 Jamieson Sheahan
#95 Jake Thomas
#9 Ricky Walker
#19 Kyrie Wilson
#82 Drew Wolitarsky
Make a selection:
[A] Search for player
[B] Search for team
[C] Quit
C
Goodbye!
Notes:
-
For
displayInfo()
methods:
o
height
will have to be parsed: use integers for working out average.
o
Refer to the following tables for Player info details:
▪
Status:
N
National
A
American
G
Global
▪
Position:
QB
Quarterback
RB
Running Back
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
FB
Full Back
WR
Wide Receiver
LB
Linebacker
DL
Defensive Lineman
OL
Offensive Line
DT
Defensive Tackle
DB
Defensive Back
DE
Defensive End
P
Punter
K
Kicker
LS
Long Snapper
-
The starter code provides 9 team instances stored in an array list.
-
The items on each line are all separated by commas.
The starter code reads in each
line, then each value (using the
useDelimiter()
method of Scanner).
Create
each player as the data is read in. As each player is created it
must be added to its
corresponding team
.
Use the team code (first value of each line eg. WPG) and the
array list of players to determine which player instance to associate it with.
______________________________________________________________________________
Submit your
java
files
(LottoTicketChecker.java, Pet.java,
PetDriver.java,
PiratePlunder
.java, Player.java, Team.java,
CFLDriver.java)
via Nexus
Related Documents
Recommended textbooks for you

Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,

EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT

C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage

C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr

Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,

EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT

C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage

C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr