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.
•
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
Related Questions
Discussion Purpose:
A discussion of the topic will reinforce the learning objectives of this lecture as students will research the topic and thereby enhance their learning and level of understanding. The interaction of ideas here will also be a healthy exposure to different perspective on the topic.
Discussion Topic:
A runtime Java system searches for exception handlers in call stack and terminates the program when it can't find one. The use of Exceptions to handle errors mitigates a lot of program interruptions. Examine and write some of the advantages of Exception handling.
arrow_forward
Python code for the scenario is attached however I'm not just after the code I need also an explanation for all the step your taking when coding this in other work if you are doing a presentation of this to a group of people what are you tell them
Analysis:(Describe the problem including input and output in your own words.)
UML Class Diagram
Algorithm Design: (Describe the major steps for designing the algorithm, for this problem-solving.)
Input Validation and Exception Handling in the code
Console and Graphical User Interface
Code dump/listing
Test Plan: (Evidence of testing)
Application Testing screenshots
arrow_forward
1.class Nothing {public static void main(String args[]){int x = 0;int y = 20;int fraction = y/x;System.out.println("End Of Main");}}1. If there will occur exception, write the code that will handle the exception.
arrow_forward
Java Foundations :
Please provide code and explain. Thank you.
Write the code segments in main( ) and in methodA( ) for the following scenario:
main( ) passes methodA an int variable called a.
methodA generates an exception, but does not deal with it, if a is not between 1 and 100.
arrow_forward
Solve this according to exception handling and file management of Java prograam.
arrow_forward
Write the code in java and understand what the question says and give me the code and don't copy or plagiarize please
arrow_forward
Explain Rethrow (propagate) exception with help of code.
arrow_forward
JAVA EXCEPTION HANDLING Complete the java code below according to the instructions given. Also use the test example below:
Define the exceptions that are necessary to catch the possible errors that can occur in the class Matrix
• ExceptionWrongMatrixValues that is thrown in the method read() if the data on the String does not correspond to numeric values, or if the data are not consistent with the form of a matrix (e.g., the rows have different length);
• ExceptionWrongMatrixDimension that is thrown in the method read() if the data on the String do not correspond to the dimension of the matrix.
The numbers are separated by space. A dot in a string means the next string of text is for the next row.
For example:
Test
Result
String input="1 2 3 . 1 e 3 ."; Matrix m = new Matrix(); m.read(input);
ExceptionWrongMatrixValues
String input="1 2 3 . 1 2 3 4 5 ."; Matrix m = new Matrix(); m.read(input);
ExceptionWrongMatrixValues
String input="12312345"; Matrix m = new Matrix();…
arrow_forward
Java
arrow_forward
Java :
Write the code segments in main( ) and in methodA( ) for the following scenario:
main( ) passes methodA an int variable called a.
methodA generates an exception, but does not deal with it, if a is not between 1 and 100.
Hint: main will try and catch the exception and methodA throws exception.
arrow_forward
Write the code in java and please don't plagiarize or copy from other sources write it on your own. Read carefully and follow the instructions in the question. Thank you.
arrow_forward
DO IT IN JAVA PLEASE, IN 25 MINUTES
arrow_forward
Java programming
This problem set will test your knowledge of System I/O, and variable assignment. Your task is to create several different java classes (.java files) that will produce a specific output based on the user input. All input will be given to you either as a command-line argument or typed in from the keyboard.
Below you will find directions for each class you need to create. Please make sure that the class name and java file name match the name
1, ContainsAnyCase
This program will accept two user inputted values that are strings. The first user input will be a single word the second user input will be a sentence of random words. This program should print "true" if the first word is in the sentence of words regardless of the casing. In other words case is ignored when checking if the word is within the sentence. The last string that this program should print is "true" or "false", nothing else.
2 PrintMathResult
Write an application that will wait for three user inputted…
arrow_forward
Create the StudentAttendance class to keep track of absences of students as created by the class StudentCollection. (Java Programming Language)
arrow_forward
Can you please help me write this in C++ with this implemented with in it
Excutes without crashing
Appropriate Internal Documentation
Doctor class created
Doctor.h
Doctor.cpp
Contains data for no more than 3 patients
Patient class created
Patient.h
Patient.cpp
Contains data for up to 5 cholesterol readings
Menu
Add: Successfully adds a patient record
Successfully adds cholesterol readings
List: Lists all the data
Quit: Quits
Loops until the user selects quit
Style:
Data members are correctly declared
Member functions exist in the correct classes
Overall style is appropriate (no globals unless constants, modularity, uses a vector, adheres to the principle of least privilege, etc.)
Appropriate formatting of output
arrow_forward
Instructions
The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.
An example of the program is shown below:
Enter name Juan Hello, Juan!
Task 1: The DebugThree3 class compiles without error.
Task 2: The getName() method accepts user input for a name and returns the name value as a String.
Task 3: The displayGreeting() method displays a personalized greeting.
Task 4: The DebugThree3 program accepts user input and displays the correct output.
arrow_forward
Challenge 1: Division.java
You have to implement a Division class that divides two numbers given by the user. The program should handle exceptions that could be thrown during operation:
If the second number is 0
If any of the numbers is not a valid number, such as a letter.
arrow_forward
please follow the right steps on making the program.. specially the main, subclass and superclass names. this is my 2nd time i've asked this question. actually the 3rd but the first one is with another account. ill ask this question again if need be.
What to Prepare for the Activity:
NetBeans IDE 8.2
JDK8 (Java Development Kit 8)
Procedure:
Create a NetBeans project for this activity. The project name should be as follows:
Project Name: MP3_<lastname_firstname>
Example: MP3_Blanco_Maria
The class names to be created are the following:
Client (the main class that contains the main method and the implementation of the main menu)
SavingsAccount (the subclass where attributes and methods are defined)
BankAccount (the superclass where attributes and methods are defined)
All class names must be suffixed with your last name.
Client<your_last_name> ClientBlanco
SavingsAccount<your_last_name> SavingsAccountBlanco
BankAccount<your_last_name>…
arrow_forward
Write the code in java and please don't plagiarize or copy from other sources write it on your own and read the question carefully and write according to it thank you.
arrow_forward
Describe the two kinds of exceptions. in the language Java
arrow_forward
Cannot compile on java the problem is chapter 5, PC #10 page 346 in starting out with java early objects version 6 by Tony Gaddis. I believe that there is a bracket missing in the text on your site as I keep getting a parsing error at the final line of the code on the "Test" program. I have tried to place it where I thought it should belong but that just caused more errors. I will attach the code to this request. I keep getting an error of java 37: error: reached end of file while parsing. The last person said to just place another bracket at the end but that caused more than 20 errors.
arrow_forward
Create a flowchart and modify the code.
INSTRUCTION:
Create a new class called CalculatorWithMod. This class should be a sub class of the base class Calculator. This class should also have an additional method for calculating the modulo. The modulo method should only be seen at the sub class, and not the base class! Include exception handling for instances when dividing by 0 or calculating the modulo with 0. You would need to use throw, try, and catch. The modulo (or "modulus" or "mod") is the remainder after dividing one number by another.Example: 20 mod 3 equals 2Because 20/3 = 6 with a remainder of 2
CODE TO COPY:
#include <iostream>
using namespace std;
class Calculator{public:Calculator(){printf("Welcome to my Calculator\n");
}
int addition(int a, int b);int subtraction(int a, int b);int multiplication(int a, int b);float division(int a, int b);};
int Calculator::addition(int a, int b){return (a+b);}
int Calculator::subtraction(int a, int b){return (a-b);}
int…
arrow_forward
python 3
arrow_forward
java 1 error with my code pls help correct my code
arrow_forward
Java OOP
Write a complete address book maintenance application. The user of the program has four options: Add a new person, delete a person, modify the data of a person, and search for a person by giving the name. Use the AddressBook class, either the original one from the chapter or the modified one from the previous exercises. You have to decide how to allow the user to enter the values for a new person, display person information, and so forth.
arrow_forward
This programming assignment involves learning about some of the common exceptions that occur in Java programs. Consider the following exception types:
NumberFormatException
ArrayIndexOutOfBoundsException
FileNotFoundException
IllegalArgumentException
Research what each exception type means and the conditions under which each occurs (i.e., is thrown). Write programs that demonstrate each type of exception being thrown (one program per exception). Write 3 procedural programs and 1 Object Oriented Program. They can be very simple but make them up.
You should write your code so that each exception type is forced to occur. Name your programs so that we can determine which exception you are using in the code. Example FileNotFoundException FileExists.java or something creative.
Then, write a program that catches each type of thrown exception and display an error message indicating some of the details as to what that exception is.
Write one program per type of exception. They can be…
arrow_forward
Design a new class that contains a print and read function by creating a new object and calling the print and reading functions inside the case
arrow_forward
JAVA EXCEPTION HANDLING:Define a new exception, called ExceptionLineTooLong, that prints out the error message "The strings is too long". Write a program that reads phrase and throws an exception of type ExceptionLineTooLong in the case where a string is longer than 80 characters.
For example:
Input
Result
The quick brown fox jumped over the lazy dogs.
The quick brown fox jumped over the lazy dogs.
The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown fox jumped…
arrow_forward
Python help please (.py)
arrow_forward
4.
5.
........is an anomaly or error that occurs during the execution of a program
a. Exception b. Error
c. Syntax
d. Finally
is a special member of a class that is executed whenever we create new objects of
that class.
6. WSDL stands for...?
a)
a. Garbage collection
a) Webserver description language
c) Webservices Description Language
7. ....... Is a keyword used to implement inheritance
b) Inherit c) Inheritance
8. ASP Stands for.....?
a)
Inherits
a)
12. A
a)
c)
b. Finalizer
Active Server Pages
Active Server Platform
9. The Get procedure of a property acts like
a) An Event
b)
c)
10. Which SQL Statements is used to extract data from database?
Open b)
c)
11. A destructor is also known as..........
Get
tables or record sets.
c. Constructor
A Variable
b) Webserver descriptor language
d) Webservices descriptor language
Select
b) Access Server Pages
d) Active Server Programming
d) Inherited
A function
d)
d. Constants
d)
Extract
RC
Garbage collector
b)
d)
Constructor c) Constants
is a…
arrow_forward
Checked exceptions in Java are those
exceptions that are checked at compile
time and must be either caught or
declared in the method's throws clause.
(True/False)
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Related Questions
- Discussion Purpose: A discussion of the topic will reinforce the learning objectives of this lecture as students will research the topic and thereby enhance their learning and level of understanding. The interaction of ideas here will also be a healthy exposure to different perspective on the topic. Discussion Topic: A runtime Java system searches for exception handlers in call stack and terminates the program when it can't find one. The use of Exceptions to handle errors mitigates a lot of program interruptions. Examine and write some of the advantages of Exception handling.arrow_forwardPython code for the scenario is attached however I'm not just after the code I need also an explanation for all the step your taking when coding this in other work if you are doing a presentation of this to a group of people what are you tell them Analysis:(Describe the problem including input and output in your own words.) UML Class Diagram Algorithm Design: (Describe the major steps for designing the algorithm, for this problem-solving.) Input Validation and Exception Handling in the code Console and Graphical User Interface Code dump/listing Test Plan: (Evidence of testing) Application Testing screenshotsarrow_forward1.class Nothing {public static void main(String args[]){int x = 0;int y = 20;int fraction = y/x;System.out.println("End Of Main");}}1. If there will occur exception, write the code that will handle the exception.arrow_forward
- Java Foundations : Please provide code and explain. Thank you. Write the code segments in main( ) and in methodA( ) for the following scenario: main( ) passes methodA an int variable called a. methodA generates an exception, but does not deal with it, if a is not between 1 and 100.arrow_forwardSolve this according to exception handling and file management of Java prograam.arrow_forwardWrite the code in java and understand what the question says and give me the code and don't copy or plagiarize pleasearrow_forward
- Explain Rethrow (propagate) exception with help of code.arrow_forwardJAVA EXCEPTION HANDLING Complete the java code below according to the instructions given. Also use the test example below: Define the exceptions that are necessary to catch the possible errors that can occur in the class Matrix • ExceptionWrongMatrixValues that is thrown in the method read() if the data on the String does not correspond to numeric values, or if the data are not consistent with the form of a matrix (e.g., the rows have different length); • ExceptionWrongMatrixDimension that is thrown in the method read() if the data on the String do not correspond to the dimension of the matrix. The numbers are separated by space. A dot in a string means the next string of text is for the next row. For example: Test Result String input="1 2 3 . 1 e 3 ."; Matrix m = new Matrix(); m.read(input); ExceptionWrongMatrixValues String input="1 2 3 . 1 2 3 4 5 ."; Matrix m = new Matrix(); m.read(input); ExceptionWrongMatrixValues String input="12312345"; Matrix m = new Matrix();…arrow_forwardJavaarrow_forward
- Java : Write the code segments in main( ) and in methodA( ) for the following scenario: main( ) passes methodA an int variable called a. methodA generates an exception, but does not deal with it, if a is not between 1 and 100. Hint: main will try and catch the exception and methodA throws exception.arrow_forwardWrite the code in java and please don't plagiarize or copy from other sources write it on your own. Read carefully and follow the instructions in the question. Thank you.arrow_forwardDO IT IN JAVA PLEASE, IN 25 MINUTESarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage