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
java programming
Questions and Answers of
Java Programming
Write a method:that displays the prompt string, reads an integer, and tests whether it is between the minimum and maxi mum. If not, print an error message and repeat reading the input.Add the method
Consider the following algorithm for computing xn for an integer n. If n < 0, xnis 1/x–n. If n is positive and even, then xn = (xn/2 )2. If n is positive and odd, then xn = xn–1 × x. Implement a
Improve the Die class of Chapter 6. Turn the generator variable into a static variable so that all dice share a single random number generator.••
Place a BankAccount class in a package whose name is derived from your e-mail address, as described in Section 8.6. Keep the BankAccountTester class in the default package.••
Provide a JUnit test class StudentTest with three test methods, each of which tests a dif ferent method of the Student class in How To 7.1.Data from How to 7.1
Provide JUnit test class TaxReturnTest with three test methods that test different tax situations for the TaxReturn class in Chapter 5.
Write methods:that show the letters H, E, L, O in the graphics window, where the point p is the top-left corner of the letter. Then call the methods to draw the words “HELLO”and “HOLE” on the
Repeat Exercise • Graphics E8.23 by designing classes LetterH, LetterE, LetterL, and LetterO, each with a constructor that takes a Point2D.Double parameter (the top-left corner) and a method
Add a method ArrayList getStatement() to the BankAccount class that returns a list of all deposits and withdrawals as positive or negative values. Also add a method void clearStatement() that resets
•••Declare a class ComboLock that works like the combination lock in a gym locker, as shown here. The lock is constructed with a combina tion—three numbers between 0 and 39. The reset method
Improve the picture gallery program in Section 8.5 to fill the space more efficiently. Instead of lining up all pictures along the top edge, find the first available space where you can insert a
In a tile matching game, tiles are arranged on a grid with rows and columns. Two tiles are turned over at a time, and if they match, the player earns a point. If they are adjacent, the player earns
Simulate a car sharing system in which car commuters pick up and drop off passengers at designated stations. Assume that there are 30 such stations, one at every mile along a route. At each station,
In Exercise •• P8.4 , drivers picked up passengers at random. Try improving that scheme. Are drivers better off picking passengers that want to go as far as possible along their route? Is it
Tabular data are often saved in the CSV (comma-separated values) format. Each table row is stored in a line, and column entries are separated by commas. However, if an entry contains a comma or
For faster sorting of letters, the U.S. Postal Service encourages companies that send large volumes of mail to use a bar code denoting the ZIP code (see Figure 8).The encoding scheme for a five-digit
Implement a program that prints paychecks for a group of student assistants. Deduct federal and Social Security taxes. (You may want to use the tax computation used in Chapter 5. Find out about
What are all the superclasses of the JFrame class? Consult the Java API documentation or Appendix D.
In Worked Example 9.1,a. What are the subclasses of Employee?b. What are the superclasses of Manager?c. What are the super- and subclasses of SalariedEmployee?d. Which classes override the weeklyPay
Which of these conditions returns true? Check the Java documentation for the inheritance patterns. Recall that System.out is an object of the PrintStream class. a. System.out instanceof PrintStream
Suppose the class Employee is declared as follows:Declare a class Manager that inherits from the class Employee and adds an instance variable bonus for stor ing a salary bonus. Implement the
Add a class NumericQuestion to the question hierarchy of Section 9.1. If the response and the expected answer differ by no more than 0.01, accept the response as correct.
Add a class FillInQuestion to the question hierarchy of Section 9.1. Such a question is constructed with a string that contains the answer, surrounded by _ _, for exam ple,"The inventor of Java was
Implement a class ChessPiece with method setPosition(String coordinates). The coordinate string identifies the row and column in chess notation, such as "d8" for the initial position of the black
What does this code fragment print? Why is this an example of polymorphism? Measurable [] data = { new BankAccount (10000), new Country("Belgium", 30510) }; System.out.println (average (data));
The classes Rectangle2D.Double, Ellipse2D.Double, and Line2D.Double implement the Shape interface. The Graphics2D class depends on the Shape interface but not on the rectangle, ellipse, and line
Suppose r contains a reference to a new Rectangle(5, 10, 20, 30). Which of the following assignments is legal? (Look inside the API documentation to check which interfaces the Rectangle class
Classes such as Rectangle2D.Double, Ellipse2D.Double, and Line2D.Double implement the Shape interface. The Shape interface has a method: Rectangle getBounds () that returns a rectangle completely
Suppose you need to process an array of employees to find the average salary. Discuss what you need to do to use the Data. average method in Section 10.1.3 (which processes Measurable objects). What
What happens if you try to use an array of String objects with the Data average method in Section 10.1.3?Data from section 10.1.3
How can you use the Data average method in Section 10.4 if you want to compute the average length of the strings?Data from section 10.4
What happens if you pass an array of strings and an AreaMeasurer to the Data.average method of Section 10.4?Data from section 10.4
Consider this top-level and inner class. Which variables can the f method access? public class T { private int t; public void m(final int x, int y) { int a; final int b; class C implements I public
What happens when an inner class tries to access a local variable that assumes more than one value? Try it out and explain your findings.
How would you reorganize the InvestmentViewer1 program of Section 10.7.2 if you needed to make AddInterestListener into a top-level class (that is, not an inner class)?
Can a class be an event source for multiple event types? If so, give an example.
Implement a class Quiz that implements the Measurable interface of Exercise •• E10.1. A quiz has a score and a letter grade (such as B+). Modify the Data class from Section 10.1 to process an
A person has a name and a height in centimeters. Use the Data class of Exercise E10.2 to process an array of Person objects. Display the aver age height and the name of the tallest person.Data
In Worked Example 10.1, add a default method:that yields an array of the first n values of the sequence.Data from worked example 10.1. default int[] values(int n)
Add a method to the Data class that returns the object with the largest measure, as measured by the supplied measurer: public static Object largest (Object[] objects, Measurer m)
Using a different Measurer object, process a set of Rectangle objects to find the rectangle with the largest perimeter.
Modify the Coin class from Section 8.2.1 to have it implement the Comparable interface.
Repeat Exercise • E10.8 , making the Measurer into an inner class inside the main method.Data from Exercise E10.8 Using a different Measurer object, process a set of Rectangle objects to find the
Repeat Exercise • E10.8 , making the Measurer an inner class outside the main method. Data from Exercise E10.8Using a different Measurer object, process a set of Rectangle objects to find the
Implement a class Bag that stores items represented as strings. Items can be repeated.Supply methods for adding an item, and for counting how many times an item has been added:Your Bag class should
Implement a class Grid that stores measurements in a rectangular grid. The grid has a given number of rows and columns, and a description string can be added for any grid location. Supply the
Reimplement Exercise •• E10.13 where the grid is unbounded. The constructor has no arguments, and the row and column parameter variables of the add and getDescription methods can be arbitrary
Write a method randomShape that randomly generates objects implementing the Shape interface in the Java library API: some mixture of rectangles, ellipses, and lines, with random positions. Call it
Enhance the ButtonViewer program in Section 10.7.1 so that it prints a message “Iwasclicked n times!” whenever the button is clicked. The value n should be incremented with each click.
Enhance the ButtonViewer program so that it has two buttons labeled A and B, each of which prints a message “Button x was clicked!”, where x is A or B.
Implement a ButtonViewer program as in Exercise •• Graphics E10.18 , using only a single listener class.Data from Exercise Graphics E10.18Enhance the ButtonViewer program so that it has two
Implement the AddInterestListener in the InvestmentViewer1 program as a regular class (that is, not an inner class). Store a reference to the bank account. Add a constructor to the listener class
Implement the AddInterestListener in the InvestmentViewer2 program as a regular class (that is, not an inner class). Store references to the bank account and the label in the listener. Add a
Reimplement the program in Section 10.7.2, specifying the listener with a lambda expression (as described at the end of Section 10.7.2).
Reimplement the program in Section 10.8, specifying the listener with a lambda expression (as described at the end of Section 10.7.2).Data from 10.8data from 10.7.2
Reimplement the program in Section 10.9, specifying the listener with a lambda expression.Data From Section 10.9: sec09/RectangleFrame.java 1 import java.awt.event.Action Event; 2 import
Change the RectangleComponent for the animation program in Section 10.9 so that the rectangle bounces off the edges of the component rather than moving outside.Data from section 10.9
Change the RectangleComponent for the mouse listener program in Section 10.10 so that a new rectangle is added to the component whenever the mouse is clicked. Keep an ArrayList and draw all
Suppose we have a string holding the text of an entire book. If we want to analyze segments of the text, it is inefficient to make substrings. Instead, we should just store a reference to the
Your task is to design a general program for managing board games with two players.Your program should be flexible enough to handle games such as tic-tac-toe, chess, or the Game of Nim of Exercise
Write a program that lets users design bar charts with a mouse. When the user clicks inside a bar, the next mouse click extends the length of the bar to the x-coordinate of the mouse click. (If it is
Consider the task of writing a program that plays tic-tac-toe against a human opponent.A user interface TicTacToeUI reads the user’s moves and displays the computer’s moves and the board. A class
Consider the task of translating a plain-text book from Project Gutenberg (http://gutenberg.org) to HTML. For example, here is the start of the first chapter of Tol stoy’s Anna Karenina:Chapter 1
Write a program that demonstrates the growth of a roach population. Start with two roaches and double the number of roaches with each button click.
Design an interface MoveableShape that can be used as a generic mechanism for animating a shape. A moveable shape must have two methods: move and draw. Write a generic AnimationPanel that paints and
What happens when you supply the same name for the input and output files to the Total program of Section 11.1? Try it out if you are not sure.
Suppose you wanted to add the total to an existing file instead of writing a new file. Exercise • R11.1 indicates that you cannot simply do this by specifying the same file for input and output.
Your input file contains a sequence of numbers, but sometimes a value is not available and is marked as N/A. How can you read the numbers and skip over the markers?
Can the readFile method in Section 11.5 throw a NullPointer Exception? If so, how?
Write a program that reads a file containing rows of numbers. Each row may have a different length, and some may be blank. Print the average of each row, or zero if a row is blank.
Modify the BankAccount class to throw an IllegalArgumentException when the account is constructed with a negative balance, when a negative amount is deposited, or when an amount that is not between 0
Repeat Exercise • E11.15 , but throw exceptions of three exception types that you provide.Data from Exercise E11.15 Modify the BankAccount class to throw an IllegalArgumentException when the
Using the mechanism described in Special Topic 11.1, write a program that reads all data from a web page and writes them to a file. Prompt the user for the web page URL and the file.Data from special
Download the file airports.dat from https://openflights.org/data.html. Write a program that prompts the user for the name of a city and then reads the airport data file, printing the names of all
Write a program that reads in a set of coin descriptions from a file. The input file has the format: coinNamel coinValuel coinName2 coinValue2 Add a method void read (Scanner in) throws FileNot
Design a class Bank that contains a number of bank accounts. Each account has an account number and a current balance. Add an accountNumber field to the BankAccount class. Store the bank accounts in
Suppose you are asked to implement a program that simulates your favorite social network. List the classes that you would implement.
Consider an enhancement of the quiz application from Chapter 9 such that a course has a number of quizzes and a number of students. Each student can log in (with a user name and password) and take a
Write CRC cards for the Coin and CashRegister classes described in Section 8.2.Data from section 8.2
Write CRC cards for the Quiz and Question classes in Section 12.2.2.Data from section 12.2.2
Draw a UML diagram for the Quiz, Question, and ChoiceQuestion classes. The Quiz class is described in Section 12.2.2.
Consider the following problem description: Users place coins in a vending machine and select a product by pushing a button. If the inserted coins are sufficient to cover the purchase price of the
Consider the following problem description: Employees receive their biweekly paychecks. They are paid their hourly rates for each hour worked; however, if they worked more than 40 hours per week,
Consider the following problem description: Customers order products from a store. Invoices are generated to list the items and quantities ordered, payments received, and amounts still due. Products
Provide a user interface to the invoice program in Section 12.3 that allows a user to enter and print an arbitrary invoice. Do not modify any of the existing classes.
Write a program to design an appointment calendar. An appointment includes the date, starting time, ending time, and a description; for example,Supply a user interface to add appointments, remove
In an “instant runoff” election, voters mark their favorite candidate on the ballot as well as two alternate candidates (in case their first or second choice does not win). When the ballots are
To compute the sum of the values in an array, add the first value to the sum of the remaining values, computing recursively. Design a recursive helper method to solve this problem.
How can you write a recursive method public static void sum(int[] a) without needing a helper function? Why is this less efficient?
Outline, but do not implement, a recursive solution for sorting an array of numbers. First sort the subarray without the initial element.
In some cultures, numbers containing the digit 8 are lucky numbers. What is wrong with the follow ing method that tries to test whether a number is lucky? public static boolean isLucky (int number) {
Using backtracking, write a program that solves summation puzzles in which each letter should be replaced by a digit, such as send + more = money Your program should find the solution 9567 + 1085 =
Using the isPalindrome method from Section 13.2 and a recursive reverse method from Exercise • E13.6, write a program to address the following mathematical hypothesis. It is believed (but not
Change the permutations method of Section 13.4 (which computed all permutations at once) to a PermutationIterator (which computes them one at a time).Now we need a way to iterate through the
Implement an iterator that produces the moves for the Towers of Hanoi puzzle described in Worked Example 13.2. Provide methods hasMoreMoves and nextMove. The nextMove method should yield a string
Using backtracking, write a program to find whether a given word can be spelled with symbols for the chemical elements. For example, brother can be spelled as Br O Th Er, the symbols for bromium,
The Koch Snowflake. A snowflake-like shape is recursively defined as follows. Start with an equilateral triangle: Next, increase the size by a factor of three and replace each straight line with four
In Java, objects are grouped into classes according to their behavior. Would a window object and a water heater object belong to the same class or to different classes?Why?
Some light bulbs use a glowing filament, others use a fluorescent gas. If you consider a light bulb a Java object with an “illuminate” method, would you need to know which kind of bulb it is?
Explain the difference between an object and a class.
Showing 500 - 600
of 791
1
2
3
4
5
6
7
8