Wednesday, April 21, 2021

Java Chapter 6 Exercise Answers


  • A String object's behavior includes its methods, such as length, substring, toUpperCase, and indexOf. Output of ReferenceMystery3 program: 14 14 7 9 14 2 18 18 7 9 14 18 The state of a Calculator object might include the number that has just been...
    Link: https://cindyparrett.com/?notes=b02-iso-iec-li-test-voucher--0-gaqm-iso-iec-li-exam-questions-and-answers--1-iso-iec-27002-lead-implementer.html


  • A field is a variable that exists inside of an object. A parameter is a variable inside a method whose value is passed in from outside. Fields have different syntax because they are usually declared with the private keyword and not in a method's...
    Link: https://ral.ucar.edu/projects/wrf_hydro/testcases
  • To access private fields, create accessor methods that return their values. For example, add a getName method to access the name field of an object. When a class is encapsulated clients cannot directly access its fields, so changing those fields will not disturb client behavior as long as the external view method behavior is consistent. Cohesion is the concept of how well a class's contents go together.
    Link: https://quizlet.com/explore/highest-and-best-use/
  • You can tell that a class is cohesive when each of its fields stores important state related to the object and each method interacts with that state in some way to produce useful behavior. Inheritance is useful for code reuse because it allows you to write a class that captures common useful code and then extend that class to add more features and behavior to it.
    Link: https://multiservizi-bologna.it/perceptual-acuity-definition.html
  • Overloading a method involves creating two methods in the same class that have the same name but different parameters. Overriding a method involves creating a new version of an inherited method in a subclass, with identical parameters but new behavior to replace the old. Correct syntax to indicate that class A is a subclass of B: a. Use the super keyword when calling a method or constructor from the superclass that you've overridden, and use the this keyword when accessing your object's own fields, constructors, and methods. UndergraduateStudent can call the setAge method but cannot directly access the name or age fields from Student.
    Link: http://cp.universiapolis.ma/cgi-bin/file.php?article=plato-geometry-semester-2-answers-bing-fuannaore-pdf&code=fbd2cac3d126c785b58889f6dcfb9be6
  • A has-a relationship is when one object contains a reference to another as a field. Having Square extend Rectangle is a poor design because a Square cannot substitute for a Rectangle. If the client thinks the Square is a Rectangle and calls setWidth or setHeight on it, unexpected results will occur. The client will expect the width and height to be different after the call, but they may not be.
    Link: http://samah-ecobil.co.kr/data/breaking-the-pdi/article.php?ee697f=ap-bio-unit-3-progress-check-frq-answers
  • Having each of the 52 playing cards in its own class is not a good design because it will result in a clutter of code files without significant differences between them. A better design would have one Card class with fields for rank and suit. We made DividendStock a separate subclass from Stock for two major reasons. First, not all stocks pay dividends, so it does not make sense for every Stock object to have a dividends field and a payDividend method. Second, the Stock code already worked correctly, so we did not want to tamper with it needlessly. Making DividendStock a separate class constituted an additive and noninvasive change. Extending a class causes your class to inherit all methods and data from that class. Implementing an interface forces you to write your own code to implement all the methods in that interface.
    Link: https://answers.yahoo.com/question/index?qid=20070914233912AAk5cuw
  • The code for class C must contain implementations of the methods m1 and m2 to compile correctly, because C claims to implement the I interface. What's wrong is that interfaces can't declare fields or write bodies for methods. The following is a correct Colored interface: import java. It's like a normal class in that it can have fields, methods, constructors, and so on. It's different from a normal class in that it can have abstract methods, which are like methods of an interface because only their headers are given, not their bodies. It's also different from a normal class because it can't be instantiated used to create objects. You can be sure that the OrderedByLength class contains a getElement method and that it implements the arrange method, because if it extends Ordered without being abstract itself, it must have that method in order to compile.
    Link: https://in.pinterest.com/mridulchandhok/sample-question-paper/
  • One good design would be to have an abstract superclass named Movie with data such as name, director, and date. There would be subclasses of Movie to represent particular movie types, such as Drama, Comedy, and Documentary. Each subclass would store its specific data and behavior. Chapter 10 An ArrayList is a structure that stores a collection of objects inside itself as elements. Each element is associated with an integer index starting from 0. You should use an ArrayList instead of an array if you don't know how many elements you'll need in advance, or if you plan to add items to or remove items from the middle of your dataset.
    Link: https://in.answers.yahoo.com/question/index?qid=20120428214455AAK3Lcz
  • Correct syntax to construct an ArrayList to store integers: e. Code to insert two additional elements, "dark" and "and", at the proper places: list. The code doesn't compile because primitives cannot be specified as type parameters for generic types. The solution is to use the "wrapper" type Integer instead of int. An Integer is an object that holds an int value. Wrappers are useful in that they allow primitive values to be stored into collections. Output produced when the mystery1 method is passed each list: [1, 2, 6, 8] [10, 30, 40, 20, 60, 50] [-4, 1, 25, 4, 16, 9, 64, 36, 49] Output produced when the mystery2 method is passed each list: [20, 10, 20, 30, 30, 20] [8, 7, 8, 2, 9, 7, 4, 4, 2, 8] [33, 28, 33, -1, 3, 28, 17, 9, 33, 17, -1, 33] Output produced when the mystery3 method is passed each list: [72, 20] [1, 20, 18, 15, 11, 6] [10, 90, 70, 40] Output produced when the mystery4 method is passed each list: [31, 21, 11].
    Link: https://mpscmaterial.com/category/mpsc-combine-exam/
  • True True or False: Each instance of a class has its own set of instance fields. True True or False: When you write a constructor for a class, it still has the defaultconstructor that Java automatically provides. False True or False: A class may not have more than one constructor. False True or False: To find the classes needed for an object-oriented application, youidentify all of the verbs in a description of the problem domain. Find the error. Both are empty. Bothaccept an int. The name field holds the name of a pet. The animal field holds the type of animal that a pet is. The setName method stores a value in the name field.
    Link: https://sites.google.com/a/ddsd40.org/ddhs-ap-human-geography/home/ap-test-review-info
  • The setAnimal method stores a value in the animal field. The setAge method stores a value in the age field. The getName method returns the value of the name field. The getAnimal method returns the value of the animal field. The getAge method returns the value of the age field. Draw a UML diagram of the class. Also include notation showing anymethod parameters and their data types. Write the Java code for the Pet class. UML diagram B. Write a constructor for this class. The constructor should accept an argument foreach of the fields. Write accessor and mutator methods for each field. Draw a UML diagram for the class, including the methods you have written.
    Link: http://knyl.artzonestore1.com/
  • Object-oriented programming looks at a program as a group of interacting entities named objects that each keep track of related data and behavior. An object is an entity that encapsulates data and behavior that operates on the data. A class is the blueprint for a type of object, specifying what data and behavior the object will have and how to construct it. The state of a String object is its sequence of characters which are actually stored internally as an array of char values. A String object's behavior includes its methods, such as length, substring, toUpperCase, and indexOf. Output of ReferenceMystery3 program: 14 14 7 9 14 2 18 18 7 9 14 18 The state of a Calculator object might include the number that has just been computed, as well as another number that is currently being input.
    Link: http://notaryexam.ninja/
  • A more complex Calculator object might also include a memory feature that stores an additional value. The behavior of a Calculator object might include methods to add, subtract, multiply, divide, and perhaps carryout other math operations such as exponentiation, logarithms, and trigonometric functions like sine and cosine. A field is a variable that exists inside of an object. A parameter is a variable inside a method whose value is passed in from outside. Fields have different syntax because they are usually declared with the private keyword and not in a method's header. A field's scope is throughout the class, while a parameter's scope is limited to the method. Accessors' names often begin with "get" or "is", while mutators' names often begin with "set".
    Link: https://amazon.com/User-Friendly-Hidden-Design-Changing/dp/0374279756
  • Correct syntax for calling computeInterest method on a BankAccount object: d. The println statement is equivalent to the following: c. It's the method that is called when you use the new keyword. A constructor is declared without a return type. Two errors with the Point constructor: The constructor shouldn't have the void keyword in its header, because constructors have no return type.
    Link: https://medium.com/the-view-from-space/landsaturated-6affa80a4f3f
  • This bug causes shadowing of the fields. It is used to access or set the object's field values, to call the object's methods, or to call one constructor from another. Objects provide abstraction by giving us more powerful pieces of data that have sophisticated behavior without having to manage and manipulate the data directly. Items declared public may be seen and used from any class. Items declared private may be seen and used only from within their own classes. Objects' fields should be declared private to provide encapsulation, so that external code can't make unwanted direct modifications to the fields' values.
    Link: https://amp.doubtnut.com/question/p-solve-fylogn-2-ydn-ndy-6699111
  • To access private fields, create accessor methods that return their values. For example, add a getName method to access the name field of an object. When a class is encapsulated clients cannot directly access its fields, so changing those fields will not disturb client behavior as long as the external view method behavior is consistent. Cohesion is the concept of how well a class's contents go together. You can tell that a class is cohesive when each of its fields stores important state related to the object and each method interacts with that state in some way to produce useful behavior. Inheritance is useful for code reuse because it allows you to write a class that captures common useful code and then extend that class to add more features and behavior to it.
    Link: https://nicholasdale.files.wordpress.com/2017/12/11-maths-kent-college.pdf
  • Overloading a method involves creating two methods in the same class that have the same name but different parameters. Overriding a method involves creating a new version of an inherited method in a subclass, with identical parameters but new behavior to replace the old. Correct syntax to indicate that class A is a subclass of B: a. Use the super keyword when calling a method or constructor from the superclass that you've overridden, and use the this keyword when accessing your object's own fields, constructors, and methods. UndergraduateStudent can call the setAge method but cannot directly access the name or age fields from Student. A has-a relationship is when one object contains a reference to another as a field. Having Square extend Rectangle is a poor design because a Square cannot substitute for a Rectangle.
    Link: https://questions.examside.com/past-years/gate/question/a-kelvin-double-bridge-is-best-suited-for-the-measurement-of-gate-ee-1995-marks-1-qtx0adkynb03esak.htm
  • If the client thinks the Square is a Rectangle and calls setWidth or setHeight on it, unexpected results will occur. The client will expect the width and height to be different after the call, but they may not be. Having each of the 52 playing cards in its own class is not a good design because it will result in a clutter of code files without significant differences between them. A better design would have one Card class with fields for rank and suit.
    Link: https://lobopintado.com/xld-dnp-openbullet/msw-angular.html
  • We made DividendStock a separate subclass from Stock for two major reasons. First, not all stocks pay dividends, so it does not make sense for every Stock object to have a dividends field and a payDividend method. Second, the Stock code already worked correctly, so we did not want to tamper with it needlessly. Making DividendStock a separate class constituted an additive and noninvasive change. Extending a class causes your class to inherit all methods and data from that class. Implementing an interface forces you to write your own code to implement all the methods in that interface. The code for class C must contain implementations of the methods m1 and m2 to compile correctly, because C claims to implement the I interface.
    Link: https://5points.com.ng/pdfs/national-open-university-of-nigeria-noun-aec-403-june-july-2013-examination-past-question-papers
  • What's wrong is that interfaces can't declare fields or write bodies for methods. The following is a correct Colored interface: import java. It's like a normal class in that it can have fields, methods, constructors, and so on. It's different from a normal class in that it can have abstract methods, which are like methods of an interface because only their headers are given, not their bodies. It's also different from a normal class because it can't be instantiated used to create objects. You can be sure that the OrderedByLength class contains a getElement method and that it implements the arrange method, because if it extends Ordered without being abstract itself, it must have that method in order to compile.
    Link: https://brainsanswers.com/mathematics/question20670050
  • One good design would be to have an abstract superclass named Movie with data such as name, director, and date. There would be subclasses of Movie to represent particular movie types, such as Drama, Comedy, and Documentary. Each subclass would store its specific data and behavior. Chapter 10 An ArrayList is a structure that stores a collection of objects inside itself as elements. Each element is associated with an integer index starting from 0. You should use an ArrayList instead of an array if you don't know how many elements you'll need in advance, or if you plan to add items to or remove items from the middle of your dataset. Correct syntax to construct an ArrayList to store integers: e. Code to insert two additional elements, "dark" and "and", at the proper places: list. The code doesn't compile because primitives cannot be specified as type parameters for generic types.
    Link: https://glassdoor.com/Interview/State-Farm-Interview-Questions-E2990.htm

No comments:

Post a Comment

Persona 5 October Exams

[DOWNLOAD] Persona 5 October Exams A: Stars Q: Now, do you know who invented this instrument? Do you remember? A2: It used to be one color Q...