All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
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
Ask a Question
Search
Search
Sign In
Register
study help
computer science
introduction to programming with java a problem solving approach
Questions and Answers of
Introduction To Programming With Java A Problem Solving Approach
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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()
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
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.
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
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
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
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 /****************
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
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
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
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
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
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
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
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
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
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[]
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
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
Multiple catch Blocks:Suppose the code in a try block might throw any of the following exceptions:IOExceptionNoSuchElementExceptionExceptionInputMismatchExceptionRuntimeExceptionIdentify an
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
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
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
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
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
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
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