cmpt 270 weekly quizzes

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/98

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

99 Terms

1
New cards

Software development is all about learning a programming language.

False

2
New cards

Object Oriented Programming

A program consisting of classes and objects organized to manage the complexity of large-scale systems

3
New cards

Procedural Programming

A program consisting of methods/functions calling each other

4
New cards

Method

Implements behaviours relevant to the purpose of the system

5
New cards

Field or Attribute

Stores data relevant to the purpose of the system

6
New cards

Entity Object

Model of a real-world thing in an application

7
New cards

Control object

organize computation or flow of the program

8
New cards

Interface Object

Facilitates communication between the system and the outside world

9
New cards

Container Object

Data structure to store entities

10
New cards

A UML Class Diagram is a type of behavioural diagram

False

11
New cards

What does a toString() method do in Java?

It allows a programmer to define a String representation of their class

12
New cards

The tree class does not have a ‘chopDown’ method. What describes it’s behaviour?

a) Set height to 0

b) Mark isDead = true

c) Free memory

d) Set tree to null

The tree variable is set to null

13
New cards

Why doesn’t the Tree class have a height setter?

a) height is public

b) height never changes

c) grow() is the setter

d) getHeight() sets it

it has one, the method grow() acts as a mutator

14
New cards

which class acts as the main/client program?

a) inventory

b) forest

c) tree

d) TreePlanter

TreePlanter

15
New cards

which step was ommited from the lecture development process?

a) documentation

b) unit testing

c) uml

d) stub methods

unit testing

16
New cards

what was the final step in the development process followed in the lecture?

a) uml

b) unit testing

c) documentation

d) coding methods

a) implementing/coding methods

17
New cards

which of the following types could be stored in a container of WaterMonster?

a) Squiiirtle

b) Starfishy

c) Peekatu

d) Monster

e) ElectricMonster

f) WaterMonster

squirtle, starfishy, watermonster

18
New cards

effective use of polymorphism is good because it increases coupling in a software system

false

19
New cards

which keyword is used to indicate inheritance in java?

extends

20
New cards

polymorphism can be used with both inherited super types and implemented interface types

true or false

true

21
New cards

which of the following methods are inherited from the Object class?

a) getClass()

b) equals()

c) scanner.readInt(),

d) System.out.println()

e) attack()

f) toString()

getClass, equals(), toString()

22
New cards

the downside to polymorphism is that you cannot convert an object back to its original type

false

23
New cards

which of the following are a benefit of polymorphism?

a) Reduces coupling

b) Reduces code

c) Simplifies code

d) Increases flexibility

all of the above

24
New cards

which keyword defines a class uses an interface in Java?

a) inherits

b) implements

c) instanceof

d) extends

implements

25
New cards

which of the following data structures in Java can store primitive types?

a) TreeMap

b) ArrayList

c) Array

d) HashSet

Array

26
New cards

An ArrayList uses an Array to store its data, and therefore an ArrayList has a fixed size that must be specified upon creation

false

27
New cards

An Array can only store primitive data types.

false

28
New cards

Both TreeMap and HashMap implement the same Map interface, and can therefore be used interchangeably

true or false

true

29
New cards

Imagine you are creating a role-playing game and need to store all of your inventory items in a collection. You want to be able to look up an item by name, and frequently get a list of all of the item names sorted alphabetically. Which of the following collections would you use?

a) TreeSet

b) TreeMap

c) Hashmap

d) LinkedList

TreeMap

30
New cards

Imagine you are in need of a collection that stores items in a linear structure and will be frequently inserting and deleting from the middle of the collection. Which collection would be the best option?

a) HashMap

b) TreeSet

c) ArrayList

d) LinkedList

d) LinkedList

31
New cards

The collections classes, such as LinkedList and TreeMap, are defined using Generic typing.

true or false

true

32
New cards

Generic typing is reserved for classes provided by Java, such as ArrayList. We cannot implement generic typing in custom classes.


False

33
New cards

It is possible to restrict a generic type to a particular supertype, such as a class or an interface type.

true or false

true

34
New cards

The Comparable interface allows different instances of the same class to be comparable using the '<' and '>' operators.

false

35
New cards

By implementing the Comparable interface, Java will automatically generate the rules by which to compare that object.

false

36
New cards

