首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
ELEC 279程序辅导、讲解java程序、java编程调试 解析C/C++编程|辅导R语言编程
项目预算:
开发周期:
发布时间:
要求地区:
ELEC 279 - Winter 2021
Introduction to Object Oriented Programming
Assignment III
Due Date: Friday April 9th, 2021 at 23:59 EST.
Submission Guide
• Add your 8 classes (GuessMaster3.java, Date.java, Person.java, Singer.java, and
Politician.java, Guessable.java, GuessablePerson.java, IncorrectDateException.java)
to a folder named ”FirstName LastName StudentNumber Assignment3” where you
place your first name, last name and student number
• Zip up your folder and submit it under the “Assignment 3” submission on onQ.
• Late submission: If you submit the assignment late, for every day late (to a
maximum of 2 days), you will lose 15% of your assignment marks.
• Add a comment at the beginning of your class (.java) files to include your name and
student number as a proof of authorship.
• All instance variables should be private unless stated otherwise and all
method MUST avoid privacy leaks (unless it is impossible to avoid (i.e.
in generic classes))
• Ensure that your Java source code has good indentation, proper white spaces, and
clear variable names
• Add comments as necessary for important parts of your code to explain what the
code is doing. Commenting is necessary for this assignment as the TAs and
I need to understand what you are doing in your code in order to assign marks as
the assignment can be completed in any number of different ways.
• This is an individual assignment. You are allowed to discuss the assignment
but any form of plagiarism will lead to a score of 0 for your
assignment, in addition to other academic sanctions
Grading
• 90% - Solve the problem as expected
– 35% - Correctly define GuessMaster3.java
– 25% - Correctly define GuessiblePerson.java
– 10% - Correctly define Date.java
– 10% - Correctly define Person.java , Singer.java, Politician.java
– 10% - Correctly define Guessible.java, IncorrectDateException.java
• 10% - Programming style and documentation (indentation/naming/comments/clarity)
Page 1 of 8 – ELEC 279 - Assignment 2
Problem: GuessMaster Version 3.0
Assignment 3 is based on Assignment 2. I am working with the teaching assistant’s
to get your assignments graded as fast as possible so that you can either have it at the
start of this assignment to continue using your code, or you can start with your code and
then implement any relevant feedback from assignment 2 once the grades are released.If
you are not confident in your solution to Assignment 2 you can use the starting code I
have provided on OnQ.
This new version of the game, GuessMaster 3.0, is played with the same rules as in
assignment I and II. However, you will need to restructure the classes you wrote in assignment
II to utilize sets, nested classes, generic classes, interfaces, iterators and exception
handling. These concepts will help clean up and shorten some parts of your code, while
allowing for better encapsulation within your program. However, the addition of some
of these concepts will make the program less efficient and reduce functionality so do not
consider this assignment the most optimal or efficient way to solve the problem, just the
one that includes the most course concepts.
A Recap of Assignment II
In assignment II, you designed a simple game that allows users to guess the birthday of
a person. It requires a player to guess the correct birthday stored secretly in the computer
program (e.g. Justin Trudeau was born on December 25, 1971). To start, the program
welcomes the player and informs them whose birthday to guess. More specifically, from
an array of instance variables representing a person, the program randomly selected one
of those people and prints the name on the screen and ask the user to guess the birth
date. After reading the inputted guess from the user from the console, the program responds
with useful information if the guess was incorrect such as: “Incorrect. Try an
earlier day.” or “Incorrect. Try a later month.”. If the guess was correct the system
displayed “CORRECT. You got it!” and then awarded the user a number of points based
on the difficulty of the person whose birthday was guessed.. The user can type “quit”
to exit the game. We will be expanding (and reducing) this functionality in Assignment 3.
Assignment III Instructions
• Let’s start off by modifying the Date class to use the better clone method, and
implement the Comparable and Cloneable interfaces.
(i) Remove the copy constructor. We will be modifying every clone method in this
project to use the better clone method rendering the copy constructor obsolete.
Let’s remove it to reduce a couple lines of code and be more efficient.
(ii) Add to your class declaration that this class now implements the Comparable
interface for Date type objects, and the Cloneable interface.
(iii) replace the clone method in the class which uses the now removed copy constructor
with the methodology we discussed in lecture where we use the parent
classes clone method.
Page 2 of 8 – ELEC 279 - Assignment 2
(iv) Around the code in your clone method put a try block.
(v) After the try block include the following:
catch(CloneNotSupportedException e)
return null;
This will catch the CloneNotSupportedExceptions and avoid needing to include
throws clauses throughout your project. As discussed in lecture it is
always good practice to catch or declare an exception so we are just getting it
out of the way here.
(vi) Now finish implementing the Comparable interface by include the full definition
for the compareTo method. This method will replace most of the code/
functionality of guessing the birthday in the GuessMaster class.
(vii) The comparable method should be implemented such that -1 is returned if the
calling object is earlier than the parameter passed to the function, and 1 if it
is later. A value of 0 should be returned if the dates are equal.
(viii) With this change fresh in your mind go into your GuessMaster3 class (previously
GuessMaster2) and change your code where you compare the user’s
guess to the birthday of the person to utilize the compareTo method you just
created. This will greatly reduce the length of your code. As we are no longer
checking the day, month, and year individually for this assignment you only
need to output to the user ”Incorrect. Try a earlier date.” or ”Incorrect. Try
a later date.” if their guess is incorrect. The functionality for a correct guess
will not change.
(ix) Define a private static nested class within the Date class called Months
(x) Create private static method called getDays which returns an int type value,
and takes in an int parameter called month. Inside this method, utilize a
switch statement to return a value equal to the number of days in numeric
value of the month that was passed in as a parameter (ex. 1 is January which
has 31 days). As you go to make this switch case statement think about how
you can efficiently return the number of days using a default case.
(xi) Now we are going to modify the constructor for the Date class that takes in a
string parameter (the input from the user) to throw exceptions if the string is
in an incorrect format, or the values of the day, month and year are impossible.
(xii) More specifically, create code to check if the string being entered is too long, or
too short, or if the day, month, or year is less than 1, or if the month is greater
than 12, or the day is not possible based on the given month. This method
should utilize the getDays method you created in the nested Month class.
(xiii) If the string is incorrect, throw a new exception of the type IncorrectDateException,
that takes in a single parameter, the string passed into the constructor.
If the string is correct, then initialize the instance variables of the object as
was done in assignment’s 1 and 2.
• Now we need to create the IncorrectDateException class, and define it to give us an
informative message when the exception is caught.
Page 3 of 8 – ELEC 279 - Assignment 2
(i) Define a new exception called IncorrectDateException which is derived from
the Exception class.
(ii) This class needs be able to create an object with the message ”The date you
have entered, INSERTSTRINGHERE is not a valid input”, where you insert
the parameter dateString.
• Modify the Person abstract class to remove most of the methods and functionality
used for the game by guessing the person birthday. This will allow for the Person
abstract class to be used to create people that are not used for the guessing game.
This better encapsulates our guessing functionality while allowing for our code to be
reused and re-purposed for other needs by only giving the programmer/ user access
to the relevant methods (which is also part of the concept of abstraction).
(i) Remove the difficulty instance variable, and any parts of any method that refer
to it.
(ii) Remove the getAwardedPointNumber, startMessage, and closingMessage methods.
(iii) Have the person class implement the Cloneable interface.
(iv) Define (or redefine) the clone method in this class using the ”better” clone
method discussed in lecture (and implemented earlier in this assignment).
(v) Around the code in your clone method put a try block.
(vi) After the try block include the following:
catch(CloneNotSupportedException e)
return null;
This will catch all of the CloneNotSupportedExceptions that you will be throwing
later in this assignment.
(vii) Remove the copy constructor from this class.
(viii) Search your Person class for anytime you utilize the Date copy constructor and
replace its use with the clone method of the Date class we defined earlier. (You
will likely need to add in some throws declarations)
• Create a Guessable interface. This interface will contain the method headings we
will implement in any class derived from the Person abstract class that we want to
be able to use in our guessing game (which in this assignment is all of them).
(i) Use your IDE to create a new interface called Guessable or created a new class
and change the class definition to be that of an interface.
(ii) Have the Guessable interface be derived from the Comparable interface such
that we can compare Person type objects.
(iii) Define a method called startMessage that takes in no parameters and returns
a String.
(iv) Define a method called closingMessage that takes in no parameters and returns
a String.
Page 4 of 8 – ELEC 279 - Assignment 2
(v) Define a method called getAwardedPointNumber that takes in no parameters
and returns an int.
• Now let’s bring the Person class and the Guessable interface together to create a
new class to use for classes we want to use in our guessing game.
(i) Create new generic class called GuessablePerson.
(ii) Put a bound on the type parameter accepted by this class such that only classes
which are derived from the Person class will be accepted.
(iii) Have this class implement the Guessable and Cloneable interfaces. (Note that
since the Guessable interface is derived from the Comparable interface this
class also essentially implements the Comparable interface).
(iv) Define a type parameter instance variable called person and a double called
difficulty.
(v) Create a constructor for the class that takes in a type parameter variable and a
double variable and initialize the instance variables to those parameters values.
Notice here you are unable to avoid a privacy leak.
(vi) Define a compareTo method such that the calling GuessablePerson object
comes ”before” the parameter if they are younger. If the two are the same age,
then the one that comes before is the one whose name comes first alphabetically.
Think critically on how to do this the most efficiently.
(vii) Include the following methods from Assignment II in this class to allow for this
class to be used with our game:
public String startMessage()
return ”Guess the birthday of the ”+person.personType()+” ”+person.getName();
public String closingMessage()
return ”Congratulations! You were correct, ”+person.toString();
public int getAwardedPointNumber()
double points = this.difficulty*100;
return (int) points;
(viii) Create a clone method for this class using the ”better” clone method.
Page 5 of 8 – ELEC 279 - Assignment 2
• Modify the Singer and Politician Classes to fit with the new changes to the code.
(i) Remove any reference to the difficulty variable that used to be in the Person
class.
(ii) Remove any use of copy constructors, and the use of copy constructors in the
classes to instead use that class’ clone method.
(iii) Redefine the clone methods to use the ”better” clone methods. Be sure to
avoid privacy leaks.
• Time to bring all this work together, with a few more course concepts in the GuessMaster3
class. Remember you will either need to rename the class and file from
GuessMaster2 to GuessMaster3, or create a new class and copy over the contents.
The latter option may be more beneficial to you in completing the lab as you can
drag over parts of the code one after another to slowly add in the new functionality.
(i) For our guessing game we now want to use a collection class to store the people
we are guessing. As we do not want the elements in the collection to occur
more than once, we will change the people instance variable from an Array,
to an HashSet. The HashSet should be of GuessablePerson objects where the
type parameter can be anything.
(ii) Create/ edit the default (no-argument) constructor for the GuessMaster3 class
such that it initializes the HashSet to a size of 0, and initializes the variable
numPoints to 0.
(iii) Modify the addPerson method to be a generic method that has a type parameter
M. This type parameter should be bound such that only reference type
objects derived from the Person class can be used.
(iv) The method will be used to add a Person type object to the game with a given
difficulty. The method returns nothing, and takes in 2 parameters, an M type
variable called person, and a double called difficulty.
(v) The method should create a new GuessablePerson object from the person parameter
while avoiding a privacy leak. This object should then be added
to the HashSet called people.
(vi) Create a method called getPeople that takes in no parameters and returns a
HashSet of GuessablePerson objects with any type parameter. The method
should return the HashSet called people.
(vii) Download the ”test.txt” file from OnQ and add it to the src folder of your
project.
(viii) In this version of the game, to demonstrate another method for system input
and to allow you to better test your assignment the Scanner object should be
changed to utilize a FileInputStream instead of System.in. For this file you
need to input the full path (location on your computer) to the ”test.txt” file.
(ix) to avoid having the startGame method throw an error you will need to put a
try block around your FileInput code to catch FileNotFoundExceptions.
Page 6 of 8 – ELEC 279 - Assignment 2
(x) Remove the random number generation functionality from your code. The
person to guess will no longer be selected based on a random number.
(xi) Instead, create an Iterator of GuessablePerson objects, with any type parameter
that is derived from person, from the people Hashset. Call this iterator
peopleIterator.
(xii) Modify your code now to accommodate the current person being guessed being
selected by using this iterator.
(xiii) You will need to adjust your while loops that end the program based on whether
there is more input to be read from the txt file, and whether there are more
people to iterate through. If there is no more input in the file, or if every
person has been guessed the game should end (in addition to the functionality
to end the game if the user types ”quit”).
(xiv) Where you get the user’s input and convert it to a Date object and then
compare the date to see if the guess is correct you will now need to utilize
exception handling of the IncorrectDateException we defined earlier to check
if the user has given an invalid input.
(xv) Think critically on where the try block should be placed so that the game
continues to run (and allow more guesses/input) after an incorrect date string
is given.
(xvi) The IncorrectDateException should be caught and utilized to display the
exception message to the user.
(xvii) Whether or not an error is thrown or caught your code should display ”If
you would like to stop, type ”quit” to exit”.
Page 7 of 8 – ELEC 279 - Assignment 2
Test Code
We will use the following code to test assignment III in combination using the
”test.txt” file for the system input that has been posted alongside this assignment
on OnQ:
Politician trudeau = new Politician(”Justin Trudeau”, new Date(25, 12, 1971), ”Liberal”);
Singer dion = new Singer(”Celine Dion”, new Date(30, 3, 1961), ”La voix du bon
Dieu”, new Date(6, 11, 1981));
Singer robertson = new Singer(”Ed Robertson”, new Date(25, 10, 1970), ” Gordon”,
new Date(7, 28, 1992));
GuessMaster3 gm = new GuessMaster3();
gm.addPerson(trudeau, 0.25);
gm.addPerson(dion, 0.5);
gm.addPerson(robertson, 0.75);
System.out.println(”There are ”+ gm.getPeople().size()+” people in the game”);
GuessablePerson
guessableTrudeau = new GuessablePerson<>(trudeau,
0.25);
System.out.println(”The next output should be -1”);
System.out.println(guessableTrudeau.compareTo(dion));
gm.startGame();
With that, you are now done with the GuessMaster game! Congratulations on all your
hard work on these assignments. I hope you enjoyed getting to see how the concepts we
have learned in the course can be used together, and how each concept built up to the
next allowing us to make more efficient code, with more functionality.
Page 8 of 8 – ELEC 279 - Assignment 2
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!