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
java concepts late objects
Java Concepts Late Objects 3rd Edition Cay S. Horstmann - Solutions
Write a program that computes taxes for the following schedule. If your status Is Single and If the taxable Income Is over the tax Is but not over of the amount over $8,000 10% $0 $8,000 $32,000 $800 + 15% $8,000 $32,000 $4,400 + 25% $32,000 If your status Is Marrled and If the taxable Income Is
Write a program that reads four integers and prints “two pairs” if the input consists of two matching pairs (in some order) and “not two pairs” otherwise. For example,1 2 2 1 two pairs1 2 2 3 not two pairs2 2 2 2 two pairs
Given two pixels on a computer screen with integer coordinates (x1, y1) and (x2, y2), write conditions to test whether they area. The same pixel.b. Very close together (with distance < 5).
The original U.S. income tax of 1913 was quite simple. The tax was• 1 percent on the first $50,000.• 2 percent on the amount over $50,000 up to $75,000.• 3 percent on the amount over $75,000 up to $100,000.• 4 percent on the amount over $100,000 up to $250,000.• 5 percent on the amount
Write a program that reads in three integers and prints “in order” if they are sorted in ascending or descending order, or “not in order” otherwise. For example,1 2 5 in order1 5 2 not in order5 2 1 in order1 2 2 in order
Explain why it is more difficult to compare floating-point numbers than integers. Write Java code to test whether an integer n equals 10 and whether a floating-point number x is approximately equal to 10.
Write a program that prompts for the day and month of the user’s birthday and then prints a horoscope. Make up fortunes for programmers, like this: Please enter your birthday (month and day): 6 16 Gemini are experts at figuring out the behavior of complicated programs. You feel where bugs
Repeat Exercise E3.5, but before reading the numbers, ask the user whether increasing\decreasing should be “strict” or “lenient”. In lenient mode, the sequence 3 4 4 is increasing and the sequence 4 4 4 is both increasing and decreasing.Data from Exercise E3.5,Write a program that reads
Suppose x and y are variables of type double. Write a code fragment that sets y to the absolute value of x without calling the Math.abs function. Use an if statement.
Write a program that reads in three strings and sorts them lexicographically. Enter three strings: Charlie Able Baker AbleBaker Charlie
Write a program that reads three numbers and prints “increasing” if they are in increasing order, “decreasing” if they are in decreasing order, and “neither” otherwise. Here, “increasing” means “strictly increasing”, with each value larger than its predecessor. The sequence 3 4
Suppose x and y are variables of type double. Write a code fragment that sets y to x if x is positive and to 0 otherwise.
Write a program that reads three numbers and prints “all the same” if they are all the same, “all different” if they are all different, and “neither” otherwise.
What do these code fragments print?a. int n = 1;int m = -1;if (n < -m) { System.out.print(n); }else { System.out.print(m); }b. int n = 1;int m = -1;if (-n >= m) { System.out.print(n); }else { System.out.print(m); }c. double x = 0;double y = 1;if (Math.abs(x - y) < 1) { System.out.print(x);
Write a program that takes user input describing a playing card in the following shorthand notation:A.....Ace2.....10 Card valuesJ......JackQ....QueenK.....KingD.....DiamondsH.....HeartsS......SpadesC......ClubsYour program should print the full description of the card. For example, Enter the card
Write a program that reads an integer and prints how many digits the number has, by checking whether the number is ≥ 10, ≥ 100, and so on. (Assume that all integers are less than ten billion.) If the number is negative, first multiply it with –1.
Find the errors in the following if statements.a. if x > 0 then System.out.print(x);b. if (1 + x > Math.pow(x, Math.sqrt(2)) { y = y + x; }c. if (x = 1) { y++; }d. x = in.nextInt();if (in.hasNextInt()){sum = sum + x;}else{System.out.println("Bad input for x");}e. String letterGrade = "F";if
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–. Break ties in favor of the better grade; for example 2.85 should be a B.
Write a program that reads a floating-point number and prints “zero” if the number is zero. Otherwise, print “positive” or “negative”. Add “small” if the absolute value of the number is less than 1, or “large” if it exceeds 1,000,000.
Explain the difference betweens = 0;if (x > 0) { s++; }if (y > 0) { s++; }ands = 0;if (x > 0) { s++; }else if (y > 0) { s++; }
Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or –. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F–. A + increases the numeric value by 0.3, a – decreases it by 0.3. However, an A+ has value
Write a program that reads an integer and prints whether it is negative, zero, or positive.
What is the value of each variable after the if statement?a. int n = 1; int k = 2; int r = n;if (k < n) { r = k; }b. int n = 1; int k = 2; int r;if (n < k) { r = k; }else { r = k + n; }c. int n = 1; int k = 2; int r = k;if (r < k) { n = r; }else { k = n; }d. int n = 1; int k = 2; int r =
This chapter contains a number of recommendations regarding variables and constants that make programs easier to read and maintain. Briefly summarize these recommendations.
Write a program that prints the values3 * 1000 * 1000 * 10003.0 * 1000 * 1000 * 1000Explain the results.
For each of the following computations in Java, determine whether the result is exact, an overflow, or a roundoff error.a. 2.0 – 1.1b. 1.0E6 * 1.0E6c. 65536 * 65536d. 1_000_000L * 1_000_000L
How do you get the first character of a string? The last character? How do you remove the first character? The last character?
Suppose you are given a string str and two Positions i and j, where i comes before j. The following pseudocode describes how to swap two letters in a word. We are given a string str and two positions i and j. (i comes before j) Set first to the substring from the start of the string to the last
The following pseudocode describes how to obtain the name of a day, given the daynumber (0 = Sunday, 1 = Monday, and so on.)Declare a string called names containing "SunMonTueWedThuFriSat".Compute the starting position as 3 x the day number. Extract the substring of names at the starting position
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.There is an approximate formula for the area:However, h is not so easy to measure, whereas the diameter d of a pie is usually well-known. Calculate the
Write a program that prints a Christmas tree, as shown below. Remember to use escape sequences.
A cocktail shaker is composed of three cone sections. Using realistic values for the radii and heights, compute the total volume, using the formula given in Self Check 25 for a cone section. Then develop an algorithm that works for arbitrary dimensions. OMedia Bakery.
Write a program that transforms numbers 1, 2, 3, …, 12 into the corresponding month names January, February, March, …, December. Hint: Make a very long string "January February March ...", in which you add spaces such that each month name has the same length. Then use substring to extract the
Modify the pseudocode for the program in How To 2.1 so that the program gives change in quarters, dimes, and nickels. You can assume that the price is a multiple of 5 cents. To develop your pseudocode, first work with a couple of specific values.
Writing large letters. A large letter H can be produced like this:It can be declared as a string literal like this: final string LETTER_H = "* *%n* *%n*****%n* *%n* *%n"; Print the string with System.out.printf. The %n format specifiers cause line breaks in the output. Do the same for the letters
Write the following mathematical expressions in Java. YRS INT FV = PV 1+ 100 G = 4x2. c= Va? + b2 - 2abcosy C = p2(m, + m2)
The following pseudocode describes how a bookstore computes the price of an order from the total price and the number of the books that were ordered. Read the total book price and the number of books. Compute the tax (7.5 percent of the total book price). Compute the shipping charge ($2 per book).
Write a program that reads a number and displays the square, cube, and fourth power. Use the Math.pow method only for the fourth power.
What is wrong with the following sequence of statements?int mystery = 1;mystery = mystery + 1;int mystery = 1 - 2 * mystery;
In this project, you will perform calculations with triangles. A triangle is defined by the x- and y-coordinates of its three corner points.Your job is to compute the following properties of a given triangle:• the lengths of all sides• the angles at all corners• the perimeter• the
Write a program that computes and displays the perimeter of a letter-size (8.5 × 11 inches) sheet of paper and the length of its diagonal.
What is the value of mystery after this sequence of statements?int mystery = 1;mystery = 1 - 2 * mystery;mystery = mystery + 1;
Easter Sunday is the first Sunday after the first full moon of spring. To compute the date, you can use this algorithm, invented by the mathematician Carl Friedrich Gauss in 1800:1. Let y be the year (such as 1800 or 2001).2. Divide y by 19 and call the remainder a. Ignore the quotient.3. Divide y
Write a program that displays the dimensions of a letter-size (8.5 × 11 inches) sheet of paper in millimeters. There are 25.4 millimeters per inch. Use constants and comments in your program.
Write declarations for storing the following quantities. Choose between integers and floating-point numbers. Declare constants when appropriate.a. The number of days per weekb. The number of days until the end of the semesterc. The number of centimeters in an inchd. The height of the tallest person
To speak more than one language is a valuable skill in the labor market today. One of the basic skills is learning to greet people. Write a program that prints a two-column list with the greeting phrases shown in the table. In the first column, print the phrase in English, in the second column,
Write pseudocode for a program that computes the first and last digit of a number. For example, if the input is 23456, the program should print 2 and 6. Hint: %, Math.log10.
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 first time: 0900 Please enter the second time: 1730 8 hours 30 minutes Extra credit if you can deal
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 integer between 1000 and 999999: 2345623,456
Write pseudocode for a program that reads a name (such as Harold James Morgan) and then prints a monogram consisting of the initial letters of the first, middle, and last name (such as HJM).
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 1 6 3 8 4 You may assume that the input has no more than five digits and is not negative.
Printing a grid. Write a program that prints the following grid to play tic-tac-toe.Of course, you could simply write seven statements of the form System.out.println("+--+--+--+"); You should do it the smart way, though. Declare string variables to hold two kinds of patterns: a comb-shaped pattern
Write pseudocode for a program that reads a word and then prints the first character, the last character, and the characters in the middle. For example, if the input is Harry, the program prints H y arr.
Explain what each of the following program segments computes.a. x = 2;y = x + x;b. s = "2";t = s + s;
According to the Coulomb force law, the electric force between two charged particles of charge Q1 and Q2 Coulombs, that are a distance r meters apart, isNewtons, where ε = 8.854 × 10−12 Farads/meter. Write a program that calculates the force on a pair of charged particles, based on the user
Explain the differences between 2, 2.0, '2', "2", and "2.0".
Consider the following tuning circuit connected to an antenna, where C is a variable capacitor whose capacitance ranges from Cmin to Cmax.Write a Java program to design a tuning circuit for a given frequency, using a variable capacitor with given values for Cmin and Cmax. (A typical input is f =
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 is in color: Please enter an integer between 1,000 and 999,999: 23,456 23456 Hint: Read the input
Consider the following code segment.double purchase = 19.93;double payment = 20.00;double change = payment - purchase;System.out.println(change);The code segment prints the change as 0.07000000000000028. Explain why. Give a recommendation to improve the code so that users will not be confused.
The circuit shown below illustrates some important aspects of the connection between a power company and one of its customers. The customer is represented by three parameters, Vt, P, and pf. Vt is the voltage accessed by plugging into a wall outlet. Customers depend on having a dependable value of
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 name C:\Windows\System\Readme.txt. (If you use UNIX or a Macintosh, skip the drive name and use / instead of \ to separate
Find three run-time errors in the following program.public class HasErrors{public static void main(String[] args){int x = 0;int y = 0;Scanner in = new Scanner("System.in");System.out.print("Please enter an integer:");x = in.readInt();System.out.print("Please enter another integer: ");x =
The pipe clip temperature sensors shown here are robust sensors that can be clipped directly onto copper pipes to measure the temperature of the liquids in the pipes.Each sensor contains a device called a thermistor. Thermistors are semiconductor devices that exhibit a temperature-dependent
Write a program that asks the user to input• The number of gallons of gas in the tank• The fuel efficiency in miles per gallon• The price of gas per gallonThen print the cost per 100 miles and how far the car can go with the gas in the tank.
Find at least five compile-time errors in the following program.public class HasErrors{public static void main();{System.out.print(Please enter two numbers:)x = in.readDouble;y = in.readDouble;System.out.printline("The sum is " + x + y);}}
The dew point temperature Td can be calculated (approximately) from the relative humidity RH and the actual temperature T bywhere a = 17.27 and b = 237.7° C. Write a program that reads the relative humidity (between 0 and 1) and the temperature (in degrees C) and prints the dew point value. Use
Write a program that helps a person decide whether to buy a hybrid car. Your program’s inputs should be:• The cost of a new car• The estimated miles driven per year• The estimated gas price• The efficiency in miles per gallon• The estimated resale value after 5 yearsCompute the total
Give an example of a method that has an argument of type int. Give an example of a method that has a return value of type int. Repeat for the type String.
Consider the circuit at right. Write a program that reads the resistances of the three resistors and computes the total resistance, using Ohm’s law. R R2 R3
Improve the program discussed in How To 2.1 to allow input of quarters in addition to bills.
Assuming that a and b are variables of type int, fill in the following table: b Math.pow(a, b) Math.max(a, b) a / b a %b Math. floorMod (a, b) a 3 3. -3 3 -2 -3 -3 -2 2. 2. 2. 2.
A video club wants to reward its best members with a discount based on the member’s number of movie rentals and the number of new members referred by the member. The discount is in percent and is equal to the sum of the rentals and the referrals, but it cannot exceed 75 percent. (Hint: Math.min.)
Write a program that asks the user for the lengths of the sides of a rectangle. Then print• The area and perimeter of the rectangle• The length of the diagonal (use the Pythagorean theorem)
What are the values of the following expressions? In each line, assume thatString s = "Hello";String t = "World";a. s.length() + t.length()b. s.substring(1, 2)c. s.substring(s.length() / 2, s.length())d. s + te. t + s
An online bank wants you to create a program that shows prospective customers how their deposits will grow. Your program should read the initial balance and the annual interest rate. Interest is compounded monthly. Print out the balances after the first three months. Here is a sample run:Initial
Write a program that prompts the user for a radius and then prints• The area and circumference of a circle with that radius• The volume and surface area of a sphere with that radius
What are the values of the following expressions, assuming that n and m have type int,n is 17, and m is 18?a. n / 10 + n % 10b. n % 2 + m % 2c. (m + n) / 2d. (m + n) / 2.0e. (int) (0.5 * (m + n))f. (int) Math.round(0.5 * (m + n))
Giving change. Implement a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer. Display the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return. In order to avoid roundoff
Write a program that prompts the user for a measurement in meters and then converts it to miles, feet, and inches.
What are the values of the following expressions? In each line, assume thatdouble x = 2.5;double y = -1.5;int m = 18;int n = 4;a. x + n * y - (x + n) * yb. m / n + m % nc. 5 * x - n / 5d. 1 - (1 - (1 - (1 - (1 - n))))e. Math.sqrt(Math.sqrt(n))
The following pseudocode describes how to extract the dollars and cents from a price given as a floating-point value. For example, a price 2.95 yields values 2 and 95 for the dollars and cents. Assign the price to an integer variable dollars. Multiply the difference price - dollars by 100 and add
Enhance the output of Exercise E2.4 so that the numbers are properly aligned:Sum: 45Difference: -5Product: 500Average: 22.50Distance: 5Maximum: 25Minimum: 20
Write the following Java expressions in mathematical notation.a. dm = m * (Math.sqrt(1 + v / c) / Math.sqrt(1 - v / c) - 1);b. volume = Math.PI * r * r * h;c. volume = 4 * Math.PI * Math.pow(r, 3) / 3;d. z = Math.sqrt(x * x + y * y);
The following pseudocode describes how to turn a string containing a ten-digit phone number (such as "4155551212") into a more readable string with parentheses and dashes, like this: "(415) 555-1212". Take the substring consisting of the first three characters and surround it with "(" 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 (the larger of the two)• The minimum (the smaller of the two)Hint: The max and min functions are
The ancient Babylonians had an algorithm for determining the square root of a numbera. Start with an initial guess of a / 2. Then find the average of your guess g and a / g. That’s your next guess. Repeat until two consecutive guesses are close enough. Write pseudocode for this algorithm.
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{public static void main(String[] args) throws Exception{URL imageLocation = new
Write pseudocode for an algorithm that describes how to prepare Sunday breakfast in your household.
Modify the program from Exercise E1.16 so that the dialog continues with the message “My name is Hal! What would you like me to do?” Discard the user’s input and display a message such as I'm sorry, Dave. I'm afraid I can't do that. Replace Dave with the name that was provided by the
Suppose you put your younger brother in charge of backing up your work. Write a set of detailed instructions for carrying out his task. Explain how often he should do it, and what files he needs to copy from which folder to which location. Explain how he should verify that the backup was carried
Type in and run the following program. Then modify it to print “Hello, name!”, displaying the name that the user typed in.import javax.swing.JOptionPane;public class DialogViewer{public static void main(String[] args){String name = JOptionPane.showInputDialog("What is your
In How To 1.1, you made assumptions about the price of gas and annual usage to compare cars. Ideally, you would like to know which car is the better deal without making these assumptions. Why can’t a computer program solve that problem?
Type in and run the following program. Then modify it to show the message “Hello, your name!”.import javax.swing.JOptionPane;public class DialogViewer{public static void main(String[] args){JOptionPane.showMessageDialog(null, "Hello, World!");}}
In order to estimate the cost of painting a house, a painter needs to know the surface area of the exterior. Develop an algorithm for computing that value. Your inputs are the width, length, and height of the house, the number of windows and doors, and their dimensions. (Assume the windows and
Write a program that prints the United States flag, using * and = characters.
Consider the question in Exercise R1.13. Suppose the numbers ($10,000, 6 percent, $500) were user selectable. Are there values for which the algorithm you developed would not terminate? If so, change the algorithm to make sure it always terminates.Data from Exercise R1.13.Write an algorithm to
Write a program that prints a poem of your choice. If you don’t have a favorite poem, search the Internet for “Emily Dickinson” or “e e cummings”.
Write an algorithm to settle the following question: A bank account starts out with $10,000. Interest is compounded monthly at 6 percent per year (0.5 percent per month). Every month, $500 is withdrawn to meet college expenses. After how many years is the account depleted?
Write a program that prints three items, such as the names of your three best friends or favorite movies, on three separate lines.
The cafeteria offers a discount card for sale that entitles you, during a certain period, to a free meal whenever you have bought a given number of meals at the regular price. The exact details of the offer change from time to time. Describe an algorithm that lets you determine whether a particular
Showing 700 - 800
of 835
1
2
3
4
5
6
7
8
9
Step by Step Answers