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
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
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
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
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
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
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):
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
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,
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 {
Write a program that takes user input describing a playing card in the following shorthand notation:A.....Ace2.....10 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
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
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 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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
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
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
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
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
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
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
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
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
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 =
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
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
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
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,
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
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.
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,
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
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.
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) /
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)
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 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.
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
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
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
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
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
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[]
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
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
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
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
Showing 700 - 800
of 835
1
2
3
4
5
6
7
8
9