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 an introduction to problem solving and progra
Java An Introduction To Problem Solving And Programming 8th Edition Walter Savitch - Solutions
Create a JavaFx application that draws a pattern of evenly spaced circles. Use four constants to control the pattern: the number of circles to draw, the radius of the first circle, the change in the radius of each subsequent circle, and the change in the x-coordinate of the circle. Cycle the colors
Suppose that you work for a beverage company. The company wants to know the optimal cost for a cylindrical container that holds a specified volume. Write a fragment of code that uses an ask-before-iterating loop. During each iteration of the loop, your code will ask the user to enter the volume and
Write a JavaFx application that draws a bull’s-eye pattern. The center should be a filled-in blue circle with a diameter of 100 pixels. The center circle should be surrounded by five rings that alternate in color from green to blue. Each ring should have a width of 30 pixels.
Write a fragment of code that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterwards.
Repeat Programming Project 7, but write the program as JavaFx application. Use a constant for the initial velocity of the ball. Draw a circle for the position of the ball at each second. The ycoordinate should be proportional to the height of the ball, and the x-coordinate should change by a small
Define an enumeration for each of the months in the year. Use a for-each statement to display each month.
Your country is at war and your enemies are using a secret code to communicate with one another. You have managed to intercept a message that reads as follows::mmZ\dxZmx]ZpgyThe message is obviously encrypted using the enemy’s secret code. You have just learned that their encryption method is
Suppose we attend a party. To be sociable, we will shake hands with everyone else. Write a fragment of code using a for statement that will compute the total number of handshakes that occur. Upon arrival, each person shakes hands with everyone who is already there. Use the loop to find the total
Holy digits Batman! The Riddler is planning his next caper somewhere on Pennsylvania Avenue. In his usual sporting fashion, he has left the address in the form of a puzzle. The address on Pennsylvania is a four-digit number where: All four digits are differentThe digit in the thousands place
Develop an algorithm for a simple game of guessing at a secret five-digit code. When the user enters a guess at the code, the program returns two values: the number of digits in the guess that are in the correct position and the sum of those digits. For example, if the secret code is 53840, and the
Write a program that reads a string for a date in the format month / day / year and displays it in the format day . month . year, which is a typical format used in Europe. For example, if the input is 06 /17/11, the output should be 17.06.11.Your program should use JOptionPane for input and output.
Write a program that inputs two strings that represents a time of day using the format HH:MM:SS AM or PM and then outputs the time elapsed from the first to the second time in minutes and seconds.For example, given the strings:11:58:10 PM12:02:15 AMThe program should output that the time elapsed is
Repeat the previous exercise, but change next to nextLine in the statement that assigns a value to b.Previous exerciseWhat does the Java codeScanner keyboard = new Scanner(System.in);keyboard.useDelimiter("y");System.out.println("Enter a string.");String a = keyboard.next();String b =
If u = 2, v = 3, w = 5, × = 7, and y = 11, what is the value of each of the following expressions, assuming int variables?u + v * w + ×u + y % v * w + ×u++ / v + u++ * w
Write a program that will compute statistics for eight coin tosses. The user will enter either an h for heads or a t for tails for the eight tosses. The program will then display the total number and percentages of heads and tails. Use the increment operator to count each h and t that is entered.
Suppose we can buy a chocolate bar from the vending machine for $1 each. Inside every chocolate bar is a coupon. We can redeem six coupons for one chocolate bar from the machine. This means that once you have started buying chocolate bars from the machine, you always have some coupons. We would
Write a loop that will create a new string that is the reverse of a given string.
You have three identical prizes to give away and a pool of ten finalists. The finalists are assigned numbers from 1 to 10. Write a program to randomly select the numbers of three finalists to receive a prize. Make sure not to pick the same number twice. For example, picking finalists 3, 6, 2 would
Write a loop that will count the number of blank characters in a given string.
Write a program that simulates a bouncing ball by computing its height in feet at each second as time passes on a simulated clock. At time zero, the ball begins at height zero and has an initial velocity supplied by the user. (An initial velocity of at least 100 feet per second is a good choice.)
Write a program that asks the user to enter the size of a triangle (an integer from 1 to 50). Display the triangle by writing lines of asterisks. The first line will have one asterisk, the next two, and so on, with each line having one more asterisk than the previous line, up to the number entered
Write a for statement to compute the sum 1 + 2 + 3 + 4 + 5 + … + n .
Repeat Practice Program 7 using JOptionPane, which is described in the graphics supplements of Chapters 2 and 3.Practice Program 7Combine the programs from Programming Projects 5 and 6 to read integer exam scores in the range 0 to 100 and to display the following statistics:Total number of
Convert the following code so that it uses nested while statements instead of for statements:int s = 0;int t = 1;for (int i = 0; i < 10; i++){s = s + i;for (int j = i; j > 0; j−−){t = t * (j − i);}s = s * t;System.out.println("T is " + t);}System.out.println("S is " + s);
Modify Programming Project 5 from Chapter 2 to check the validity of input data. Valid input is no less than 25 cents, no more than 100 cents, and an integer multiple of 5 cents. Compute the change only if a valid price is entered. Otherwise, print separate error messages for any of the following
Write a fragment of code that will compute the sum of the first n positive odd integers. For example, if n is 5, you should compute 1 + 3 + 5 + 7 + 9.
Write a program that reads a bank account balance and an interest rate and displays the value of the account in ten years. The output should show the value of the account for three different methods of compounding interest: annually, monthly, and daily. When compounded annually, the interest is
For all of the following words, if you move the first letter to the end of the word, and then spell the result backwards, you will get the original word: banana dresser grammar potato revive uneven assess Write a program that reads a word and determines whether it has this property. Continue
Develop an algorithm for computing the month-by-month balance in your savings account. You can make one transaction—a deposit or a withdrawal each month. Interest is added to the account at the beginning of each month. The monthly interest rate is the yearly percentage rate divided by 12.
Write a program that implements your algorithm from Exercise 3.Exercise 3.Develop an algorithm for a simple game of guessing at a secret five-digit code. When the user enters a guess at the code, the program returns two values: the number of digits in the guess that are in the correct position and
Write a fragment of code that will read words from the keyboard until the word done is entered. For each word except done, report whether its first character is equal to its last character. For the required loop, use aa. While statementb. Do-while statement
Write Java statements that create a yes-or-no dialog box to answer the question, “Are you in college?”
Given that the int variable temp contains a temperature that is not negative, write a Java statement that uses the conditional operator to set the String variablelabel to either "degree" or "degrees". We want to use label to produce grammatically correct output, such as 0 degrees, 1 degree, 2
Repeat Exercise 13, but use a multibranch if-else statement instead of a switch statement.Exercise 13Imagine a program that displays a menu of five possible choices, lettered a through e. Suppose the user’s selection is read into the character variable choice. Write a switch statement that reacts
Repeat the previous exercise, but define an enumeration and use it within the switch statement.Previous exerciseImagine a program that displays a menu of five possible choices, lettered a through e. Suppose the user’s selection is read into the character variable choice. Write a switch statement
Imagine a program that displays a menu of five possible choices, lettered a through e. Suppose the user’s selection is read into the character variable choice. Write a switch statement that reacts to this choice by displaying a message that indicates the choice. Display an error message if the
Consider the previous question, but include + or − letter grades. A+ is 4.25, A− is 3.75, B+ is 3.25, B− is 2.75, and so on.a. Why can’t we use one switch statement with no other conditionals to convert these additional letter grades?b. Write a fragment of code that will do the conversion
Write a switch statement to convert a letter grade into an equivalent numeric value on a fourpoint scale. Set the value of the variable gradeValue to 4.0 for an A, 3.0 for a B, 2.0 for a C, 1.0 for a D, and 0.0 for an F. For any other letter, set the value to 0.0 and display an error message.
The following flowchart contains a series of questions to determine what kind of haircut to get. Write a program that asks the questions to the user and outputs the recommended haircut based on the user’s input. Male or Female? Male Female Superhero or Super Superhero or Super villain? villain?
Consider the boolean expression((2 < 5) && (x < 100)). Why is this expression probably not what the programmer intended?
Repeat Programming Project 8 in Chapter 1, but add yes-or-no dialogs to allow the user to make the following color changes:Change the color of the solid center circle from black to red.Change the color of the outer circle from black to blue.Change the color of the spines from black to
Consider the boolean expression((x > 10) || (x < 100)). Why is this expression probably not what the programmer intended?
Write a JavaFx application to draw the five interlocking rings that are the symbol of the Olympics. The color of the rings, from left to right, is blue, yellow, black, green, and red.
The following code fragment will not compile. Why?if !x > x + yx = 2 * x;elsex = x + 3;
Write a program to play the rock-paper-scissor game. Each of two users types in either P, R, or S. The program then announces the winner as well as the basis for determining the winner: paper covers rock, rock breaks scissors, scissors cuts paper, or nobody wins. Your program should allow the users
What is the value of each of the following boolean expressions if x is 5,y is 10, and z is 15?a. (x < 5 && y > x)b. (x < 5 || y > x)c. (x > 3 || y < 10 && z == 15)d. (! (x > 3) && x!= z || x + y == z)
Repeat Programming Project 11 in Chapter 2, but if the displacement is positive then output that “The (material name) will expand by” the displacement in meters. If the displacement is negative then output that “The (material name) will contract by” the displacement in meters. You
We would like to assess a service charge for cashing a check. The service charge depends on the amount of the check. If the check amount is less than $10, we will charge $1. If the amount is greater than $10 but less than $100, we will charge 10 percent of the amount. If the amount is greater than
Repeat Programming Project 5 but in addition ask the user if he or she is a. Sedentaryb. Somewhat active (exercise occasionally)c. Active (exercise 3–4 days per week)d. Highly active (exercise every day)If the user answers “Sedentary,” then increase the calculated BMR by 20 percent. If
Consider the following fragment of code:if (x > 5){System.out.println("A");if (x < 10)System.out.println("B");}elseSystem.out.println("C");What is displayed if x isa. 4;b. 5;c. 6;d. 9;e. 10;f. 11
Repeat the calorie-counting program described in Programming Project 8 from Chapter 2. This time ask the user to input the string “M” if the user is a man and “W” if the user is a woman. Use only the male formula to calculate calories if “M” is entered and use only the female formula to
Write a program that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid.The input date will have the format mm/dd/yyyy. A valid
Consider the following fragment of code:if (x > 5)System.out.println("A");else if (x < 10)System.out.println("B");elseSystem.out.println("C");What is displayed if x isa. 4;b. 5;c. 6;d. 9;e. 10;f. 11
Suppose that we are working for an online service that provides a bulletin board for its users. We would like to give our users the option of filtering out profanity. Suppose that we consider the words cat, dog, and llama to be profane. Write a program that reads a string from the keyboard and
Suppose you are writing a program that asks the user to give a yes-or-no response. Assume that the program reads the user’s response into the Stringvariableresponse.a. If response is yes or y, set the boolean variable accept to true; otherwise, set it to false.b. How would you change the code so
Repeat any of the previous Practice Programs using JOptionPane, which is described in the graphics supplement at the end of Chapter 2.
Write a fragment of code that will change the integer value stored in x as follows. If x is even, divide x by 2. If x is odd, multiply x by 3 and subtract 1.
Write a fragment of code that will test whether an integer variable score contains a valid test score. Valid test scores are in the range 0 to 100.
Define named constants that you could use in Programming Project 6 in Chapter 1.Programming Project 6Write an JavaFx application that displays the following pattern:
Repeat Exercise 18 in Chapter 1, but define and use named constants.Exercise 18Write statements that can be used in a JavaFX application to draw the five interlocking rings that are the symbol of the Olympics. (Don’t worry about the color.)
Many sports have constants embedded in their rules. For example, baseball has 9 innings, 3 outs per inning, 3 strikes in an out, and 4 balls per walk. We might encode the constants for a program involving baseball as follows:public static final int INNINGS = 9;public static final int
How does a computer’s main memory differ from its auxiliary memory?
Write a Java program that displays the following picture. Write a sequence of println statements that display lines of asterisks and blanks. **** ** * **** ****** * ** ************** **** ** **
After you use a text editor to write a program, will it be in main memory or auxiliary memory?
Write a complete program for the problem described in Exercise 9.Exercise 9. Given a person’s year of birth, the Birthday Wizard can compute the year in which the person’s nth birthday will occur or has occurred. Write statements that can be used in a Java program to perform this
When a computer executes a program, will it be in main memory or auxiliary memory?
Write a complete program for the problem described in Exercise 10.Exercise 10.Write statements that can be used in a Java program to read two integers and display the number of integers that lie between them, including the integers themselves. For example, four integers are between 3 and 6: 3, 4,
How does machine language differ from Java?
Write an JavaFx application similar to the one in Listing 1.2 that displays a picture of a snowman. Draw three circles, one above the other. Make the circles progressively smaller from bottom to top. Make the top circle a happy face.Listing 1.2import javafx.application.Application;import
How does bytecode differ from machine language?
Write an JavaFx application for the problem described in Exercise 18.Exercise 18.Write statements that can be used in a JavaFX application to draw the five interlocking rings that are the symbol of the Olympics. (Don’t worry about the color.)
What would the following statements, when used in a Java program, display on the screen?int age;age = 20;System.out.println ("My age is");System.out.println(age);
Write an JavaFx application that displays the following pattern:
Write a statement or statements that can be used in a Java program to display the following on the screen:321
Write statements that can be used in a Java program to read your age, as entered at the keyboard, and display it on the screen.
Given a person’s year of birth, the Birthday Wizard can compute the year in which the person’s nth birthday will occur or has occurred. Write statements that can be used in a Java program to perform this computation for the Birthday Wizard.
Write statements that can be used in a Java program to read two integers and display the number of integers that lie between them, including the integers themselves. For example, four integers are between 3 and 6: 3, 4, 5, and 6.
A single bit can represent two values: 0 and 1. Two bits can represent four values: 00, 01, 10, and 11. Three bits can represent eight values: 000, 001, 010, 011, 100, 101, 110, and 111. How many values can be represented by a. 8 bits?b. 16 bits?c. 32 bits?
Find the documentation for the Java Class Library on the Oracle® Web site. (At this writing, the link to this documentation is https://docs.oracle.com/javase/8/docs/api/.) Then find the description for the class Scanner. How many methods are described in the section entitled “Method Summary”?
Self-Test Question 27 asked you to think of some attributes for a song object. What attributes would you want for an object that represents a play list containing many songs?Self-Test Question 27What attributes would you want for an object that represents a song?
What behaviors might a song have? What behaviors might a play list have? Contrast the difference in behavior between the two kinds of objects.
What attributes and behaviors would an object representing a credit card account have?
Suppose that you have a number x that is greater than 1. Write an algorithm that computes the largest integer k such that 2 is less than or equal to x.
Write statements that can be used in a JavaFX application to draw the five interlocking rings that are the symbol of the Olympics. (Don’t worry about the color.)
Find the documentation for the class Graphics Context in the JavaFX Class Library. (See Exercise 12.) Learn how to use the method strokeRect. Then write statements that can be used in a JavaFx application to draw a square containing a circle. The circle’s diameter and the square’s side should
Write statements that can be used in a JavaFx application to draw the outline of a crescent moon.
Write a program that demonstrates the approximate nature of floating point values by performing the following tasks:Use Scanner to read a floating-point value x.Compute 1.0 / x and store the result in y.Display x, y, and the product of x and y.Subtract 1 from the product of x and y and display the
Write a program that converts degrees from Fahrenheit to Celsius, using the formulaDegreesC = 5(DegreesF −32)/9Prompt the user to enter a temperature in degrees Fahrenheit as a whole number without a fractional part. Then have the program display the equivalent Celsius temperature, including the
Write a program that demonstrates type casting of double values by performing the following tasks:Use Scanner to read a floating-point value x.Type cast x to an int value and store the result in y.Display x and y clearly labeled.Type cast x to a byte value and store the result in z.Display x and z
Write a program that reads a line of text and then displays the line, but with the first occurrence of hate changed to love. For example, a possible sample dialogue might be Enter a line of text.I hate you.I have rephrased that line to read:I love you.You can assume that the word hate occurs
Write a program that demonstrates the operator % by performing the following tasks:Use Scanner to read a floating-point value x.Compute x % 2.0 and store the result in y.Display x and y clearly labeled.Type cast x to an int value and store the result in z.Display x, z, and z % 2 clearly labeled.Try
Write a program that will read a line of text as input and then display the line with the first word moved to the end of the line. For example, a possible sample interaction with the user might be Enter a line of text. No punctuation please.Java is the languageI have rephrased that line to
Write a program that asks the user to enter a favorite color, a favorite food, a favorite animal, and the first name of a friend or relative. The program should then print the following two lines, with the user’s input replacing the items in italics:I had a dream that Name ate a Color Animal and
What changes to the ChangeMaker program in Listing 2.3 are necessary if it also accepts coins for one dollar and half a dollar?Listing 2.3 import java.util.Scanner; public class ChangeMaker { public static void main (String[] args) { int amount, originalAmount, quarters, dimes, nickels, pennies;
Write a program that determines the change to be dispensed from a vending machine. An item in the machine can cost between 25 cents and a dollar, in 5 cent increments (25, 30, 35, … , 90, 95, or 100), and the machine accepts only a single dollar bill to pay for the item. For example, a possible
If the int variable × contains 10, what will the following Java statements display?System.out.println("Test 1" + × * 3 * 2.0);System.out.println("Test 2" + × * 3 + 2.0);Given these results, explain why the following Java statement will not compile:System.out.println("Test 3" + × * 3 − 2.0);
Write a program that reads a 4-bit binary number from the keyboard as a string and then converts it into decimal. For example, if the input is 1100, the output should be 12. Break the string into substrings and then convert each substring to a value for a single bit. If the bits are b0, b1, b2, and
Write some Java statements that use the String methods indexOf and substring to find the first word in a string. We define word to be a string of characters that does not include whitespace. For example, the first word of the string"Hello, my good friend!"is the string "Hello,"and the second word
Many private water wells produce only 1 or 2 gallons of water per minute. One way to avoid running out of water with these low-yield wells is to use a holding tank. A family of 4 will use about 250 gallons of water per day. However, there is a “natural” water holding tank in the casing (i.e.,
Repeat the previous exercise, but find the second word in the string.Previous exerciseWrite some Java statements that use the String methods indexOf and substring to find the first word in a string. We define word to be a string of characters that does not include whitespace. For example, the first
Showing 300 - 400
of 407
1
2
3
4
5
Step by Step Answers