首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导ELEC 279编程、Java,c/c++,Python程序辅导 辅导Web开发|调试Matlab程序
项目预算:
开发周期:
发布时间:
要求地区:
ELEC 279 - Winter 2021
Introduction to Object-Oriented Programming
Quiz 3 Practice Problems - Week 11
I am changing things up a bit for the Quiz 3 practice problems. As I was creating the
quiz I realized that most of the content from the last few weeks was application based,
instead of knowledge based. Due to this, there are a greater number of written (long)
answer questions on the Quiz than in Quiz 1 and Quiz 2 and much fewer fact based
multiple choice questions. I did not feel that giving you all a bunch of the cut multiple
choice questions would adequately prepare you for the quiz.
Instead I have compiled for you all of the practice problems from weeks 7-10 that are
the most applicable for the quiz. I have reworded and adjusted some of them to
better reflect the phrasing you would see in the quiz, and be less like a lab,
as well as added a few additional ones. (What I have cut, and reworded/ added
should be very telling to what you will and won’t see on the Quiz) These will be a great
way to ensure that you have not only an understand the course concepts but can use
them. Written solutions are at the end of the document. For a verbal explanation of any
question you don’t understand the answer for see the respective practice problem videos
from that particular week. (I am also doing things this way as the number of people who
have viewed, let alone, done the practice problems is very low and the practice problems
are honestly the best way to prepare you for the quiz)
Page 1 of 10 – ELEC 279 - Lab 1 Week 2
Practice Problems
Week 7
1. Define an interface called Measurable. Inside the interface define a public method,
measure, that takes in one String parameter and returns an int.
2. Define a class Table that implements the interface from the last question, and the
Comparable interface.
3. Define a compareTo method for a class that takes in Object type parameter, and is
used to compare an int type instance variable i, such that the object with the lower
value of i is before the other.
4. If an abstract class implements an interface, what methods must a concrete class
derived from the abstract class define?
5. If an interface B, is derived from another interface, A, a concrete class that implements
interface B must contain method definitions from which interface(s)?
6. True or false, the compiler will check to see if you have define a clone method in a
class that implements the Cloneable interface. Explain.
7. True or false, the compiler will check to see if you have correctly defined the compareTo
method if you create a class that implements the Compareable interface.
Explain.
8. True or false, a class can be derived from more than one abstract class.
9. True or false, a class can implement more than one interface.
10. True or false, interfaces contain instance variables.
11. True or false, abstract classes can contain complete method definitions.
12. True or false, methods in interfaces can be declared as private.
Page 2 of 10 – ELEC 279 - Lab 1 Week 2
Week 8
1. To practice error handling, we first need some code that can cause exceptions/ errors.
Let’s define a method, pickANumber, that takes in a single int type parameter, and
returns a boolean value. This function will be used to compare the parameter with
an int type instance variable called myNumber which is between 1 and 10 inclusive.
If the numbers are the same the method returns True, if not it returns False.
2. Define a new exception called NumberTooBigException that extends Exception.
Create a constructor for the exception such that when the exception is caught it
can display ”The number INSERTNUMBERHERE is too big.”
3. Put a try block around your code in the pickANumberMethod, and create an if
statement to check if the value of the parameter is greater than 10. If the number
is greater than 10, throw a NumberTooBigException exception.
4. Catch your exception and display the message of the exception.
5. Define a new exception called NumberWayTooBigException that extends NumberTooBigException.
6. Add to the code in your pickANumberMethod code to check if the parameter is
greater than 50. If it is, throw a new NumberWayTooBigException exception.
Think critically about the order of your if-else statements.
7. Catch the NumberTooBigException. Think critically about the order of your catch
blocks. Inside the catch block for the NumberWayTooBigException output the
message of the exception, followed by ”Try a number way smaller.”.
8. Include code in your pickANumber method that will output to the user ”Do you want
to guess again?” after any messages from exceptions, whether or not an exception
does occur.
9. In your own words, describe the catch or declare rule.
10. Given a class called Bird which has an inner class called Nest, where both the Bird
class and the Nest class have a method called hatch() that takes in no parameters,
do the following:
(a) Create a new object called myBird of type bird.
(b) Create a new object of type nest called myBirdNest.
(c) Run the hatch method with myBird.
(d) Run the hatch method with myBirdNest.
11. True or false, a non static inner class can have static instance variables and methods.
12. True or false, a non static inner class can have a static inner class.
Page 3 of 10 – ELEC 279 - Lab 1 Week 2
Week 9
1. Let’s say there is a class, PracticeProblem with instance variables; int numQuestions,
Date currDate, String author, Problem problem1. Assuming the Problem and Date
classes already have a clone method, define a clone method of the practice problem
class, avoiding privacy leaks, using the ”better” clone method.
2. Order the callback methods; onStart(), onResume(), and onCreate() in the order
they are called in an activity lifecycle.
3. During which callback method does the user become able to interact with the activity
in an Android application?
4. During which callback method an app release all resources from memory?
5. Create an ArrayList with the identifier practice that contains 10 Date type objects.
6. To this array list, change the first Date object in the list to an object with the
identifier newDate.
7. Get the element at index 5 and set it to the value of a Date variable with the
identifier gotDate.
8. Add to the end of the ArrayList an object with the identifier addedDate.
9. Remove the element in the first index (index 0).
10. Define a generic class GenericPractice that contains an instance variable of the type
parameter type called genericVariable.
11. Add a constructor to this class that takes in a parameter, genericVariable of the
type parameter, and sets the instance variable to that value.
12. Add an accessor for the genericVariable.
13. Define a a new object called myGenericPractice of type GenericPractice, where the
parameter type is String.
14. Given the object, myObj, cast myObj to a GenericPractice type object with the
identifier myGenericObj and a String type parameter.
15. Define a new Generic class Generic whose type parameter can only be a class derived
from the Date class.
16. Define a new Generic class Generic34 which has two type parameters, one that can
only be a class that implements the Cloneable interface and one that can only be a
class that implements the Cloneable interface and is derived from the Date class
17. Define a static generic method that takes in a parameter, param1 of the type parameter,
and returns the parameter. (I know it makes no sense, just needed an easy
example)
Page 4 of 10 – ELEC 279 - Lab 1 Week 2
18. Given a String, myString, call the method you just created (assuming it is within
the MyGeneric class) and give it myString as the parameter.
19. Define a new method, exampleMethod, that takes in a GenericPractice type object
(the generic class you defined earlier) and returns nothing.
20. Alter the method heading from the previous question such that the method will only
accept GenericPractice objects with a type parameter of a class that implements
the Cloneable interface.
21. Alter the method heading from the previous question such that the method will
only accept GenericPractice objects with a type parameter of a class that is used
to derive the Date class.
Week 10
1. In your own words, give two reasons why the ”better” clone method is better than
the clone method that uses the copy constructor.
2. What is the differences between Sets and Lists
3. Write a line of code to create an empty HashSet of strings.
4. Do optional methods of interfaces need to be implemented in a class that implements
it?
5. Given a HashSet myHash, add all the elements of the set to an empty ArrayList of
strings you create with the identifier myList.
6. How are elements ordered in a HashSet?
7. Create an empty hash set of strings with the capacity of 10.
8. Add the string ”Hello” to the HashSet from the previous question.
9. Remove all elements from the HashSet in the previous question that are not contained
in the HashSet otherHash.
Page 5 of 10 – ELEC 279 - Lab 1 Week 2
Solutions
Week 7
1. My code:
2. My code:
public inter fa ce Measurable {
public int measure ( S t ri n g dimen si on ) ;
}
3. My code:
public c l a s s Table implements Measurable , Comparable
{}
4. My code:
public int compareTo ( Ob jec t o the rOb j ){
i f ( i < o the rOb j . y )
return −1;
e l s e i f ( i == o therOb j . i )
return 0 ;
e l s e
return 1 ;
}
}
5. All the abstract methods from the abstract class, and any methods from the interface
not already defined in the abstract class.
6. All the methods from interfaces A and B.
7. False. The Cloneable interface contains no method headings, so you do not need
to define a clone() method in the class (though you should unless you only have
primitive type instance variables).
8. False. The compiler only checks for correct syntax, not for if you have implemented
an interface as intended.
9. False.
10. True.
11. False.
12. True.
13. False.
Page 6 of 10 – ELEC 279 - Lab 1 Week 2
Week 8
1. My code
public boolean pickANumber ( int number ){
i f ( number==myNumber)
return True ;
e l s e
return F al s e ;
}
2. My code
public c l a s s NumberTooBigException extends Excep ti on {
public NumberTooBigException ( int number ){
super ( ”The number ”+ number+” i s t o o bi g . ” ) ;
}
}
3.
4. My code
public boolean pickANumber ( int number ){
try{
i f ( number>10)
throw(new NumberTooBigException ( number ) ) ;
i f ( number==myNumber)
return True ;
e l s e
return F al s e ;
}catch ( NumberTooBigException e ){
System . out . p r i n t l n ( e . ge tMessage ( ) ) ;
return F al s e ;
}
}
5. My code
public c l a s s NumberWayTooBigException extends NumberTooBigException{
public NumberWayTooBigException ( int number ){
super ( number ) ;
}
}
Page 7 of 10 – ELEC 279 - Lab 1 Week 2
6.
7. My code
public boolean pickANumber ( int number ){
try{
i f ( number>50)
throw(new NumberWayTooBigException ( number ) ) ;
e l s e i f ( number>10)
throw(new NumberTooBigException ( number ) ) ;
i f ( number==myNumber)
return True ;
e l s e
return F al s e ;
}catch ( NumberWayTooBigException e ){
System . out . p r i n t l n ( e . ge tMessage ( ) ) ;
System . out . p r i n t l n ( ”Try a number way sm all e r . ” ) ;
return F al s e ;
}catch ( NumberTooBigException e ){
System . out . p r i n t l n ( e . ge tMessage ( ) ) ;
return F al s e ;
}
}
8. My code
. . . . .
f i n a l l y {
System . out . p r i n t l n ( ”Do you want t o g u e s s a g ai n ? ” ) ;
}
9. In your own words.
10. My Code:
Bird myBird = new Bird ( ) ;
Bird . Nest myBirdNest = myBird .new Nest ( ) ;
myBird . hatch ( ) ;
myBirdNest . hatch ( ) ;
11. False
12. False
Page 8 of 10 – ELEC 279 - Lab 1 Week 2
Week 9
1. My code
public P r ac ticeP r oblem cl o n e ( P r ac ticeP r oblem o t h e r ) {
P r ac ticeP r oblem copy = ( P r ac ticeP r oblem ) super . cl o n e ( ) ;
copy . cu r rD a te = o t h e r . cu r rD a te . cl o n e ( ) ;
copy . problem1 = o t h e r . problem1 . cl o n e ( ) ;
return copy ;
}
2. onCreate(), onStart(), onResume()
3. onResume()
4. onDestroy()
5. ArrayList
practice = new ArrayList
(10);
6. practice.set(0, newDate);
7. Date gotDate = practice.get(5)
8. practice.add(addedDate);
9. practice.remove(0);
10.
public c l a s s G e n e ri cP r a c ti c e
{
private T g e n e r i c V a r i a b l e ;
public G e n e ri cP r a c ti c e (T g e n e r i c V a r i a b l e ){
th is . g e n e r i c V a r i a b l e = g e n e r i c V a r i a b l e ;
}
public T g e tG e n e ri c V a ri a bl e ( ) {
return g e n e r i c V a r i a b l e ;
}
}
13. GenericPractice
myGenericPractice;
14. GenericPractice
myGenericObj = (GenericPractice
) myObj;
15. public class Generic2
16. public class Generic34< T extends Cloneable, M extends Date Cloneable>
17. public static
T genericMethod(T param1) return param1;
18. MyGeneric.
genericMethod(myString);
19. public void exampleMethod(GenericPractice> param1);
20. public void exampleMethod(GenericPractice extends Cloneable> param1);
Page 9 of 10 – ELEC 279 - Lab 1 Week 2
21. public void exampleMethod(GenericPractice extends Cloneable> param1);
22. public void exampleMethod(GenericPractice super Date> param1);
Week 10
1. Watch Week 10 Video 0
2. Lists allow for elements to occur more than once
3. HashSet
newSet = new HashSet<>();
4. My code
A r r ayLi s t
myList = new A r r ayLi s t <>();
myList . addAll (myHash ) ;
5. Based on a hash function that maps keys (indices) to values (elements).
6. HashSet
newSet = new HashSet<>(10);
7. newSet.add(”Hello”);
8. newSet.retainAll(otherHash)
Page 10 of 10 – ELEC 279 - Lab 1 Week 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
软件定制开发网!