New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
introduction to programming with java a problem solving approach
Introduction To Programming With Java A Problem Solving Approach 3rd International Edition John Dean - Solutions
EllipseDriver program. Compile and execute the following program. Provide the program’s output as part of your answer. Using Oracle’s or OpenJFX’s Java documentation as a resource, figure out what the program does and how it works. Insert comments at indicated places in the program’s code
Suppose you have two classes related by inheritance that both contain a one-parameter method named printThis. Here’s the subclass’s version of printThis:
What does it mean when you use the final modifier for a class?
What does it mean when you use the final modifier for a method?
Fill in the blanks:If a Y class “is a” special form of an X class, there is a(n) ________ association, and the right side of Y’s class heading will contain the words _______. If an object X “has an” object Y and also “has an” object Z, there is a(n) _______ association, and X’s
Identification of type of association:Given the following list of word pairs, for each word pair, identify the association between the two words. That is, identify whether the two words are related by composition or inheritance. To get you started, we’ve provided the answers to the first two word
Shuffling:Suppose you are developing a card game program like that suggested earlier in the chapter, but you want to use an ArrayList instead of an array. The following UML class diagram shows your plan:Assume you have implemented the Card class and the GroupOfCards class. (The next exercise will
This is a continuation of the card game program described in the prior exercise. Implement the Card and GroupOfCards classes.Data From Previous Exercise:
GridWorld’s firstProject file contains the BugRunner driver:BugRunner starts by creating an instance of ActorWorld named world. ActorWorld’s constructor immediately creates a 10 × 10 BoundedGrid. Next, BugRunner asks the ActorWorld object to add a new Bug at a random location, and it then adds
Using GridWorld documentation, provide a UML class diagram for the Actor class and its descendants, Bug, Rock, and Flower. This should be similar to this chapter’s UML class diagram for the Person class and its descendants. Include UML specifications of all class and instance variables and
This chapter’s Exercise 15 presents code containing the statement ActorWorld world = new ActorWorld();After that, we said, “ActorWorld’s constructor immediately creates a 10 × 10 BoundedGrid.” But if you look at GridWorld’s source code for the ActorWorld class, you’ll see that the
Find and describe the explicit calls to superclass members in the ActorWorld, BoundedGrid, Bug, Rock, WorldFrame, and GridPanel classes, mentioned in Exercise 15, above. In each class that makes such a call, identify the class, the method or constructor that includes the call, the constructor or
Create a RandomBug class that extends the Bug class in the GridWorld program. In this extended class, override the move method inherited from Bug. Do this by copying the code from Bug’s move method and then replacing the code fragment that creates flowers and deposits them in the bug’s wake
If you want a class you define to inherit methods from the Object class, you must append the suffix extends Object to your class’s heading. (T / F)
When used to compare reference variables, the == operator works the same as the Object class’s equals method. (T / F)
What does the equals method defined in the String class compare?
What is returned by the Object class’s toString method?
What’s wrong with replacing the println statement in Figure 14.2’s main method with these two statements?String description = car.toString();System.out.println(description);Figure 14.2 /*************** ********* * Car2.java *Dean & Dean * * This instantiates a car and displays its properties.
The return type of an overriding method must be the same as the return type of the overridden method. (T / F)
In Java, polymorphic method calls are bound to method definitions at compile time (not runtime). (T / F)
Assume one reference variable’s class is descended from another reference variable’s class. To be able to assign one reference variable to the other one (without using a cast operator), the left-side variable’s class must be a(n) _______ of the right-side reference variable’s class.
A given array may contain different types of elements. (T / F)
What are the syntax features of an abstract method?
Any class that contains an abstract method must be declared to be an abstract class. (T / F)
You cannot instantiate an abstract class. (T / F)
You can use an interface to provide direct access to a common set of constants from many different classes. (T / F)
You can declare reference variables to have an interface type and use them just as you would use reference variables declared to be the type of a class in an inheritance hierarchy. (T / F)
Describe the access provided by the protected modifier.
It’s illegal to use private for any method that overrides an abstract method. (T / F)
Given a Car class with the following instance variables:private String make;private String model;private int year;private String color;Write an equals method for customers who don’t care about color.
Assume that this chapter’s Car class is instantiated with a statement like this:Car car = new Car("Mazda", 2018, "green");Enhance this Car class by providing an additional method that responds to this subsequent print statement:System.out.println(car);With output like this:Green 2018 Mazda
Assume you have a programmer-defined class named Person. Assume this class includes a name instance variable, initialized by the constructor’s name parameter. Suppose a driver fills a people array with Person objects. Then the driver goes back through the array and uses
What does the following program output? For each bird’s output, describe how the output is generated (be specific). public class Bird {} public class Turkey extends Bird { public String toString() { return "gobble, gobble"; } } // end class Turkey public class BirdDriver { public static void
Suppose we add the following method to the previous exercise’s Bird class:What does the enhanced program output? Explain. public String toString() ( return "tweet, tweet";
Suppose you have a reference variable named thing, you’re not sure what type of object it points to, and you want your program print out its type. The Object class (and therefore any class!) has another method, getClass, that returns a special object of type Class that contains information about
Given superclass Pet and subclass Cat, identify and explain all compilation errors in the following code fragment. Pet pet: Cat mrWhiskers, fluffy new Pet()); mrWhiskers = pet fluffy; = new Cat ();
Assume you have a superclass Pet and subclasses Cat and Dog. In the following code fragment, the second and third lines generate compilation errors. Provide corrected versions of those two lines. Preserve the spirit of the original code. For example, the bottom line should still assign the second
If a superclass is abstract, every subclass must override all of the superclass’s methods (T / F).
Given the Pet2Driver class below, write an abstract Pet2 class that contains just one item—an abstract declaration for a speak method. Also write Dog2 and Cat2 classes that extend Pet2, so that when you execute Pet2Driver and input ‘c’ or ‘d’, the program prints “Meow! Meow!” or
Write an AssetAging interface that includes abstract accessor methods that retrieve the following instance variables’ values: originalCost (a double) acquisitonDate (a String) depreciation Rate (a double)
In Exercise 10, above, indicate all changes you would make to Pet2, Cat2, and Dog2 so that Pet2 is an interface rather than an abstract class. It should not be necessary to make any changes to Exercise 10’s Pet2Driver class.Exercise 10Given the Pet2Driver class below, write an abstract Pet2 class
Expand the cryptic code in the getFICA method of the Employee3 class in Figure 14.20 into “if else” statements so that the algorithm is easier to understand.Figure 14.20 /**************** *Employee3.java * Dean & Dean * * This abstract class describes employees, and it includes * Social
This exercise refers to the different versions of the GridWorld program that have been looked at previously. Identify a GridWorld class that stores a two-dimensional array that can hold objects of any type. Provide the class name and the declaration for the array variable. List three types of
This exercise refers to the different versions of the GridWorld program that have been looked at previously. Identify a GridWorld interface that is implemented by a class. Provide the method headings for each method that the interface specifies.
Describe GridWorld’s Location class. What Java API interface does it implement? Identify its instance variables, summarize its static constants, and list its method headers.
If your program contains an API method call, you should put it inside a try block. To be fully compliant with proper coding practice, you should apply this rule for all your API method calls. (T / F)
A try block and its associated catch block(s) must be contiguous. (T / F)
Usually, you should try to aggregate related dangerous statements in the same try block to minimize clutter. (T / F)
Where should you put safe statements that use the results of dangerous operations?
If an exception is thrown, the JVM jumps to a matching catch block, and after executing the catch block, it returns to the try block at the point where the exception was thrown. (T / F)
In checking for compile-time errors, the compiler takes into account that all statements inside a try block might get skipped. (T / F)
If an exception is derived from the RuntimeException class it is a(n) ________ exception.
Checked exceptions are exceptions that are in or derived from the ________ class, but not in or derived from the _______ class.
In the following list, indicate whether each option is a viable option for an unchecked exception that you know your program might throw:a) Ignore it.b) Rewrite the code so that the exception never occurs.c) Put it in a try block, and catch it in a following catch block.
When a statement might throw a checked exception, you can keep the compiler from complaining if you put that statement in a try block and follow the try block with a catch block whose parameter type is the same as the exception type. (T / F)
You can determine whether a particular statement contains a checked exception and the type of that exception by attempting to compile with no try-catch mechanism. (T / F)
Is it OK to include code that can throw both unchecked and checked exceptions in the same try block?
What type of exception matches all checked exceptions and all unchecked exceptions except those derived from the Error class?
What does the getMessage method return?
The compiler automatically checks for out-of-order catch blocks. (T / F)
Write the header for a catch block that catches either an InvalidPathException or a NoSuchFileException.
What are the two types of information displayed by the JVM when it encounters a runtime error that terminates execution?
Suppose you want to postpone catching of a NumberFormatException. What should you append to the heading of a method to alert the compiler and a potential user that something in the method might throw that type of exception?
Given a non-void method that contains no try and catch blocks. If the method throws an exception, we know that the JVM transfers the thrown exception back to the calling method. But does the JVM return a value (with a return statement) to the calling module?
The JVM will close your file automatically if you instantiate its file handler in a try-with-resources header, like this (T / F): public void writeToFile(String filename, String text) throws IOException { PrintWriter fileOut; try (fileOut { = new Print Writer(new File(filename ) ) )
Given the program below, what is the output if the user enters 3 in response to the prompt? import java.util. Scanner; public class Athletes { public static void main(String[] args) { Scanner stdIn String[] players {"Serena Williams", "Alex Morgan", " Allyson Felix", "Lindsey Vonn", "Katie
For the program in Exercise 1, what is the output if the user enters “first” in response to the prompt?Exercise 1Given the program below, what is the output if the user enters 3 in response to the prompt? import java.util.Scanner; public class Athletes { public static void main(String[] args) {
Explain what the following program does for different possible user inputs. import java.util.Scanner; import java.util. InputMismatch Exception; public class Guess { public static void main(String[] args) { Scanner stdIn = new Scanner (System.in); int guess, num (int) (Math.random() * 10); try { =
Suppose you have a program with a method call you’re unfamiliar with. Describe the best way to determine if that method might throw an unchecked exception. And if you find that the method call might call an unchecked exception, what are the strategies for dealing with that situation?
Early in the development of a new program that is likely to throw exceptions of many types, what can you do to enable early testing to help identify types of exceptions that might be thrown and why they are thrown? Specifically, provide a catch block that catches any thrown exception, prints a
Multiple catch Blocks:Suppose the code in a try block might throw any of the following exceptions:IOExceptionNoSuchElementExceptionExceptionInputMismatchExceptionRuntimeExceptionIdentify an acceptable sequence for the given exceptions if they were in a sequence of catch block headings.
Handling an ArithmeticException.The following program calls getQuotient, which divides its two passed-in values and returns the quotient as a floating-point number.The program works well for the normal cases, but when the user enters 0 for the divisor, the program generates this error:Exception in
Correcting Problems:Fix the problems in the NumberList program without making any changes to the NumberListDriver class.a) Avoid the possibility of an ArrayIndexOutOfBoundsException by adding to the while condition, sizeb) If the entry is not a “q” and if it is not a legal integer, catch the
Postponed catch elaboration:Modify this chapter’s StudentList2 program so that the driver’s exception handler displays more than just “Invalid entry.” Instead, have it display the error class and message and the acceptable range of index values. Most of the change will be in the driver
Simple try-with-resources:Implement a program named WriteToFileEx that writes and displays what this chapter’s WriteToFile program writes and displays. But do not use a separate write method. Put the try-with-resources block together with the catch block in the main method.
Assuming the object that manages output will be called writer, write a statement that opens a text file called dogs.html for output by println statements.
To be file-writable and file-readable, an object must be an instance of a class that implements .
Write a statement that opens a file for input of objects and assigns a reference to the connection to objectIn. Assume the file is in the current directory, with the name automobiles.data.
Assuming you have made the declaration, TestObject testObject; you can assign the value returned by ObjectInputStream’s readObject method directly to testObject. (T / F)
Given the filename “TradingPartners,” write a try-with-resources header that opens a file for writing text with a PrintWriter called fileOut and stores that text using the UTF-16 character set.
Given the filename “Suppliers,” write a try-with-resources header that(1) Opens a text file for reading with a Scanner named fileIn, and(2) Interprets the file’s data using the UTF-16 character set.
What Java API package contains Enum StandardOpenOption?
In a Java interface, what does the ... notation (an ellipsis) in the parameter specification OpenOption... options say about the arguments you should supply to the constructor or method?
When a text file is large, for good performance, what type of file handler should you use?
What does a flip() method call do?
What is the difference between the ByteBuffer methods, get() and get(int index)?
ByteBuffer’s putDouble(double value) method inserts the 8-byte value into the buffer starting at the current position and increments position to just after that inserted value. (T / F)
Given int[] integers and ByteBuffer buffer, write a statement that copies integers[3] into buffer, starting at buffer’s current position.
Assuming import java.nio.file.*; and an existing file called “CanadianFriends,” write a Java statement that declares and opens a read- only FileChannel to that file.
Given a FileChannel called channel and a ByteBuffer called buffer whose capacity and limit equal channel.size(), write a statement that maps the entire file into the buffer for read-only access.
Write code for a try-with-resources header that creates a stream containing information about what’s in the parent of the current directory.
What is a “glob”?
The most appropriate type to use for financial accounting is ——————.
For each statement, specify true or false:a) 1234.5 is a floating-point number. (T / F)b) 1234 is a floating-point number. (T / F)c) 1234. is a floating-point number. (T / F)
If you try to assign an int value into a double variable, the computer automatically makes the conversion without complaining, but if you try to assign a double value into an int variable, the compiler generates an error. Why?
For each statement, specify true or false:a) 0.1234 is a float. (T / F)b) 0.1234f is a float. (T / F)c) 0.1234 is a double. (T / F)d) 1234.0 is a double. (T / F)
What modifier specifies that a variable’s value is fixed/constant?
What is the remainder operator?
Write the following mathematical expressions as legal Java expressions: a) 3x - 1 b) 1 1 2+: xy
Assume this:Evaluate the following expressions:a) (7 - n) % 2 * 7.5 + 9b) (4 + n / m ) / 6.0 * x int m= 3, n = 2; double x = 7.5;
Showing 300 - 400
of 717
1
2
3
4
5
6
7
8
Step by Step Answers