Java Software Solutions 8th Edition Answers Test Pdf Free

Transcription

Continue39149144.851852 30869338534 23867747240 63380375528 19664651.526316 69597533 71478.25 72920684.478261 40390862988 25570638.037037 11036635.483146 15645787.038961

Java software solutions 8th edition answers test pdf freeSoftware engineering 8th edition solution manual pdf.The inner loop finds the smallest value in the rest of the list by scanning all positions greater than or equal to the index specified by the outer loop. KEY CON CEPT The versions of an overloaded method are distinguished by the number, type, and order of their parameters. In the linearSearch method, the while loop steps through the elements of thearray, terminating either when the target is found or the end of the array is reached. What is the relationship between them? Listing 7.8 shows an interface called Complexity. Therefore, it’s usually a good idea to define a toString method for most classes. M05 LEWI1724 09 GE C05.indd 239 25/09/17 5:13 PM 240 C HAP TE R 5 Conditionals andLoops Comparing Objects The Unicode relationships among characters make it easy to sort characters and strings of characters. If it’s not, the println statement is skipped and processing continues with whatever code follows it. The four basic transformation types are: Translation—changes the position of the node along the x or y axis. 25/09/174:08 PM 460 C HAP TE R 9 Inheritance The final modifier can also be applied to an entire class. SR 1.15 What is the total number of communication lines needed for a fully connected point-to-point network of five computers? Create a driver class to exercise some Task objects. Three kinds of objects cooperate to create a graphical user interface inJavaFX: controls events event handlers A GUI control is a screen element that displays information and/or allows the user to interact with a program in a certain way. The declarations of object variables have a similar structure to the declarations of primitive variables. ********************public class Employee extends StaffMember { protected String socialSecurityNumber; protected double payRate; ----------------// Constructor: Sets up this employee with the specified // information. VideoNote Comparison of Java IDEs. Included in the download of the Java Standard Edition is the Java SoftwareDevelopment Kit (SDK), which is sometimes referred to simply as the Java Development Kit (JDK). Such an approach seems ridiculous in today’s world of distributed processing, but it is a good example of how a large system can be obsolete by the time it is developed. 4 Command-Line Arguments LI S T ING 407 8 .1 ********************* // NameTag.java Author: Lewis/Loftus // // Demonstrates the use of command line arguments. 7 Method Design LISTING 357 7.17 ******************** // Num.java Author: Lewis/Loftus // // Represents a single integer as an object. Itcan hold one of the four Season values, but nothing else. (Processing I/O exceptions is discussed further in Chapter 11.) The body of the outer while loop will be executed as long as the hasNext method of the input file scanner returns true—that is, as long as there is more input in the data file to process. An interface reference variable can be used torefer to any object of any class that implements that interface. K E Y C O N CEP T While an identifier can be of any length, you should choose your names carefully. It takes just under 50 days for the timer to go from 232 down to zero. Decimal Integer Literal 0 129 029 L l An integer literal is composed of a series of digits followed by an optional suffixto indicate that it should be considered an integer. The equivalent assembly language code is somewhat readable, but it is more verbose and less intuitive. The System.out object represents an output device or file, which by default is the monitor screen. Describe the inheritance structure for JavaFX controls and shapes. ---------// Some comments such as those above methods or classes // deserve to be blocked off to focus special attention // on a particular aspect of your code. That is, we used the predefined classes in the Java API that are provided to us to make the process of writing p rograms easier. K E Y C O N CEP T M06 LEWI1724 09 GE C06.indd 29825/09/17 5:17 PM 6 . Each case has statements associated with it. s3 s2.concat(s1); SR 3.7 What output is produced by the following code fragment? If they do not match exactly, two println statements and an assignment statement are executed. SR 6.22 How would you rotate an Ellipse named oval 40 degrees clockwise? EX 7.17 Draw a UML classdiagram that shows the relationships among the elements of Exercise 7.16. One responds to the action event that occurs when an option is selected in the choice box. At the end of the program, it invokes a method called getCount through the class name, which returns the number of Slogan objects that were instantiated in the program. Design issuesrelated to polymorphism are examined. Special thanks go to the following people who provided valuable advice to us about this book via their participation in focus groups, interviews, and reviews. Although assembly language is an improvement over machine code from a programmer’s perspective, it is still tedious to use. (Volume πr2h, surfacearea 2πrh 2πr2.) Include a toString method that returns a one-line description of the cylinder. KEY CON CEPT Digital technology breaks information into discrete pieces and represents those pieces as numbers. Printing a student’s high test grade when the student’s average test grade should have been output. Designing a solution. The secondkind of problem occurs during program execution. Others are more interesting and require careful planning. Its constructor calls the constructor of FoodItem using the super reference, asserting that there are eight servings per pizza. M06 LEWI1724 09 GE C06.indd 316 25/09/17 5:17 PM Object-Oriented Design CH A P T ER 7 O BJ ECTI V E S Establish key issues related to the design of object-oriented software. For many traditional compilers, the source code is translated directly into a particular machine language. 4 c. ISBN 10: 1-292-22172-0 ISBN 13: 978-1-292-22172-4 British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library10 9 8 7 6 5 4 3 2 1 Typeset by Cenveo Publisher Services Printed and bound by Vivar in Malaysia A01 LEWI1724 09 GE FM.indd 2 20/10/17 5:40 PM This book is dedicated to our families. Include a method called reset that resets the temperature to 37 C. Before the loop begins, the first part of the header, called the initialization, is executed.Assuming the value of num1 is 2 and the value of num2 is 2? Continue playing until the user chooses to stop, then print the number of user wins, losses, and ties. If we want to represent more than two things, we need more than one bit. int size() Returns the number of elements in this list. Oracle, for developing Java programs that use the companythat manages the Java language, no longer graphics and GUIs. supports those older technologies. byte to char e. These modifications are included as a programming project at the end of the chapter. key typed A keyboard key that generates a character is typed (pressed and released). 2a 23/09/17 5:29 PM 144 C HAP TE R 3 Using Classes andObjects static int abs(int num) Returns the absolute value of num. PP 6.15 Write a JavaFX application that displays 10,000 very small circles (radius of 1 pixel) in random locations within the visible area. A review that steps carefully through a document, evaluating each section. be easily calculated. For example, the operator can be used asfollows: total 5; This performs the same operation as the following statement: total total 5; The right-hand side of the assignment operator can be a full expression. However, completely specifying the package and class name every time it is needed quickly becomes tiring. Let’s look at an example that demonstrates this situation. Enter apotential palindrome: abcddcba y That string IS a palindrome. Show how to both declare and populate team using an initializer list. This type of program interweaves the translation of code and the execution of the code. SR 4.28 What start angle and arc length would you specify to include the complete bottom half of the underlying ******************************** public class ArcDisplay extends Application { -------------------// Draws three arcs based on the same underlying ellipse. If the main method of the PigLatin class attempted to invoke the translateWord method, for instance, the compiler would issue anerror message. Once an array is declared to be a certain size, the number of values it can hold cannot be changed. (One mile equals 1.60935 kilometers.) Read the miles value from the user as a floating point value. Provide a method called setDailyAmount that accepts a day of a week as a number (0 for Sunday, 1 for Monday, and so on) and anamount and sets that amount as the daily sale amount. They didn’t factor in errors and inefficiencies that always occur in a complex system. PP 7.14 Write a JavaFX application that displays the top view of a battle tank that follows the movement of the mouse. The selectionSort method is polymorphic. In the Lincoln program, the reserved words usedare class, public, static, and void. A Die ming is defining classes that represent object also has various methods we can invoke on it, such as the objects with well-defined state and ability to roll the die or get its face value. The expression on the right-hand side of the operator is evaluated, then that result is added to the current value of the variable onthe left-hand side, and that value is stored in the variable. ************************ public class Rocket extends Application { -------------------// Displays a rocket lifting off. Likewise, Java assumes that all floating point literals are of type double. Others include plotters,which move pens across large sheets of paper (or vice versa) speakers, for audio output goggles, for virtual reality display Some devices can provide both input and output capabilities. KEY CON CEPT Private members are inherited by the child class, but cannot be referenced directly by name. Generic types are introduced as well.theSumOfTheSquaresOnTheOtherTwoSides c. Java follows a well-defined set of precedence rules that governs the order in which operators will be evaluated in an expression. The other method is discussed later in this section. Use the shapes found in the javafx.scene.shape package to construct the chart. Explore boolean expressions that can beused to make decisions. The Contact class implements the Comparable interface and therefore provides a definition of the compareTo method. EX 3.2 Write a statement that prints the 8th character of a String object called introduction. Provide a method called weeklyReport that prints the name and the total sale amount of each team member and thetotal amount for the entire team. It is part of the Java standard class library that can be found in any Java development environment. This values. K E Y C O N CEP T An array of size N is indexed from 0 to N–1. M09 LEWI1724 09 GE C09.indd 460 This approach is made possible by the inheritance relationships among many of the classes in theJavaFX API. However, the process of reading data from a memory location does not affect it. It should contain instance data that represents the start hour, end hour, start minute, and end minute. PP 3.14 Write a JavaFX application that displays your name rotated at a random angle (0 to 360). For example, we may say that all vehicles have aparticular speed. 7 bits c. When such failures occur, the operators at the power control center are responsible for keeping the load balanced. The numeric value is calculated by summing each letter of the name, assuming a 1, b 2, and so on. A third visibility modifier, protected, is relevant only in the context of inheritance. Likewise, mutatormethod names have the form setX, where X is the value they are setting. It also specifies the relationships among the classes. The do loop terminates when we run out of digits to process, which corresponds to the point when the variable number reaches the value zero. It should be done in situations in which a child class could possibly be used tochange functionality that you, as the designer, specifically want to be handled a certain way. Instead, an abstract class may contain a partial description that is inherited by all of its descendants in the class hierarchy. The method add is used to add several String objects to the end of the ArrayList in a specific order. EX 6.10 Write a code fragment thatdetermines and prints the total number of uppercase characters in a String object named title. The Object class is defined in the java.lang package of the Java standard class library. M01 LEWI1724 09 GE C01.indd 71 23/09/17 3:36 PM 72 C HAP TE R 1 Introduction The principles of object-oriented software development have been around for manyyears, essentially as long as high-level programming languages have been used. The programmer does not have to worry about explicitly reclaiming memory that has become garbage. The software that controls the movement of messages across the Internet must conform to a set of protocols called TCP/IP (pronounced by spelling out the letters, TCP-I-P). A set of methods is associated with an object. SR 9.28 What does the getValue method of a DatePicker object return? The Method Body is a block of statements that executes when the method is invoked. Programmers can and should include tate human comprehension. The goal is to ensure that every path through a program is executed atleast once. The default constructor is used if we don’t M04 LEWI1724 09 GE C04.indd 197 23/09/17 5:06 PM 198 C HA PTE R 4 Writing Classes provide our own. In Chapter 6, we’ll see that using the break statement is usually necessary when writing switch statements. iResult o. SR 9.5 Why is the super reference important to a child class? This isthe essence of polymorphism. A check box is defined by the CheckBox class from the JavaFX API. Likewise if it currently refers to a Horse object. Carefully compare the output of the Countdown program, shown at the bottom of the program listing, to the program code. 3 Comparing Data 241 To determine the relative ordering of two strings, use thecompareTo method of the String class. For years, Robert has consistently provided valuable feedback that helps shape and evolve this textbook. The shape of an ellipse is based on two radius values: one along the horizontal, or x-axis, and one along the vertical, or y-axis. M08 LEWI1724 09 GE C08.indd 419 25/09/17 5:22 PM 420 C HAP TE R 8

Arrays Like other shapes, the fill color, stroke color, and stroke width of polygons and polylines can be set using calls to the appropriate methods. They include chips, boxes, wires, keyboards, speakers, disks, memory cards, universal serial bus (USB) flash drives (also called jump drives), cables, plugs, printers, mice, monitors, routers, and so on.Listings. Figure 5.1 lists the Java equality and relational operators. This leads to error messages that are sometimes difficult to decipher. By providing multiple versions of a constructor, we provide multiple ways to set up an object. PP 5.13 Design and implement a program that compares two text input files, line by line, for equality. On most systems,pressing the Control-C keyboard combination (hold down the Control key and press C) terminates a running program. F I G U RE 7 . The color of the stroke and fill can be set using calls to the setStroke and setFill methods, respectively. 6JavaFX mouse events M07 LEWI1724 09 GE C07.indd 366 25/09/17 11:47 AM 7 . For example, an alcoholthermometer is an analog device for measuring temperature. Typically, each number in an RGB value is in the range of 0–255. RGB stands for Red–Green–Blue. Recall that Comparable is an interface that includes only one method, compareTo, which is designed to return an integer that is less than zero, equal to zero, or greater than zero if theexecuting object is less than, equal to, or greater than the object to which it is being compared, respectively. a / b * c * d f. PP 4.11 Write a JavaFX application that uses a GridPane to display four versions of an image in a 2 * 2 grid. Put println statements in constructors of both the parent and child classes. Often the entire standard library is referredto generically as the Java API. Assume that the first parameter is greater than the second. For instructors, a comprehensive gradebook tracks correct and incorrect answers and stores the code submitted by students for review. How many times does the string "Here again" get printed? A transformation changes the visual presentation of a node. 7Part of the Node class hierarchy in the JavaFX API Rectangle Shape Node VBox HBox StackPane BorderPane GridPane FlowPane Pane Group 9 . While the majority of this book deals with the development of software, we’ll begin with an overview of computer processing to set the context. The number was 5 M05 LEWI1724 09 GE C05.indd 234 725/09/17 5:13 PM 5 . the updated index by the length of the colorList array (which is 6). Each line represents one hole, and the file contains 18 lines. When you want to use a class from a class library in a program, you could use its fully qualified name, including the package name, every time it is referenced. The methods of the aggregate objectgenerally invoke the methods of the objects from which it is composed. had failed to keep trees near the power lines trimmed appropriately. iResult l. Nested for loops are used in the TwoDArray program to load the array with values and also to print those values in a table format. The characters of the sentence are represented as a series of 12numbers, as shown in Figure 1.5. When a character is repeated, such as the uppercase 'H', the same representation number is used. K E Y C O N CEP T The constructor of the Scene class accepts four parameters: the root node to be displayed, the preferred width and height of the scene, and its background color. An object should be encapsulated,guarding its data from inappropriate access. In the Wages program, if an employee works over 40 hours in a week, the payment amount takes into account the overtime hours. The operators were told the Therac-25 had so many safety precautions that it would be “virtually impossible” to overdose a patient. The lines of a program should be divided inlogical places, and certain lines should be indented and aligned so that the program’s underlying structure is clear. By convention, uppercase letters are used when naming constants to distinguish them from regular variables, and individual words are M02 LEWI1724 09 GE C02.indd 95 23/09/17 3:45 PM 96 C HAP TE R 2 Data and Expressionsseparated using the underscore character. ----------------public String toString() { return value ""; } } and a new Num object is created and assigned to the second Num parameter. The use of String and args does not come into play in this particular program. Attributes such as the variable faceValue are called instanceKEY CON CEPT data because new memory space is reserved for that variable every The scope of a variable, which detertime an instance of the class is created. At a later point, if we want to change the pattern that the formatter object uses, we can invoke the applyPattern method. Then all three of those groups were added to the root node (also agroup) of the scene. The declaration also gives keys an initial value of 88. ----------------public void flip() { face (int) (Math.random() * 2); } ----------------// Returns true if the current face of the coin is heads. EX 1.13 List and explain the parts of the URLs for a. Design and implement aclass called Task that represents a task (such as on a to-do list) that implements the Priority interface. The variable fileScan is created as a scanner that operates on the input file named urls.inp. K E Y C O N CEP T Suppose we declare an interface called Speaker as follows: public interface Speaker { public void speak(); public void announce(Stringstr); } The interface name, Speaker, can now be used to declare an object reference variable: Speaker current; K E Y C O N CEP T An interface reference can refer to any object of any class that implements that interface. At this point the object is called garbage because it serves no useful purpose. The compiler will produce errors if any of themethods in the interface are not given a definition in the class. We’ve seen dependency relationships in many examples in which one class “uses” another. For example, in the following code, an int value is assigned to an Integer object reference variable: Integer obj1; int num1 69; obj1 num1; // automatically creates an Integer object The reverseconversion, called unboxing, also occurs automatically when needed. When that method is done, control returns to the location where the call was made and execution continues. Consider a method whose purpose is to validate that a particular integer value is in the range 0 to 99, inclusive. Note that the array is declared to hold StaffMemberreferences, but it is actually filled with objects created from several other classes, such as Executive and Employee. But you can imagine that a child class may want to refer to the constructor of the parent class, which is one of the reasons for the super reference, described next. 5 Using Loops and Conditionals with Graphics LI S T ING 6 .6 303continued Scene scene new Scene(root, 400, 400, Color.BLACK); primaryStage.setTitle("Boxes"); primaryStage.setScene(scene); primaryStage.show(); } } D I S P L A Y A for loop is used to create 50 boxes. Leave all circles unfilled except for the largest circle, which should be filled with a translucent red (30% **************************** public class TwoDArray { ----------------// Creates a 2D array of integers, fills it with increasing // integer values, then prints them out. 1000 to 5000 c. Compute the distance between the current location of the mouse pointer and the center point todetermine the current radius of the circle. S E LF - REVI EW Q UESTI O NS (see answers in Appendix L) SR 1.20 When was the Java programming language developed? A switch statement is used to handle each of the four arrow keys to which we want the program to respond. PP 3.11 Write a JavaFX application that displays a target with three redcircles and two white circles in a 500 3 500 pixels window. The safety features of the Therac-25 were dominantly software based, and the lurking problems emerged. With multiple inheritance, it can be derived from both, as shown in Figure 9.2. Multiple inheritance works well in some situations, but it comes with a price. A sentence can often havetwo or more different meanings. And, as we’ve seen previously, it has a next method that returns the next input token as a string. String toString() Returns a string representation of this object. Then, to tailor the class as needed, the programmer can add new variables and methods to the derived class or modify the inherited ones. Store the totals forpar and the players in an ArrayList. At that point, only one airline—United—agreed to use the automated system. Artist’s conception of the Mars Climate Orbiter After its nine-month journey, the orbiter arrived at Mars in September, 1999, and fired its main engines to establish an orbit. New to This Edition The biggest change to this edition of JavaSoftware Solutions is a sweeping overhaul of the Graphics Track sections of the book to fully embrace the JavaFX API. A class implements an interface by providing method implementations for each of the abstract methods defined in the interface. However, an assembly language program cannot be executed directly on a computer. A separate wirefor each connection is not a workable solution because every time a new computer is added to the network, a new communication line will have to be installed for each computer already in the network. String substring(int offset, int endIndex) Returns a new string that is a subset of this string starting at index offset and extending through endIndex-1.The pattern defined by the string "0.###", for example, indicates that at least one digit should be printed to the left of the decimal point and should be a zero if the integer portion of the value is zero. ----------------public abstract double pay(); } M10 LEWI1724 09 GE C10.indd 487 23/09/17 10:45 AM 488 C HAP TE R10 Polymorphism However, the descendants of StaffMember each provide their own specific definition for pay. M02 LEWI1724 09 GE C02.indd 85 23/09/17 3:45 PM 86 C HAP TE R 2 Data and Expressions String Concatenation A string literal cannot span multiple lines in a program. ArcType.CHORD An arc whose end points are connected by astraight line. The number of bits we use in any given situation determines the number of unique items we can represent. PP 3.16 Write a JavaFX application that displays a depiction of a solar system with a sun and three planets. A method is a group of programming statements that is given a name. public variable d. ---------------public void message() { System.out.println("Warning: Dates in calendar are closer " "than they appear."); System.out.println(); super.message(); // explicitly invokes the parent's version } } the main method, the Thought version of message is executed. If an initial value is not specified for a variable, the value is undefined. int to long b. Thisdeclaration does not create any String objects; it merely creates an array that holds references to String objects. The StaffMember class shown in Listing 10.3 is abstract. The only changes made to the state of the object should be accomplished by that object’s methods. In that case, the getCharacter method of the event can be used to get thecharacter. executed on a particular object. num1 : num2)); The conditional operator is occasionally helpful to evaluate a short condition and return a result. Constants, which are declared using the final modifier, are often declared using the static modifier. In fact, all classes in Figure 9.7 are nodes. Finally, the String object variables mutation3 andmutation4 are initialized by the calls to mutation2.replace and mutation3.substring, respectively: mutation3 "CHANGX IS INXVITABLX, XXCXPT FROM VXNDING MACHINXS" mutation4 "NGX IS INXVITABLX, XXCXPT F" S E LF - REVI EW Q UESTI O NS (see answers in Appendix L) SR 3.6 Assume s1, s2, and s3 are String variables initialized to"Amanda", "Bobby", and "Chris", respectively. SR 9.12 Which is the only Java class that does not have a parent class? 9 Introduction to JavaFX 157 Autoboxing Autoboxing is the automatic conversion between a primitive value and a corresponding wrapper object. Two other terms are used to describe memory devices: random access memory (RAM)and read-only memory (ROM). Because both selection sort and insertion sort have the same general efficiency, the choice between them is almost arbitrary. Listing 3.9 shows a program that displays a snowman scene. Moreover, this sentence could describe the preferences of an unusual insect known as a “time fly,” which might be found near anarchery range. The two plus signs that make up the operator cannot be separated by white space. LI S T IN G 2 .1 ******************** // Countdown.java Author: Lewis/Loftus // // Demonstrates the difference between print and println. PP 8.12 Define a class called Star that extends Polygon and isshaped like a five-pointed star. The complete machine language code for this particular expression is over 400 bits long. That person might explain those directions in any one of several languages, such as English, Russian, or Italian. When dealing with large amounts of data that are dimensions is rare in an object-oriented managed at multiple levels,additional information and the methods system. A USB flash drive consists of a small printed circuit board carrying the circuit elements and a USB connector, insulated electrically and protected inside a plastic, metal, or rubberized case, which can be carried in a pocket or on a key chain, for example. Each array is created using an initialization list.Various software tools can be used to help with all parts of the development process as well. int num 1, max 20; while (num 6 max) { if (num%2 0) System.out.println(num); num ; } EX 5.9 What is wrong with the following code fragment? Common characteristics are defined in high-level classes, and specific differences are defined inderived classes. Other computer memory devices are made up of tiny electrical circuits. In the Graphics Track sections of this chapter, we discuss the characteristics of a well-designed graphical user interface (GUI) and explore mouse and keyboard events. The base value of a number system dictates how many digits we have to work with andindicates the place value of each digit in a number. (value1 5) 7 value2 c. The only restriction is that the array eleme

Java software solutions 8th edition answers test pdf free . VideoNote Comparison of Java IDEs. Included in the download of the Java Standard Edition is the Java Software Development Kit (SDK), which is sometimes referred to simply as the Java Development Kit (JDK). Such an approach seems ridiculous in today's world of distributed processing .