After an exception is caught, the program continues execution where the exception was originally thrown.

false

37
New cards

Which of the following scenarios describe a situation when an exception should be thrown?

a) a user enters bad/incorrect data

b) a test regression fails

c) a bug detected in the program

d) a parameter violates a stated precondition

a user enters bad data, a parameter violates a stated precondition

38
New cards

Where is the best place to catch and handle an exception?

a) the main program

b) the method that has enough information to most effectively handle the exception

c) immediately, the place where the method that threw the exception is originally called

the method that has enough information to most effectively handle the exception

39
New cards

A try-catch statement can catch multiple different types of exceptions from the same try block.

true or false

true

40
New cards

When using the Scanner class' nextInt() method, which of the following exceptions are most likely to be thrown if the user enters something that isn't a number?

a) ArithmeticException

b) InputMismatchException

c) NullPointerException

d) InputMismatchException

InputMismatchException

41
New cards

Which of the following statements about exceptions is true? 

a) A checked exception is named because it indicates a bug that should have been checked over by the programmer

b) Unchecked exceptions are things like IOException and FileNotFoundException

c) Your code will not compile if you don't try to catch a potential checked exception

d) Your code will not compile if you don't try to catch a potential unchecked exception

Your code will not compile if you don't try to catch a potential unchecked exception

42
New cards

Which of the following will create a pop-up dialogue box, prompting the user to enter some text into the program?

a) JOptionPane.showMessageDialogue()

b) JOptionPane.showOptionDialogue()

c) JOptionPane.showConfirmDialogue()

d) JOptionPane.showInputDialogue()

JOptionPane.showInputDialogue()

43
New cards

Which of the following classes in Java Swing represents the application's window?

a) JWindow

b) JFrame

c) JPanel

d) JLabel

b) JFrame

44
New cards

Which of the following is not a JComponent?

JFrame

JPanel

JButton

JLabel

JFrame

45
New cards

Which of the following is a container widget/component?

JButton

JPanel

JLabel

JTextField

JPanel

46
New cards

When creating a graphical user interface, the interface is automatically made visible when the JFrame object is created.

false

47
New cards

JFrame is a Java class, which means we can create a custom window/frame by creating our own custom class which inherits from JFrame.

true or false

true

48
New cards

In the event delegation model, which of the following is a JButton?

Event Source

Event Handler

Event

Listener

Event Source

49
New cards

Assume you want to respond to a button click. Which of the following describes the process?

You create a class that inherits from ActionListener

You create a class that implements the ActionListener interface

You directly bind a method to the button using the 'addMethodBinding()' method

You write a method called 'actionPerformed()' which is automatically bound to the button

You create a class that implements the ActionListener interface

50
New cards

Consider the following code:

public class MyFrame extends JFrame {

    JButton myButton;

    public MyFrame(){
        JPanel panel = new JPanel();
        myButton = new JButton("Click me");
        myButton.addActionListener(new MyClickListener());
        panel.add(myButton);
        this.setContentPane(panel);
    }

    class MyClickListener implements ActionListener {

        public void actionPerformed(ActionEvent e){
        System.out.println("clicked");
        }
    }
 }

Which of the following describes what 'MyClickListener' is?

A method

An Anonymous class

A Local Inner class

A Nested Inner class

A Nested Inner class

51
New cards

An anonymous inner class is defined without needing to assign the class a name.

true or false

true

52
New cards

In software design, a goal is to maximize cohesion.

true or false

true

53
New cards

In software design, a goal is to maximize coupling.

false

54
New cards

A design pattern and an algorithm are the same thing.

false

55
New cards

Which type of design pattern is the Singleton Pattern?

Adaptable

Structural

Behavioural

Creational

Creational

56
New cards

Which features does the Singleton Pattern provide?

Encapsulates an action or behaviour into a separate class

An abstracted approach for broadcasting updates to other objects in the system

Provides global access to the object instancer

Guarantees at most one instance of the class can exist in the system

Provides global access to the object instancer

Guarantees at most one instance of the class can exist in the system

57
New cards

A static method can access both static variables and instance variables.

false

58
New cards

Which of the following is not part of the Singleton Pattern?

A public, static method that returns the instance

A public constructor

Creating an instance if one doesn't already exist

A private, static instance to an object of its own type

A public constructor

