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 Study Help
New
Search
Search
Sign In
Register
study help
computer science
java programming
Questions and Answers of
Java Programming
Most countries (with the exception of Canada, Colombia, the Dominican Republic, Mexico, and the United States) follow the ISO 216 standard for paper sizes. An A0 sheet has dimensions 841 × 1189
A Person has a name (just a first name for simplicity) and friends. Store the names of the friends in a string, separated by spaces. Provide a constructor that constructs a person with a given name
Add a method:to the Person class of Exercise •• P3.6.Data from P 3.6A Person has a name (just a first name for simplicity) and friends. Store the names of the friends in a string, separated by
Write a class Battery that models a rechargeable battery. A battery has a constructor public Battery(double capacity) where capacity is a value measured in milliampere hours. A typical AA battery has
Write a program that draws three stars like the one at right. Use classes Star, StarComponent, and StarViewer.
Implement a class RoachPopulation that simulates the growth of a roach population. The constructor takes the size of the initial roach population. The breed method simulates a period in which the
In this project, you will enhance the Bank Account class and see how abstraction and encapsulation enable evolutionary changes to software. Begin with a simple enhancement: charging a fee for every
In this project, you will explore an object-oriented alternative to the “Hello, World”program in Chapter 1.Begin with a simple Greeter class that has a single method, sayHello. That method should
Given a string s, write expressions for:• The string consisting of the first letter• The string consisting of the first and last letter• The string consisting of all but the first and last
Find at least five compile-time errors in the following program. public class HasErrors {
Find three run-time errors in the following program. public class Has Errors { } public static void main(String[] args) { } int x = 0; int y = 0; Scanner in new Scanner("System.in");
Consider the following code: Cash Register register = new Cash Register(); register.record Purchase(19.93); register. receive Payment (20, 0, 0, 0, 0); System.out.print("Change: ");
Explain the differences between 2, 2.0 , '2', "2", and "2.0".
In Worked Example 4.1 , it is easy enough to measure the width of a pyramid. To measure the height without climbing to the top, you can use a theodolite and determine the angle between the ground and
A cocktail shaker is composed of three cone sections. The volume of a cone section with height h and top and bottom radius r1 and r2 is:Compute the total volume by hand for one set of realistic
You are cutting off a piece of pie like this, where c is the length of the straight part(called the chord length) and h is the height of the piece.However, h is not so easy to measure, whereas the
Write a program that displays the properties of a letter-size (8.5 × 11 inches) sheet of paper in millimeters. There are 25.4 millimeters per inch. The program should print:• The width and
Write a program that prompts the user for two integers and then prints• The sum• The difference• The product• The average• The distance (absolute value of the difference)• The maximum
Enhance the output of Exercise •• E4.3 so that the numbers are properly aligned:Data from exercise E 4.3Write a program that prompts the user for two integers and then prints• The sum• The
Write a program that asks the user for the lengths of a rectangle’s sides. Then print• The area and perimeter of the rectangle• The length of the diagonal (use the Pythagorean theorem)
Improve the program discussed in How To 4.1 to allow input of quarters in addition to bills.Data from How to 4.1
Change the Menu class in Worked Example 3.1 so that the menu options are labeled A, B, C, and so on. Make a string of the labels.Data from worked example 3.1. WORKED EXAMPLE 3.1 Making a Simple Menu
File names and extensions. Write a program that prompts the user for the drive letter (C), the path (\Windows\System), the file name (Readme), and the extension (txt). Then print the complete file
Write a program that reads a number between 1,000 and 999,999 from the user, where the user enters a comma in the input. Then print the number without a comma. Here is a sample dialog; the user input
Write a program that reads a number between 1,000 and 999,999 from the user and prints it with a comma separating the thousands. Here is a sample dialog; the user input is in color: Please enter an
Write a program that prints the following grid to play tic-tac-toe.You should do it the smart way, though. Declare string variables to hold two kinds of patterns: a comb-shaped pattern and the bottom
Write a program that reads in an integer and breaks it into a sequence of individual digits. For example, the input 16384 is displayed as:You may assume that the input has no more than five digits
Write a program that reads two times in military format (0900, 1730) and prints the number of hours and minutes between the two times. Here is a sample run. User input is in color. Please enter the
Writing large letters. A large letter H can be produced like this:Print the string with System.out.printf. The %n format specifiers cause line breaks in the output. Do the same for the letters E, L,
Write a program that transforms numbers 1, 2, 3, …, 12 into the corresponding month names January, February, March, …, December. Make a very long string "January February March ...", in which you
Write a program that prints a Christmas tree: /\ "1 11 1 " " Remember to use escape sequences.
Enhance the CashRegister class by adding separate methods enterDollars, enter-Quarters, enterDimes, enterNickels, and enterPennies.Use this tester class: public class CashRegister Tester { public
Implement a class IceCreamCone with methods getSurfaceArea() and getVolume(). In the constructor, supply the height and radius of the cone. Be careful when looking up the formula for the surface
Implement a class SodaCan whose constructor receives the height and diameter of the soda can. Supply methods getVolume and getSurfaceArea. Supply a SodaCanTester class that tests your class.
Implement a class Balloon that models a spherical balloon that is being filled with air.The constructor constructs an empty balloon. Supply these methods:Supply a BalloonTester class that constructs
Write a program that reads a number from the user and does the following: Discard all but the last three digits. Reverse the digits, subtract the original from the reversed (discarding any minus
A boat floats in a two-dimensional ocean. It has a position and a direction. It can move by a given distance in its current direction, and it can turn by a given angle.Provide methods: public double
The CashRegister class has an unfortunate limitation: It is closely tied to the coin system in the United States and Canada. Research the system used in most of Europe.Your goal is to produce a cash
Consider the following tuning circuit connected to an antenna, where C is a variable capacitor whose capacitance ranges from Cmin to Cmax. Antenna f The tuning circuit selects the frequency. To
Assume that n is 1. For each of the combinations ofa, b, and c given at right, what is the value of n after each compound if statement?a. if (a b) { if (b c) { n = 2; } else { n = 3; } }b. if (a b) {
Explain the difference between s = 0; if (x > 0) { s++; } (y> 0) { s++; } if and S = 0; if (x > 0) { s++; } else if (y> 0) { s++; }
Find the errors in the following if statements:a. b. c. d. e. if x>0 then System.out.print(x);
What do these code fragments print?a. b. c. d. int n = 1; int m = -1; if (nm) { System.out.print (n); } else { System.out.print(m); }
Give a set of four test cases for the algorithm of Exercise •• R5.11 that covers all branches.Data from Exercise R5.11Each square on a chess board can be described by a letter and number, such as
Draw a flow chart for the algorithm in Exercise •• E5.12.Data from Exercise E5.12When two points in time are compared, each given as hours (in military time, ranging from 0 and 23) and minutes,
Draw a flow chart for the algorithm in Exercise •• P5.1.Data from Exercise P5.1The following algorithm yields the season (Spring, Summer, Fall, or Winter) for a given month and day.Write a
Develop a set of test cases for the algorithm in Exercise •• P5.1.Data from Exercise P 5.1The following algorithm yields the season (Spring, Summer, Fall, or Winter) for a given month and
Rewrite the condition in Section 5.3 to use < operators instead of >= operators. What is the impact on the order of the comparisons?
Give a set of test cases for the tax program in Exercise •• P5.3. Manually compute the expected results.Data from exercise P5.3Write a program that computes taxes for the following schedule. If
What is wrong with the following program? System.out.print("Enter the number of quarters: "); int quarters = in.nextInt (); if (in.hasNextInt()) { total total + quarters * 0.25;
Write a program that reads a string, compares the first and last letter, and and prints “first and last letter same” or “first and last letter different”.
Write a program that reads a word, compares the first and second half of the word, and prints “first and second half same” or “first and second half different”. If the length of the word is
Write a program that translates a number between 0 and 4 into the closest letter grade. For example, the number 2.8 (which might have been the average of several grades) would be converted to B–.
Write a program that takes user input describing a playing card in the following shorthand notation:A Ace 2 ... 10 Card values J Jack Q Queen K King D Diamonds H Hearts S Spades C Clubs Your program
Write a program that reads in the name and salary of an employee. Here the salary will denote an hourly wage, such as $9.25. Then ask how many hours the employee worked in the past week. Be sure to
A supermarket awards coupons depending on how much a customer spends on groceries. For example, if you spend $50, you will get a coupon worth eight percent of that amount. The following table shows
Write a program to simulate a bank transaction. There are two bank accounts: checking and savings. First, ask for the initial balances of the bank accounts; reject negative balances. Then ask for the
Given the variables:a. b. c. d. e. String stars *******; String stripes = "===== what do these loops print?
What do these code snippets print?a. b. c. d. int result = 0; for (int i = 1; i
Provide trace tables for these loops.a. b. c. d. int i=0; int j = 10; int n = 0; while (ij) { i++; j-; n++; }
What do these loops print? a. for (int i = 1; i
Add a storyboard panel for the conversion program in Section 6.6 that shows a scenario where a user enters incompatible units.
In Section 6.6, we decided to show users a list of all valid units in the prompt. If the program supports many more units, this approach is unworkable. Give a story board panel that illustrates an
Change the storyboards in Section 6.6 to support a menu that asks users whether they want to convert units, see program help, or quit the program. The menu should be displayed at the beginning of the
Explain the differences between these debugger operations:• Stepping into a method• Stepping over a method
Explain in detail how to inspect the string stored in a String object in your debugger.
Explain in detail how to inspect the information stored in a Rectangle object in your debugger.•• Testing
Explain in detail how to use your debugger to inspect the balance stored in a Bank-Account object.
Explain the divide-and-conquer strategy to get close to a bug in a debugger.
Translate the following pseudocode for randomly permuting the characters in a string into a Java program. Read a word. Repeat word length times Pick a random position i in the word, but not the last
Using the Picture class from Worked Example 6.2, apply a sunset effect to a picture, increasing the red value of each pixel by 30 percent (up to a maximum of 255).Data from worked example 6.2. WORKED
Print a diamond shape, as in the preceding exercise, with the asterisks in the middle row and column omitted, like this: ****** ** **
Print an X shape in a box of a given side length, like this:
Enhance Worked Example 6.1 to check that the credit card number is valid. A valid credit card number will yield a result divisible by 10 when you:Form the sum of all digits. Add to that sum every
The Fibonacci numbers are defined by the sequenceAfter that, discard fold2, which is no longer needed, and set fold2 to fold1 and fold1 to fnew. Repeat an appropriate number of times.Implement a
Factoring of integers. Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 150, the program should print 2355 Use a class
Prime numbers. Write a program that prompts the user for an integer and then prints out all prime numbers up to that integer. For example, when the user enters 20, the program should print:2357 11 13
Mean and standard deviation. Write a program that reads a set of floating-point data values. Choose an appropriate mechanism for prompting for the end of the data set. When all values have been read,
A bicycle combination lock has four rings with numbers 0 through 9. Given the actual numbers and the combination to unlock, print instructions to unlock the lock using the minimum number of twists. A
A simple model for the hull of a ship is given by:(Note: There are two values of y for each x and z because the hull is symmetric from starboard to port.)The cross-sectional area at a point x is
Carry out the following tasks with an array: a. Allocate an array a of ten integers. b. Put the number 17 as the initial element of the array. c. Put the number 29 as the last element of the array.
What is wrong with each of the following code segments? a. ArrayList b. ArrayList c. ArrayList values = new ArrayList (); values = new ArrayList(); values = new ArrayList ;
Trace the flow of the loop in Section 7.3 .4 with the given example. Show two columns, one with the value of i and one with the output.
Trace the flow of the loop in Section 7.3.5, where values contains the elements 80 90 100 120 110. Show two columns, for pos and found. Repeat the trace when values contains the elements 80 90 120
Trace the algorithm for removing an element described in Section7.3.6. Use an array values with elements 110 90 100 120 80, and remove the element at index 2.
What is wrong with the following method that aims to fill an array with random numbers?
Solve the task described in Section 7.5 using an algorithm that removes and inserts elements instead of switching them. Write the pseudocode for the algorithm, assuming that methods for removal and
Section 7.7 .7 shows that you must be careful about updating the index value when you remove elements from an array list. Show how you can avoid this problem by traversing the array list backwards.
Define the terms regression testing and test suite.
What is the debugging phenomenon known as cycling? What can you do to avoid it?
Type in and run the following program. Then modify it to show a different greeting and image. import java.net. URL; import javax.swing.ImageIcon; import javax.swing.JOptionPane; public class Test { }
Rewrite Exercise to store the answers in a set rather than a list. Write a program that creates an ArrayList and adds a Loan object, a Date object, a string, and a Circle object to the list,
Java is architecturally _________________.a. Neutralb. Orientedc. Specificd. Abstract
Sunshine Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists. In Chapter 2, you wrote an application that prompts the user for the number of
The to String () method converts the data type(s) _________________ to a String.a. Charb. Char and intc. Char, int, and floatd. Char, int, float, and double
A useful recursive method must _________________.a. Call another methodb. Produce outputc. Provide a way to stop recursiond. Accept parameters
In previous chapters, you have created a number of programs for Yummy Catering. Now, create an interactive GUI program that allows the user to enter the number of guests for an event into a text
Unlike a Window, a JFrame _________________.a. Has a title bar and borderb. Can be made visiblec. Can have descendantsd. Can hold other objects
Which of the following does not set a JFrame named aFrame to be 300 pixels wide by 200 pixels tall?a. JFr ame aFrame = new JFrame(300, 200);b. AFrame.setSize(300, 200);c. AFrame.setBounds(300,
An advantage of extending the JFrame class is _________________.a. You can set the child class properties within the class constructorb. There is no other way to cause an application to close when
Showing 700 - 800
of 791
1
2
3
4
5
6
7
8