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
Hire a Tutor
AI Tutor
New
Search
Search
Sign In
Register
study help
computer science
java concepts late objects
Questions and Answers of
Java Concepts Late Objects
A laboratory container is shaped like the frustum of a cone:Write methods to compute the volume and surface area, using these equations: R. R1
The effective focal length f of a lens of thickness d that has surfaces with radii of curvature R1 and R2 is given bywhere n is the refractive index of the lens medium. Write a method that computes f
In a movie theater, the angle θ at which a viewer sees the picture on the screen depends on the distance x of the viewer from the screen. For a movie theater with the dimensions shown in the picture
You are designing an element for a control panel that displays a temperature value between 0 and 100. The element’s color should vary continuously from blue (when the temperature is 0) to red (when
Having a secure password is a very important practice, when much of our information is stored online. Write a program that validates a new password, following these rules:• The password must be at
In a social networking service, a user has friends, the friends have other friends, and so on. We are interested in knowing how many people can be reached from a person by following a given number of
Give pseudocode for a recursive method for printing all substrings of a given string. For example, the substrings of the string "rum" are "rum" itself, "ru", "um", "r", "u", "m", and the empty
Write a program that prints the decimal expansion of a fraction, marking the repeated part with an R. For example, 5/2 is 2.5R0, 1/12 is 0.08R3, and 1/7 is 0.R142857.
Write a method that computes the Scrabble score of a word. Look up the letter values on the Internet. For example, with English letter values, the word JAVA is worth 8 + 1 + 4 + 1 = 14 points.
Suppose an ancient civilization had constructed circular pyramids. Write pseudocode for a program that determines the surface area from measurements that you can determine from the ground.
Write a program that reads two fractions, adds them, and prints the result so that the numerator and denominator have no common factor. For example, when adding 3/4 and 5/6, the result is 19/12. Use
Write a program that prints instructions to get coffee, asking the user for input whenever a decision needs to be made. Decompose each task into a method, for example:public static void
Write a program that, given a month and year, prints a calendar, such asTo find out the weekday of the first day of the month, call int weekday = java.time.LocalDate.of(year, month,
Write a method that computes the balance of a bank account with a given initial balance and interest rate, after a given number of years. Assume interest is compounded yearly.
Consider the following method that is intended to swap the values of two integers:public static void falseSwap(int a, int b){int temp = a;a = b;b = temp;}public static void main(String[] args){int x
Write a program that reads words and arranges them in a paragraph so that all lines other than the last one are exactly forty characters long. Add spaces between words to make the last word extend to
Use recursion to determine the number of digits in an integer n. If n is < 10, it has one digit. Otherwise, it has one more digit than n / 10.
Consider the following method:public static int f(int a){if (a < 0) { return -1; }int n = a;while (n > 0){if (n % 2 == 0) // n is even{n = n / 2;}else if (n == 1) { return 1; }else { n = 3 * n
Write a program that prompts the user for a regular English verb (such as play), the first, second, or third person, singular or plural, and present, past, or future tense. Provide these values to a
Use recursion to implement a method public static boolean find(String str, String match) that tests whether match is contained in str: boolean b = find("Mississippi", "sip"); // Sets b to true Hint:
Perform a walkthrough of the int Name method with the following arguments:a. 5b. 12c. 21d. 301e. 324f. 0g. -2
Write a program that reads two strings containing section numbers such as "1.13.2" and "1.2.4.1" and determines which one comes first. Provide appropriate helper methods.
Write a recursive methodpublic static boolean isPalindrome(String str)that returns true if str is a palindrome, that is, a word that is the same when reversed. Examples of palindrome are “deed”,
Use the process of stepwise refinement to describe the process of making scrambled eggs. Discuss what you do if you do not find eggs in the refrigerator.
Write a method String getTimeName(int hours, int minutes) that returns the English name for a point in time, such as "ten minutes past two", "half past three", "a quarter to four", or "five o'clock".
Write a method public static int countVowels(String str) that returns a count of all vowels in the string str. Vowels are the letters a, e, i, o, and u, and their uppercase variants. Use a helper
What is the difference between an argument and a return value? How many arguments can a method call have? How many return values?
In which sequence are the lines of the Cubes.java program in Section 5.2 executed, starting with the first line of main?section 5.2/Cubes.java1 /**2 This program computes the volumes
In Section 4.7.5, the code for finding the largest and smallest input initializes the largest and smallest variables with an input value. Why can’t you initialize them with zero?
Draw a flowchart for a program that carries out unit conversions as described in Section 4.6.
Following Section 4.9, develop a program that reads text and displays the average number of words in each sentence. Assume words are separated by spaces, and a sentence ends when a word ends in a
Complete the program in How To 4.1 on page 171. Your program should read twelve temperature values and print the month with the highest temperature.
What is encapsulation? Why is it useful?
The following code tries to close the writer without using a try-with-resources statement:PrintWriter out = new PrintWriter(filename);try{Write output.out.close();}catch (IOException
What values are returned by the calls reg1.getCount(), reg1.getTotal(), reg2.getCount(),and reg2.getTotal() after these statements?CashRegister reg1 = new
A microwave control panel has four buttons: one for increasing the time by 30 seconds, one for switching between power levels 1 and 2, a reset button, and a start button. Implement a class that
We want to add a button to the tally counter in Section 8.2 that allows an operator to undo an accidental button click. Provide a method public void undo() that simulates such a button. As an added
Suppose the program in Section 7.5 reads a file containing the following values:1234What is the outcome? How could the program be improved to give a more accurate error report?
Which exceptions can the next and nextInt methods of the Scanner class throw? Are they checked exceptions or unchecked exceptions?
What happens when an exception is thrown, a try-with-resources statement calls close, and that call throws an exception of a different kind than the original one? Which one is caught by a surrounding
What is the purpose of the try-with-resources statement? Give an example of how it can be used.
Suppose a file contains bond energies and bond lengths for covalent bonds in the following format:Write a program that accepts data from one column and returns the corresponding data from the other
Modify the DataAnalyzer program so that you do not call hasNextInt or hasNextDouble. Simply have nextInt and nextDouble throw a NoSuchElementException and catch it in the main method.
Is the type of the exception object always the same as the type declared in the catch clause that catches it? If not, why not?
The figure below shows a plot of the capacitor voltage from the circuit shown in Exercise P7.11. The capacitor voltage increases from 0 volts to B volts. The “rise time” is defined as the time
Write a program that asks the user to input a set of floating-point values. When the user enters a value that is not a number, give the user a second chance to enter the value. After two chances,
What can your program do with the exception object that a catch clause receives?
After the switch in the figure below closes, the voltage (in volts) across the capacitor is represented by the equationSuppose the parameters of the electric circuit are B = 12 volts, R = 500 Ω, and
Write a program that reads each line in a file, reverses its lines, and writes them to another file. For example, if the file input.txt contains the lines Mary had a little lamb Its fleece was
What happens if an exception does not have a matching catch clause?
A store owner keeps a record of daily cash transactions in a text file. Each line contains three items: The invoice number, the cash amount, and the letter P if the amount was paid or R if it was
Write a program that reads a text file, as described in Exercise P7.8, and writes a separate file for each service category. Each service category file should contain the entries for that category.
Write a program that checks the spelling of all words in a file. It should read each word of a file and check whether it is contained in a word list. A word list is available on most Linux systems in
Write a program that replaces each line of a file with its reverse. For example, if you runjava Reverse HelloPrinter.javathen the contents of HelloPrinter.java are changed toretnirPolleH ssalc
When your program executes a throw statement, which statement is executed next?
Why don’t you need to declare that your method might throw an IndexOutOfBoundsException?
A hotel salesperson enters sales in a text file. Each line contains the following, separated by semicolons: The name of the client, the service sold (such as Dinner, Conference, Lodging, and so on),
Write a program Find that searches all files specified on the command line and prints out all lines containing a specified word. For example, if you call java Find ring report.txt address.txt
Add an alarm feature to the Clock class of Exercise P9.1. When setAlarm(hours, minutes) is called, the clock stores the alarm. When you call getTime, and the alarm time has been reached or exceeded,
Which methods does the ChoiceQuestion class inherit from its superclass? Which methods does it override? Which methods does it add?
Modify the checkAnswer method of the Question class so that it does not take into account different spaces or upper/lowercase characters. For example, the response "JAMES gosling" should match an
The System.out.printf method has predefined formats for printing integers, floatingpoint numbers, and other data types. But it is also extensible. If you use the S format, you can print any class
Which methods does the SavingsAccount class in How To 9.1 inherit from its superclass? Which methods does it override? Which methods does it add?
Add a class AnyCorrectChoiceQuestion to the question hierarchy of Section 9.1 that allows multiple correct choices. The respondent should provide any one of the correct choices. The answer string
List the instance variables of a CheckingAccount object from How To 9.1.
Add a class MultiChoiceQuestion to the question hierarchy of Section 9.1 that allows multiple correct choices. The respondent should provide all correct choices, separated by spaces. Provide
Change the CheckingAccount class in How To 9.1 so that a $1 fee is levied for deposits or withdrawals in excess of three free monthly transactions. Place the code for computing the fee into a
Suppose the class Sub extends the class Sandwich. Which of the following assignments are legal?Sandwich x = new Sandwich();Sub y = new Sub();a. x = y;b. y = x;c. y = new Sandwich();d. x = new Sub();
Add a method addText to the Question superclass and provide a different implementation of ChoiceQuestion that calls addText rather than storing an array list of choices.
Draw an inheritance diagram that shows the inheritance relationships between these classes.• Person• Employee• Student• Instructor• Classroom• Object
Provide toString methods for the Question and ChoiceQuestion classes.
Improve the appointment book program of Exercise P9.6. Give the user the option to add new appointments. The user must specify the type of the appointment, the description, and the date.Data from
In an object-oriented traffic simulation system, we have the classes listed below. Draw an inheritance diagram that shows the relationships between these classes.• Vehicle• Car• Truck•
Implement a subclass of BankAccount from How To 9.1 called BasicAccount whose withdraw method will not withdraw more money than is currently in the account.
Improve the appointment book program of Exercises P9.6 and P9.7 by letting the user save the appointment data to a file and reload the data from a file. The saving part is straightforward: Make a
What inheritance relationships would you establish among the following classes?• Student• Professor• TeachingAssistant• Employee• Secretary• DepartmentChair• Janitor•
Implement a subclass of BankAccount from How To 9.1 called BasicAccount whose withdraw method charges a penalty of $30 for each withdrawal that results in an overdraft.
In this problem, you will model a circuit consisting of an arbitrary configuration of resistors. Provide a superclass Circuit with a instance method getResistance. Provide a subclass Resistor
How does a cast such as (BankAccount) x differ from a cast of number values such as (int) x?
Reimplement the CheckingAccount class from How To 9.1 so that the first overdraft in any given month incurs a $20 penalty, and any further overdrafts in the same month result in a $30 penalty.
Part (a) of the figure below shows a symbolic representation of an electric circuit called an amplifier. The input to the amplifier is the voltage vi and the output is the voltage vo. The output of
Add a method hasNext to the Sequence interface of Worked Example 9.2 that returns false if the sequence has no more values. Implement a class MySequence producing a sequence of real data of your
Suppose an int value a is two billion and b is -a. What is the result of a – b? Of b – a? What is the result of Integer.compare(a, b)? Of Integer.compare(b – a)?
A labeled point has x- and y-coordinates and a string label. Provide a class LabeledPoint with a constructor LabeledPoint(int x, int y, String label) and a toString method that displays x, y, and the
Provide a class FirstDigitDistribution that works just like the LastDigitDistribution class of Worked Example 9.2, except that it counts the distribution of the first digit of each value. (It is a
Suppose a double value a is 0.6 and b is 0.3. What is the result of (int)(a - b)? Of (int)(b - a)? What is the result of Double.compare(a, b)? Of Double.compare(b - a)?
Reimplement the LabeledPoint class of Exercise E9.15 by storing the location in a java.awt.Point object. Your toString method should invoke the toString method of the Point class.Data from Exercise
Declare an interface Filter as follows:public interface Filter { boolean accept(Object x); }Add a Filter parameter to the average method of Section 9.6. Only objects that the filter accepts should be
Modify the SodaCan class of Exercise P8.5 to implement the Measurable interface. The measure of a soda can should be its surface area. Write a program that computes the average surface area of an
Solve Exercise P9.16, using a lambda expression for the filter.Data from Exercise P9.16,Declare an interface Filter as follows:public interface Filter { boolean accept(Object x); }Add a Filter
A person has a name and a height in centimeters. Use the average method in Section 9.6 to process a collection of Person objects.
In Exercise P9.16, add a method to the Filter interface that counts how many objects are accepted by the filter:static int count(Object[] values, Filter condition)Data from Exercise P9.16,Declare an
Write a methodpublic static Measurable maximum(Measurable[] objects)that returns the object with the largest measure. Use that method to determine the country with the largest area from an array of
In Exercise P9.16, add a method to the Filter interface that retains all objects accepted by the filter and removes the others: static void retainAll(Object[] values, Filter condition)Data from
Add static methods largest and smallest to the Measurable interface. The methods should return the object with the largest or smallest measure from an array of Measurable objects.
In Exercise P9.16, add a method default boolean reject(Object x) to the Filter interface that returns true for all objects that this filter doesn’t accept.Data from Exercise P9.16,Declare an
In the Sequence interface of Worked Example 9.2, add static methods that yield Sequence instances:static Sequence multiplesOf(int n)static Sequence powersOf(int n)For example, Sequence.powersOf(2)
In Exercise P9.16, add a method default Filter invert() to the Filter interface that yields a filter accepting exactly the objects that this filter rejects.Data from Exercise P9.16,Declare an
In Worked Example 9.2, add a default method default int[] values(int n) that yields an array of the first n values of the sequence.Data from Example 9.2,n this Worked Example, we investigate
Consider an interfacepublic interface NumberFormatter{String format(int n);}Provide four classes that implement this interface. A DefaultFormatter formats an integer in the usual way. A
Showing 200 - 300
of 835
1
2
3
4
5
6
7
8
9