ACS-1903-050-F2023 Assignment 3

.pdf

School

University of Winnipeg *

*We aren’t endorsed by this school

Course

1903

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

13

Uploaded by BaronDinosaur975

Report
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.
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
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