59
New cards

What type of design pattern is the Factory Pattern?

Behavioural

Adaptable

Creational

Structural

Creational

60
New cards

What is the main goal of the Factory Pattern?

To create lots of objects very quickly

To encapsulate an action or method as a separate object

To guarantee at most one instance of a class can exist in the system

To abstract the creation of a class or a hierarchy of classes

To abstract the creation of a class or a hierarchy of classes

61
New cards

In lecture, our initial implementation of the Factory Pattern used Strings as the parameter type to the factory method. What was the issue with this design choice?

It is easy to make spelling errors

It made the coupling between the main program and the factory too high

The Factory was inefficient

The factory wasn't returning the correct type of object

It is easy to make spelling errors

62
New cards

What type was String replaced with in the second iteration of the Factory?


A Set

A character Array

An integer

A Java enum

A Java enum

63
New cards

In the third iteration of the factory, we refactored the Monster inheritance hierarchy. Which classes in the system had to be rewritten to accommodate this large refactor (besides the Monster classes themselves)?


Only the MonsterFactory class

The main program and the MonsterFactory class

The main program

Everything

Only the MonsterFactory class

64
New cards

Which type of design pattern is the Strategy Pattern?


Creational

Structural

Adaptable

Behavioural

Behavioural

65
New cards

What is the main goal of the Strategy Pattern?


Define and encapsulate a family of algorithms to make them interchangeable in the program

To encapsulate a method for the purpose of storing actions in data structures

To gain global access to a specific object instance

To more efficiently create object instances

Define and encapsulate a family of algorithms to make them interchangeable in the program

66
New cards

What is meant by the principle to "program to the supertype, not an implementation"?

More levels of inheritance are always better to increase cohesion

You should store objects in the most specific type possible

When using Java Collections, you should pick the correct type to best model your program

You should store objects in the most general type possible

You should store objects in the most general type possible

67
New cards

What is meant by the principle of "favour composition over inheritance"?

You should prioritize 'is-a' relationships over 'has-a' relationships

Inheritance is always the best approach to designing and organizing your program

Inheritance always over complicates your program and it should be avoided

In some cases, encapsulating behaviours as objects makes the program more flexible than using inheritance

In some cases, encapsulating behaviours as objects makes the program more flexible than using inheritance

68
New cards

Which of the following would be reasonable candidates for using the Strategy Pattern?

Implementing an 'undo/redo' system

Abstracting the creation of many different types of ducks

Creating a bunch of different types of shapes in a drawing program

Managing a Queue of web requests

Choosing different routing algorithms in a map program

Storing a central data structure of Student objects

Equipping different attacks/abilities to a pokemon

Choosing different routing algorithms in a map program, Equipping different attacks/abilities to a pokemon

69
New cards

What are the three layers in the 'Three-Layer Architecture'?

Presentation, Domain, System

70
New cards

Which of the following is NOT true about the Three-Layer Architecture?


The Command pattern can be used to coordinate between the Presentation and Domain layer

The Observer Pattern is used to update the databases whenever classes in the Domain layer change

It promotes increased cohesion by forcing classes to be focused on smaller tasks

Each layer can only call methods in the layer below

The Observer Pattern is used to update the databases whenever classes in the Domain layer change

71
New cards

Which type of design pattern is the Command Pattern?

Adaptable

Creational

Behavioural
Structural

Behavioural

72
New cards

What is the main goal of the Command Pattern?

Define and encapsulate a family of algorithms to make them interchangeable in the program

To more efficiently create object instances

To encapsulate a method for the purpose of storing actions in data structures

To gain global access to a specific object instance

To encapsulate a method for the purpose of storing actions in data structures

73
New cards

The Command Pattern uses Inheritance instead of Composition

False

74
New cards

How are individual commands abstracted?

Commands don't share a common supertype, but they can be stored in the same data structure

An intermediate class handles the creation and management of Command objects

Commands all inherit from a common super class

Commands all implement the same 'Command' interface

Commands all implement the same 'Command' interface

75
New cards

Which of the following would be reasonable candidates for using the Command Pattern?

Storing a centra data structure of Student objects

Equipping different attacks/abilities to a Pokemon

Creating a bunch of different types of shapes in a drawing program

Choosing different routing algorithms in a map program

