uml代做 | 代写java | java编程 | project代写 – CSC207 Practice Exam Questions

CSC207 Practice Exam Questions

uml代做 | 代写java | java编程 | project代写 – 这是一个关于java的题目, 主要考察了关于java的内容,是一个比较经典的题目, 是比较典型的uml/java/ R 等代写方向, 这是值得参考的project代写的题目

R语言 统计代做 代写统计


The exam will test a subset of the topics discussed in this practice exam. It will have fewer questions with a different format.

Solutions will not be posted to these questions. Instead, we will be discussing the answers during the last lecture of the semester. You can also discuss the solutions to these questions on the message forum or in any office hours for this course, including:

Questions:

  1. In order to run a java program, the computer must first compile the.javafiles to create.classfiles. Then the Java Virtual Machine (JVM) runs the.classfiles. After compilation, when the JVM first starts to run the program, what is created in memory first? When do instances of an object get created? How long do they stay in memory? Under what circumstances will the JVM delete an object from memory?
  2. What are the main components of a class in Java? What are the standard accessi- bility modifiers for each (e.g., protected, private, etc.)? When would you want to use a non-standard accessibility modifier for a variable? for a method? for a constructor?
  3. In what ways are methods similar to constructors? In what ways are they different? (Consider: the syntax for coding each, how they show up in the Java memory model, features such as calling other constructors, whether or not Java provides them by default, returning values, the applicability of terms like instance and static, etc..)
  4. Is it possible for a class to have more than one parent class? More than one child class? To implement more than one interface?
  5. In which ways are abstract classes and interfaces similar? In what ways are they different? List the conditions which are necessary and sufficient for a: (a) class to be declared abstract and (b) for a method to be abstract.
  6. Under which circumstances would we want to override theequals,toString, and/or hashCodemethods?
  1. List all of the primitive types. How does the memory model reflect the differences between primitive types and ob- jects? When are two primitive variables equal? When are two objects equal? What are the differences between==and theequalsmethod? Are all non-primitive types subclasses of theObjectclass? What features of class Objectdid we use most frequently in the lectures, besides theequalsmethod?
  2. What do we mean by casting, autoboxing, and wrapper class. Compare and contrast these terms.
  3. Give four examples of subclasses ofCollectionin Java. Describe a different cir- cumstance for each in which you would require the features of that particular type of collection. For example, how and when would you use anArrayList? How are collections similar to arrays? How are they different? Is it possible to define a non- generic subclass ofCollection? Why or why not?
  4. Write your own generic class and also write a second class in which you instantiate the generic one. What does instantiate mean?
  5. Finish answering the question from theTicketVendorexample from Week 6.
  6. Think of examples of how your project follows each of the SOLID principles. How does following each principle prevent code smells? Which code smell(s) does each principle prevent (if any)?
  7. In Week 5, you learned about Exceptions. Write amainmethod that tries to call a different method that can throw an Exception. The method should be located in a different class frommain. Can you get yourmainmethod to:
