AP Computer Science Chapter 12 Flashcards
57 Questions
100 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following most likely indicates that you have chosen a good name for your class? (Select all that apply)

  • The name consists of a single word.
  • You can tell by the name what an object of the class is supposed to represent. (correct)
  • The name describes what task the class will perform.
  • You can easily determine by the name how many concepts the class represents.
  • Which of the following questions should you ask yourself in order to determine if you have named your class properly?

  • Is the class name a verb?
  • Can I visualize an object of the class? (correct)
  • Does the class name describe the tasks that this class will accomplish?
  • Does the class name contain 8 or fewer characters?
  • Which of the following would be an appropriate name for a game-related class?

  • ResetTheCurrentLevel
  • InitialLevel (correct)
  • FinalizeLevelOne
  • AscendToFinalLevel
  • Which of the following would be an appropriate name for a class used in an inventory application?

    <p>Product</p> Signup and view all the answers

    You are designing an application to support an automobile rental agency. Which of the following probably should NOT be represented as an object?

    <p>Payment amount</p> Signup and view all the answers

    You are designing an application to support a veterinary clinic. Which of the following probably should NOT be represented as an object?

    <p>Drug dosage</p> Signup and view all the answers

    Classes often correspond to ____ in a requirements description.

    <p>Nouns</p> Signup and view all the answers

    A/an ____ represents a set of objects with the same behavior.

    <p>Class</p> Signup and view all the answers

    After you have identified a set of classes needed for a program, you should now ____.

    <p>Define the behavior of each class.</p> Signup and view all the answers

    A CRC card describes ____.

    <p>A class, its responsibilities, and its collaborating classes.</p> Signup and view all the answers

    When using the CRC method, other classes that are needed to fulfill the responsibilities of a given class are called its ____.

    <p>Collaborators.</p> Signup and view all the answers

    When using the CRC method, if you determine that a class cannot carry out a particular task by itself and needs the help of another class to complete the task, you should ____.

    <p>Add the other class onto this class's CRC card as a collaborator.</p> Signup and view all the answers

    Which of the following is the most important consideration when designing a class?

    <p>Each class should represent a single concept or object from the problem domain.</p> Signup and view all the answers

    Under which of the following conditions would the public interface of a class be considered cohesive?

    <p>All of its features are related to the concept that the class represents.</p> Signup and view all the answers

    A class (ClassOne) is considered to have a dependency on another class (ClassTwo) under which of the following conditions?

    <p>ClassOne uses objects of ClassTwo.</p> Signup and view all the answers

    A UML class diagram would be most useful in visually illustrating which of the following?

    <p>Dependencies between classes.</p> Signup and view all the answers

    Why is it generally considered good practice to minimize coupling between classes?

    <p>High coupling increases program maintenance and hinders code reuse.</p> Signup and view all the answers

    Dependency between classes denotes that ____.

    <p>Methods in the objects of one class use an object of another class.</p> Signup and view all the answers

    In a UML diagram, dependency is denoted by ____.

    <p>A dotted/dashed line with an open arrow tip.</p> Signup and view all the answers

    If many classes of a program depend on each other, we say that ____.

    <p>Coupling is high.</p> Signup and view all the answers

    UML means ____.

    <p>Unified Modeling Language.</p> Signup and view all the answers

    The dependency relationship is sometimes referred to as the ____ relationship.

    <p>knows-about</p> Signup and view all the answers

    Which statement correctly describes the class relationship shown in this diagram? CASHREGISTER - - - - - - > COIN

    <p>Coin class depends on CashRegister class</p> Signup and view all the answers

    Which of the following code snippets denotes that the Purse class depends on the Wallet class?

    <p>public class Purse { private Wallet aWallet; }</p> Signup and view all the answers

    Which of the following code snippets denotes that the Pen class depends on the Ink class?

    <p>public class Pen { private Ink anInk; }</p> Signup and view all the answers

    Which of the following code snippets denotes that the Kitchen class depends on the Stove class?

    <p>public class Kitchen { private Stove aStove; }</p> Signup and view all the answers

    ____ is often described as the has-a relationship.

    <p>Aggregation.</p> Signup and view all the answers

    Which of the following statements is correct?

    <p>Aggregation is a stronger form of dependency.</p> Signup and view all the answers

    Consider the following code snippet: public class Motorcycle { private Tire[] tires; ...} This code is best described as an example of ____.

    <p>Aggregation.</p> Signup and view all the answers

    Consider the following code snippet: public class Motorcycle { private Tire[] tires; ...} Which of the following statements correctly describes the relationship between the Motorcycle and Tire classes?

    <p>Motorcycle exhibits the has-a relationship with regards to Tire.</p> Signup and view all the answers

    Consider the following code snippet: public class Purse { private Coin[] coins; ...} This code is best described as an example of ____.

    <p>Aggregation.</p> Signup and view all the answers

    Consider the following code snippet: public class Purse { private Coin[] coins; ...} Which of the following statements is correct?

    <p>Purse aggregates Coin.</p> Signup and view all the answers

    Aggregation denotes that ____.

    <p>Objects of one class contain references to objects of another class.</p> Signup and view all the answers

    A CashRegister class contains an array list of Coin objects. This is best described as an example of ____.

    <p>Aggregation</p> Signup and view all the answers

    A Quiz class contains an array of Question objects. This is best described as an example of ____.

    <p>Aggregation</p> Signup and view all the answers

    In a UML diagram, aggregation is denoted by ____.

    <p>A solid line with a diamond-shaped symbol next to the aggregating class.</p> Signup and view all the answers

    In general, you need ____ when an object needs to remember another object between method calls.

    <p>Aggregation</p> Signup and view all the answers

    Which statement correctly describes the class relationship shown in this diagram? QUIZ -------- QUESTION

    <p>Quiz class aggregates Question class.</p> Signup and view all the answers

    Which of the following code snippets denotes that the Fleet class aggregates the Taxi class?

    <p>public class Fleet { private ArrayList taxicabs; }</p> Signup and view all the answers

    Which of the following code snippets denotes that the Kitchen class aggregates the Dish class?

    <p>public class Kitchen { private Dish[] dishes; }</p> Signup and view all the answers

    ____ is often described as the is-a relationship.

    <p>Inheritance.</p> Signup and view all the answers

    Consider the following code snippet: public class Motorcycle extends Vehicle { private Tire[] tires; ...} This code is best described as an example of ____.

    <p>Inheritance and aggregation.</p> Signup and view all the answers

    Consider the following code snippet: public class Motorcycle extends Vehicle { ...} Which of the following statements correctly describes the relationship between the Motorcycle and Vehicle classes?

    <p>Motorcycle exhibits the is-a relationship with regard to Vehicle.</p> Signup and view all the answers

    Consider the following code snippet: public class Motorcycle extends Vehicle { private Tire[] tires; private Engine anEngine; ...} Which of the following statements describing relationships between the Motorcycle, Tire, Engine and Vehicle classes is NOT correct?

    <p>Vehicle exhibits the has-a relationship with regards to Motorcycle.</p> Signup and view all the answers

    Consider the following code snippet: public class PowerBoat extends Vessel { private Engine[] engines; ...} This code is best described as an example of ____.

    <p>Inheritance and aggregation.</p> Signup and view all the answers

    Consider the following code snippet: public class SailBoat extends Vessel { private Engine[] engines; private Sail mainsail; ...} Which of the following statements is NOT correct?

    <p>Sail depends on Sailboat.</p> Signup and view all the answers

    Consider the following code snippet: public class SailBoat extends Vessel { ...} public class Catamaran extends SailBoat { ...} Which of the following statements is NOT correct?

    <p>Catamaran depends on SailBoat.</p> Signup and view all the answers

    Consider the following code snippet: public class Manager extends Employee {private Project[] projects; private Address address; ...} Which of the following statements is NOT correct?

    <p>Address aggregates Manager.</p> Signup and view all the answers

    In a UML diagram, inheritance is denoted by ____.

    <p>A solid line with a closed arrow tip pointing to the superclass.</p> Signup and view all the answers

    Which of the following statements about class relationships is correct?

    <p>Inheritance represents the is-a relationship, while aggregation represents the has-a relationship.</p> Signup and view all the answers

    Which of the following code snippets denotes that the Lime class inherits from the Citrus class?

    <p>public class Lime extends Citrus</p> Signup and view all the answers

    Which of the following code snippets denotes that the Rose class inherits from the Flower class?

    <p>public class Rose extends Flower</p> Signup and view all the answers

    When designing classes, if you find classes with common behavior you should ____.

    <p>Place the common behavior into a superclass.</p> Signup and view all the answers

    In a UML diagram, an interface implementation is denoted by ____.

    <p>A dotted line with a closed arrow tip.</p> Signup and view all the answers

    In a UML diagram, the relationship symbol shown below denotes ____.

    <p>Aggregation</p> Signup and view all the answers

    In a UML diagram, the relationship symbol shown below denotes ____.

    <p>Interface implementation</p> Signup and view all the answers

    In a UML diagram, the relationship symbol shown below denotes ____.

    <p>Inheritance</p> Signup and view all the answers

    Study Notes

    Class Naming and Responsibilities

    • A good class name clearly indicates what an object represents, enhancing readability and maintainability.
    • Class names should visualize an object; they should not be mere verbs but should clarify the purpose or role of the class.

    Selecting Class Names

    • Appropriate class names for games should be simple and intuitive, such as InitialLevel, which indicates clear functionality.
    • For an inventory application, a name like Product reflects core class responsibilities and is suitable.

    Object Representation

    • In applications like automobile rentals or veterinary clinics, certain concepts, like payment amounts or drug dosages, may not require object representation as standalone entities.

    Class Characteristics

    • Classes typically correspond to nouns in requirement descriptions, signifying the objects or concepts being modeled.
    • A class encapsulates a set of objects with shared behavior, referred to as a "class."

    Behaviors and Relationships

    • Identify necessary behaviors for each class before code writing to ensure an organized method of development.
    • CRC (Class-Responsibility-Collaborator) cards detail a class, its responsibilities, and its collaborating classes.

    Cohesion and Dependencies

    • A cohesive public interface means all features relate to the concept the class represents, enhancing clarity and usability.
    • Dependency between classes happens when one class requires another’s objects to fulfill functions. It is visually represented in UML diagrams as a dashed line with an open arrow tip.

    Coupling Considerations

    • Minimizing coupling between classes is vital as it enhances maintainability and code reuse, reducing complexity.

    UML Diagrams

    • UML diagrams visually represent class relationships, with dependencies illustrated by dashed lines. Aggregation is depicted with solid lines and diamond symbols next to the aggregating class.

    Inheritance and Relationship Types

    • Inheritance represents an is-a relationship, while aggregation represents a has-a relationship, each serving different design needs.
    • Aggregation indicates one class contains references to another class, exemplified by a class containing an array or collection of objects from another class.

    Code Snippets and Class Relationships

    • Code snippets illustrate various relationships. For example, when a class contains a collection of another class's objects, it's aggregation.
    • Inheritance is denoted by extending a class, indicating the child class derives from the parent class, which supports shared behavior and properties.

    Best Practices in Class Design

    • When faced with common behaviors across classes, encapsulate shared behaviors into a superclass to adhere to DRY (Don't Repeat Yourself) principles.
    • Interfaces in UML diagrams signify relationships and are represented with distinct notation (dashed lines with closed arrow tips) to demonstrate functionality.

    Key Concepts

    • Dependency denotes a use relationship among classes, critical in structuring complex programs.
    • Understanding different types of relationships (aggregation, inheritance, dependency) enhances object-oriented design skills and code organization.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Test your knowledge with these flashcards for Chapter 12 of AP Computer Science. This quiz focuses on key concepts like class naming and object representation in programming. Perfect for exam revision and self-assessment.

    More Like This

    Class Naming Convention Quiz
    3 questions
    Ruby Class Methods and Naming Conventions
    5 questions
    Use Quizgecko on...
    Browser
    Browser