Implementing an 'undo/redo' system

Managing a Queue of web requests

Abstracting the creation of many different types of ducks

Implementing an 'undo/redo' system

Managing a Queue of web requests

76
New cards

Client/Driver

Creates the objects and sets up the pattern

77
New cards

Subject/Observable

The thing being observed

78
New cards

Observer

The classes that receive notifications/updates

79
New cards

indicate the corresponding component of an analogy using Podcast distribution: Observer

The user that subscribes and listens to the podcast

The publisher/creator of the podcast

The act of subscribing to a podcast

The user that subscribes and listens to the podcast

80
New cards

indicate the corresponding component of an analogy using Podcast distribution: Subject/Observable

The user that subscribes and listens to the podcast

The publisher/creator of the podcast

The act of subscribing to a podcast

The publisher/creator of the podcast

81
New cards

indicate the corresponding component of an analogy using Podcast distribution: Client/Driver

The user that subscribes and listens to the podcast

The publisher/creator of the podcast

The act of subscribing to a podcast

The act of subscribing to a podcast

82
New cards

In order to minimize coupling, the Subject should minimize it's knowledge about the Observer's details, but the Observer should always have full access to the Subject.

false

83
New cards

Which of the following describes the use of UML 'ball-and-socket' notation?

Creating an interface to abstract/loosen coupling between two objects

An alternative version of 'Composition' and 'Aggregation' that indicates a stronger contains relationship

A special kind of inheritance used in the Observer Design pattern

Indicates a part of the program with excessive coupling that needs to be fixed

Creating an interface to abstract/loosen coupling between two objects

84
New cards

Which of the following previous topics uses the Observer pattern?

ArrayLists

ActionListeners

Polymorphism

Encapsulation

ActionListeners

85
New cards

Which design pattern is commonly used in the Model-View-Controller architecture?

Strategy

Observer

Factory

Command

Observer

86
New cards

Which of the following would be the responsibility of the Model?

Interprets user input through ActionListeners

Visually presents data to the user

Generate ActionEvents in response to user interaction

Perform the program's business logic

Call methods on the Model in response to user commands

Update the View when the program's data changes

Perform the program's business logic

Update the View when the program's data changes

87
New cards

Which of the following would be the responsibility of the Controller?

Generate ActionEvents in response to user interaction

Perform the program's business logic

Interprets user input through ActionListeners

Update the View when the program's data changes

Call methods on the Model in response to user commands

Visually presents data to the user

Interprets user input through ActionListeners

Call methods on the Model in response to user commands

88
New cards

Which of the following would be the responsibility of the View?

Generate ActionEvents in response to user interaction

Interprets user input through ActionListeners

Visually presents data to the user

Perform the program's business logic

Call methods on the Model in response to user commands

Update the View when the program's data changes

Generate ActionEvents in response to user interaction

Visually presents data to the user

89
New cards

Which part of the architecture is the Observer?

Model

Main Program

Controller

View

View

90
New cards

When does the Model send an update to the View?


Every time the data changes

Every second

It doesn't

60 times per second


Every time the data changes

91
New cards

To create a custom GUI element/widget, which class do we need to inherit from?


JFrame

Observable

JWidget

JComponent

JComponent

92
New cards

Which method needs to be overridden to make a custom GUI element/widget appear?

drawWidget

fillRect

repaint

paintComponent

paintComponent

93
New cards

Which method needs to be called in order to update a custom GUI element/widget's appearance at runtime?

fillRect

drawWidget

repaint

paintComponent

repaint

94
New cards

What type of object is passed into the paintComponent method as a parameter?

Graphics

Canvas

GraphicsContext

Context

Graphics

95
New cards

When you are writing code to draw a GUI element/widget, you need to set the colour for each shape you draw

true or false

false

96
New cards

By default, a javax.swing Timer object will send an ActionEvent repeatedly with a specified delay

true or false

true

97
New cards

A javax.swing Timer automatically starts when the Timer object is created

true or false

false

98
New cards

n the Flashing Rectangle example from class, which part of the MVC architecture managed the Timer to initiate animation changes?

Controller

Model

Main Program

View

controller

99
New cards

In the Flashing Rectangle example from class, which part of the MVC architecture stored the animation data (i.e., the sequence of colours)?

Model

View

Main Program

Controller

Model