(a) compile but not run to completion.
(b) compile and run, even though an exception is thrown.
(c) compile and run, but print the stack trace to the screen twice, at different parts
of the program. In other words, the two traces should describe different points
in the code.
(d) compile and run, even though an exception is thrown from inside acatchblock.
(e) The file compiles but does not run. However, between the moment when the last
exception is thrown and the end of execution, the message This is a message.
appears on the screen.
  1. We discussed the following design patterns in class: Iterator, Observer, Strategy, MVC, Dependency Injection, and Factory Method. When would you want to use each pattern? Describe a situation where the Iterator pattern would be useful. Do that again for each of the other patterns. Describe an alternative solution to the Observer pattern, the Iterator pattern, and to the Strategy pattern.
  1. Demonstrate the lookup rules for Java by creating a parent class and child class that each contain a static variable with the same name, instance variable with the same, static method with the same signature and instance method with the same signature. Let the parent class be calledParentand the child class be calledChild. Include the following lines in your main method: Parent var1 = new Parent(); Parent var2 = new Child(); Child var3 = new Child(); Then try printing the value of each variable and the return value of each method for var1,var2, andvar3. When does Java shadows (use the code from the parent class) and when does it over- ride (use the code from the child class?
  2. Try the questions in the regexpractice file, on the website under Week 9.Also try at least one Regular Expressions Crossword fromregexcrossword.com.
  3. What is a floating point variable? What examples of floating point issues have we seen?
  4. Complete an alternative set of CRC cards for the TicketVendor activity that we did during lecture. Use as many design patterns as is appropriate. Looking at your cards, is it possible to deduce where each class is instantiated? As the user, where is the entry point into your program? If you move the main method, how does that impact your design?
  5. Pretend that you are trying to explain JUnit to someone who knows nothing about it. What is an assertion? What does it mean to pass a test? What is the difference between a fail and an error? What is a unit test?
  6. What is version control? What do the following commands do?
git pull
git add
git commit
git push
Is this the correct order in which to use these commands? Are there circumstances
when you would use them in a different order?
  1. Take a look at the uml diagram for your Phase 1. How much of that diagram has changed? What major changes occurred between Phase 1 and Phase 2? For each major change, why is the new design better than the previous? Did the change in- volve implementing a design pattern? Does the new design follow any of the SOLID principles better than your Phase 1 design?
  1. Consider the code that starts on the next page. For each SOLID principle, ask the question:
Does the code violate this principle?
If so, on which line(s)?
How can I fix the code so that it better implements this principle?
  1. Consider the code that starts on the next page. Are there any design patterns that can be used to improve or extend it?
  2. In the code that starts on the next page, figure out what (if anything) is inherited by each class.
  3. How would you recognize each of the following, when looking at someone elses code: (a) Cyclomatic complexity (b) Data clump (c) Excessively long identifiers (d) Duplicated code (e) Shotgun surgery

public c l a s s T i c k e t {

private s t a t i c i n t numSales ;
private S t r i n g e v e n t ;
private S t r i n g b u y e r ;
private boolean i s F o r S a l e ;
public T i c k e t ( S t r i n g e v e n t , S t r i n g b u y e r ) {
t h i s. e v e n t = e v e n t ;
t h i s. b u y e r = b u y e r ;
i s F o r S a l e = f a l s e;
numSales++;
}
public void r e t u r n T i c k e t ( ) {
b u y e r =   ;
i s F o r S a l e = true;
}
public void s e l l T i c k e t ( S t r i n g b u y e r ) {
t h i s. b u y e r = b u y e r ;
i s F o r S a l e = f a l s e;
numSales++;
}
public S t r i n g t o S t r i n g ( ) {
return  t h i s t i c k e t f o  R  + e v e n t +  b e l o n g s t o  + b u y e r ;
}

public i n t getNumSales ( ) { return numSales ; } }

public c l a s s T r a i n T i c k e t extends T i c k e t {

private S t r i n g f r o m C i t y ;
private S t r i n g t o C i t y ;
public T r a i n T i c k e t ( S t r i n g f r o m C i t y , S t r i n g t o C i t y , S t r i n g b u y e r ) {
super(  t r a i n r i d e  , b u y e r ) ;
t h i s. f r o m C i t y = f r o m C i t y ;
t h i s. t o C i t y = t o C i t y ;

}

public void r e t u r n T i c k e t ( ) {
System. o u t. p r i n t l n (  T h i s t i c k e t i s f o r s a l e a g a i n  ) ;
}
public S t r i n g g e t T o C i t y ( ) {
return t o C i t y ;
}

public void s e t T o C i t y ( S t r i n g t o C i t y ) { t h i s. t o C i t y = t o C i t y ; } }

public c l a s s TwoWayTrip {

private T r a i n T i c k e t d e p a r t T i c k e t ;
private T r a i n T i c k e t r e t u r n T i c k e t ;
private S t r i n g s t a r t D a t e ;
private S t r i n g endDate ;
public TwoWayTrip (
S t r i n g s t a r t D a t e , S t r i n g endDate , S t r i n g f r o m C i t y , S t r i n g t o C i t y ,
S t r i n g b u y e r ) {
d e p a r t T i c k e t =new T r a i n T i c k e t ( f r o m C i t y , t o C i t y , b u y e r ) ;
r e t u r n T i c k e t =new T r a i n T i c k e t ( t o C i t y , f r o m C i t y , b u y e r ) ;
t h i s. s t a r t D a t e = s t a r t D a t e ;
t h i s. endDate = endDate ;
}

public void p r i n t I t i n e r a r y ( ) { System. o u t. p r i n t l n ( S t a r t d a t e : + s t a r t D a t e + , End d a t e : + endDate ) ; } }