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 how to program late objects
Java How To Program Late Objects Version 8th Edition Paul Deitel, Deitel & Associates - Solutions
Write methods that accomplish each of the following tasks:a) Check whether the string is terminated by a full stop, and if not, add a full stop.b) Check whether the string starts with a capital letter, and if not, capitalize the first letter.c) Use the methods developed in parts (a) and
Implement the following integer methods:a) Method Kelvin returns the Kelvin equivalent of a Celsius temperature, using the calculation Kelvin = Celsius + 273.15;b) Method Celsius returns the Celsius equivalent of a Kelvin temperature, using the calculation Celsius = Kelvin - 273.15;c) Use the
A positive integer is a palindrome if its value is the same after reversing the order of the digits in the number. For example, 12321 is a palindrome, but 12563 is not. Write a method that determines whether a number is a palindrome. Use this method in an application that determines whether a
An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number, because 6 = 1 + 2 + 3. Write a method isPerfect that determines whether parameter number is a perfect number. Use this method in an
A positive integer is prime if it’s divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. The number 1, by definition, is not prime.a) Write a method that determines whether a number is prime.b) Use this method in an application that determines and
Write a method that takes a four-digit integer value and returns the sum of the digits. For example, given the number 7631, the method should return 17. Incorporate the method into an application that reads a value from the user and displays the result.
The greatest common divisor (GCD) of two integers is the largest integer that evenly divides each of the two numbers. Write a method gcd that returns the greatest common divisor of two integers. You might want to use Euclid’s algorithm. You can find information about it at
Write a method sportsRecommender that inputs a Celsius temperature and returns “It’s lovely weather for sports today!” if it’s 20–30 °C, “It’s reasonable weather for sports today.” if it’s 10–40 °C, and “Please exercise with care today, watch out for the weather!”
Write an application that simulates coin tossing. Let the program toss a coin each time the user chooses the “Toss Coin” menu option. Count the number of times each side of the coin appears. Display the results. The program should call a separate method flip that takes no arguments and returns
Write an application that plays “guess the number” as follows: Your program chooses the number to be guessed by selecting a random integer in the range 1 to 1000. The application displays the prompt Guess a number between 1 and 1000. The player inputs a first guess. If the player's guess is
Modify the program of Exercise 5.30 to count the number of guesses the player makes. If the number is 10 or fewer, display Either you know the secret or you got lucky! If the player guesses the number in 10 tries, display Aha! You know the secret! If the player makes more than 10 guesses, display
Write method distance to calculate the distance between two points (x1, y1) and (x2, y2). All numbers and return values should be of type double. Incorporate this method into an application that enables the user to enter the coordinates of the points.
Modify the craps program of Fig. 5.8 to allow wagering. Initialize variable bankBalance to 1000 dollars. Prompt the player to enter a wager. Check that wager is less than or equal to bankBalance, and if it’s not, have the user reenter wager until a valid wager is entered. Then, run one game of
Write an application that displays a table of the binary, octal and hexadecimal equivalents of the decimal numbers in the range 1 through 256. If you aren’t familiar with these number systems.
The use of computers in education is referred to as computer-assisted instruction (CAI). Write a program that will help an elementary school student learn multiplication. Use a SecureRandom object to produce two positive one-digit integers. The program should then prompt the user with a question,
One problem in CAI environments is student fatigue. This can be reduced by varying the computer’s responses to hold the student’s attention. Modify the program of Exercise 5.35 so that various comments are displayed for each answer as follows:Possible responses to a correct answer:Very
More sophisticated computer-assisted instruction systems monitor the student’s performance over a period of time. The decision to begin a new topic is often based on the student’s success with previous topics. Modify the program of Exercise 5.36 to count the number of correct and incorrect
Exercises 5.35 5.37 developed a computer-assisted instruction program to help teach an elementary school student multiplication. Modify the program to allow the user to enter a difficulty level. At a difficulty level of 1, the program should use only single-digit numbers in the problems; at a
Modify the program of Exercise 5.38 to allow the user to pick a type of arithmetic problem to study. An option of 1 means addition problems only, 2 means subtraction problems only, 3 means multiplication problems only, 4 means division problems only and 5 means a random mixture of all these
Write Java statements to accomplish each of the following tasks:a) Display the value of the tenth element of array r.b) Initialize each of the six elements of one-dimensional integer array g to -1.c) Find the maximum of the first one-hundred elements of floating-point array c.d) Copy a
Use a one-dimensional array to solve the following problem: You want to eventually perform some basic compression on an image. Assume that you will only be operating on a single row of the image, and that pixel colors are represented as simple numbers in the array. You are required to quantize the
Write statements that perform the following one-dimensional-array operations:a) Set elements of index 10–20, both inclusive, of integer array counts to zero.b) Multiply each of the twenty elements of integer array bonus by 2.c) Display the ten values of integer array bestScores, each on a new
Use a one-dimensional array to solve the following problem: Write an application that inputs ten numbers, each between 10 and 100, both inclusive. Save each number that was read in an array that was initialized to a value of –1 for all elements. Assume a value of –1 indicates an array element
Label the elements of a five-by-six two-dimensional array table to indicate the order in which they’re set to zero by the following program segment:for (int col = 0; col < 6; col++){for (int row = 0; row < 5; row++){table[row][col] = 0;}}
Write an application that calculates the average of a series of integers that are passed to method average using a variable-length argument list. Test your method with several calls, each with a different number of arguments.
Write a program that takes command-line arguments and computes the average of their maximum and minimum. Make sure there are command-line arguments being passed before you attempt to compute anything.
Write an application that uses an enhanced for statement to find the absolute values of int numbers passed by command-line arguments.
Write an application to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values
Write an application that runs 1,000,000 games of craps (Fig. 5.8) and answers the following questions:a) How many games are won on the first roll, second roll, …, twentieth roll and after the twentieth roll?b) How many games are lost on the first roll, second roll, …, twentieth roll and
A small airline has just purchased a computer for its new automated reservations system. You’ve been asked to develop the new system. You’re to write an application to assign seats on each flight of the airline’s only plane (capacity: 10 seats).Your application should display the following
A group of four friends visit a sports club and they decide to practice archery. Each player gets 3 chances and in every chance they can score between 0 to 10 points. The player with the maximum score after adding the scores obtained in all 3 chances wins.Write an application that simulates this
The Logo language made the concept of turtle graphics famous. Imagine a mechanical turtle that walks around the room under the control of a Java application. The turtle holds a pen in one of two positions, up or down. While the pen is down, the turtle traces out shapes as it moves, and while the
An interesting puzzler for chess buffs is the Knight’s Tour problem, originally proposed by the mathematician Euler. Can the knight piece move around an empty chessboard and touch each of the 64 squares once and only once? We study this intriguing problem in depth here.The knight makes only
In part (c) of Exercise 6.22, we developed a solution to the Knight’s Tour problem. The approach used, called the “accessibility heuristic,” generates many solutions and executes efficiently.As computers continue to increase in power, we’ll be able to solve more problems with sheer
In this exercise, you’ll develop several brute-force approaches to solving the Eight Queens problem introduced in Exercise 6.24.a) Use the random brute-force technique developed in Exercise 6.23 to solve the Eight Queens problem.b) Use an exhaustive technique (i.e., try all possible
A prime number is any integer greater than 1 that’s evenly divisible only by itself and 1. The Sieve of Eratosthenes is a method of finding prime numbers. It operates as follows:a) Create a primitive-type boolean array with all elements initialized to true. Array elements with prime indices
In this problem, you’ll re-create the classic race of the tortoise and the hare. You’ll use random-number generation to develop a simulation of this memorable event.Our contenders begin the race at square 1 of 70 squares. Each square represents a possible position along the race course. The
The Fibonacci series 0, 1, 1, 2, 3, 5, 8, 13, 21, … begins with the terms 0 and 1 and has the property that each succeeding term is the sum of the two preceding terms.a) Write a method fibonacci(n) that calculates the nth Fibonacci number. Incorporate this method into an application that enables
The Internet and the web are enabling more people to network, join a cause, voice opinions, and so on. Recent presidential candidates have used the Internet intensively to get out their messages and raise money for their campaigns. In this exercise, you’ll write a simple polling program that
Fill in the blanks in each of the following:a) Each class declaration that begins with keyword _________ must be stored in a file that has exactly the same name as the class and ends with the .java filename extension.b) Keyword _________ in a class declaration is followed immediately by the
State whether each of the following is true or false. If false, explain why.a) An import declaration is not required when one class in a package uses another in the same package.b) Variables declared in the body of a particular method are known as instance variables and can be used in all methods
Modify class Account (Fig. 7.8) to provide a method called withdraw that withdraws money from an Account. Ensure that the withdrawal amount does not exceed the Account’s balance. If it does, the balance should be left unchanged and the method should print a message indicating "Withdrawal amount
(Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables—a part number (type String), a part description (type String), a quantity of the item
Create a class called Car that includes three instance variables—a model (type String), a year (type String), and a price (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the price is not positive, do not
Create a class called Clock that includes three instance variables—an hour (type int), a minute (type int) and a second (type int). Provide a constructor that initializes the three instance variables and assumes that the values provided are correct. Provide a set and a get method for each
In the AccountTest class of Fig.7.9, method main contains six statements (lines 11–12, 13–14, 26–27, 28–29, 38–39 and 40–41) that each display an Account object’s name and balance. Study these statements and you’ll notice that they differ only in the Account object being
Modify the GradeBook class of Fig.7.16 so that the constructor accepts as parameters the number of students and the number of exams, then builds an appropriately sized two-dimensional array, rather than receiving a preinitialized two-dimensional array as it does now. Set each element of the new
Modify Fig.7.13 to deal a five-card poker hand. Then modify class DeckOfCards of Fig.7.12 to include methods that determine whether a hand containsa) A pairb) Two pairsc) Three of a kind (e.g., three jacks)d) Four of a kind (e.g., four aces)e) A flush (i.e., all five cards of the same
Use the methods developed in Exercise 7.16 to write an application that deals two five-card poker hands, evaluates each hand and determines which is better.Exercise 7.16Modify Fig.7.13 to deal a five-card poker hand. Then modify class DeckOfCards of Fig.7.12 to include methods that determine
Modify the application developed in Exercise 7.17 so that it can simulate the dealer. The dealer’s five-card hand is dealt “face down,” so the player cannot see it. The application should then evaluate the dealer’s hand, and, based on the quality of the hand, the dealer should draw one, two
Modify the application developed in Exercise 7.18 so that it can handle the dealer’s hand automatically, but the player is allowed to decide which cards of the player’s hand to replace. The application should then evaluate both hands and determine who wins. Now use this new application to play
Modify the application of Figs. 7.11–7.13 to use Face and Suit enum types to represent the faces and suits of the cards. Declare each of these enum types as a public type in its own source-code file. Each Card should have a Face and a Suit instance variable. These should be initialized by the
Research the Fisher-Yates shuffling algorithm online, then use it to reimplement the shuffle method in Fig.7.12.Fig.7.12 I // Fig. 7.12: DeckOfCards.java 2 // DeckOfCards class represents a deck of playing cards. 3 import java.security.SecureRandom; 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
While exercising, you can use a heart-rate monitor to see that your heart rate stays within a safe range suggested by your trainers and doctors. According to the American Heart Association (AHA) (http://bit.ly/TargetHeartRates), the formula for calculating your maximum heart rate in beats per
A health-care issue that has been in the news lately is the computerization of health records. This possibility is being approached cautiously because of sensitive privacy and security concerns, among others.Computerizing health records could make it easier for patients to share their health
Write an application that inputs one number consisting of five digits from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each. For example, if the user types in the number 42339, the program should printAssume that the
Write a Java statement to accomplish each of the following tasks:a) Declare variable sum of type int and initialize it to 0.b) Declare variable x of type int and initialize it to 1.c) Add variable x to variable sum, and assign the result to variable sum.d) Print "The sum is: ", followed by the
Combine the statements that you wrote in Exercise 3.5 into a Java application that calculates and prints the sum of the integers from 1 to 10.Use a while statement to loop through the calculation and increment statements. The loop should terminate when the value of x becomes 11. Exercise 3.5Write
What type of repetition would be appropriate for obtaining an input from the user until the user indicates there is no more input to provide? What type would be appropriate for calculating the factorial of 5? Briefly describe how each of these tasks could be performed.
If integers x and y are set to 7 and 3, what is the value of x after x = y++ and x = ++y?
Identify and correct the errors in each of the following pieces of code.a) if (age >= 65);System.out.println("Age is greater than or equal to 65");else System.out.println("Age is less than 65)";b) int x == 1, total == 0;while (x
Drivers are concerned with the mileage their automobiles get. One driver has kept track of several trips by recording the miles driven and gallons used for each tankful. Develop a Java application that will input the miles driven and gallons used (both as integers) for each trip. The program should
Develop a Java application that determines whether any of several department-store customers has exceeded the credit limit on a charge account. For each customer, the following facts are available:a) Account numberb) Balance at the beginning of the monthc) Total of all items charged by the
A large company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5,000 worth of merchandise in a week receives $200 plus 9% of $5,000, ora total of $650. You’ve been supplied with a
Develop a Java application that determines the total tax for each of three citizens. The tax rate is 15% for earnings up to 30,000 USD earned by each citizen and 20% for all earnings in excess of that ceiling. You are given a list with the citizens’ names and their earnings in a given year. Your
The process of finding the largest value is used frequently in computer applications. For example, a program that determines the winner of a sales contest would input the number of units sold by each salesperson. The salesperson who sells the most units wins the contest. Write a pseudocode program,
Write a Java application that uses looping to print the following table of values: N 12445 3 N 1 4 9 16 25 N 1 8 27 64 125 N4 1 16 81 256 625
Modify the program in Fig. 3.10 to validate its inputs. For any input, if the value entered is other than 1 or 2, keep looping until the user enters a correct value.Fig. 3.10 Enter result (1= Enter result (1 = Enter result (1 Enter result (1 Enter result (1 Enter result (1 Enter result (1 Enter
The Java compiler always associates an else with the immediately preceding if unless told to do otherwise by the placement of braces ({ and }). This behavior can lead to what is referred to as the dangling-else problem. The indentation of the nested statement 5". Otherwise, it appears that if x is
Based on the dangling-else discussion in Exercise 3.27, state the output for each of the following code segments when x is 9 and y is 11 and when x is 11 and y is 9. We eliminated the indentation from the following code to make the problem more challenging.a)b)Exercise 3.27The Java compiler always
Based on the dangling-else discussion in Exercise 3.27, modify the following code to produce the output shown. Use proper indentation techniques. You must not make any additional changes other than inserting braces and changing the code’s indentation. We’ve eliminated the indentation from the
Write an application that prompts the user to enter the length of the base of a triangle, and uses that to draw a right-angled triangle composed of asterisks. Your program should work for triangles of base lengths between 1 and 10.
A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it’s a palindrome. If the number
Write an application that inputs an integer containing only 0s and 1s (i.e., a binary integer) and prints its decimal equivalent. Use the remainder and division operators to pick off the binary number’s digits one at a time, from right to left. In the decimal number system, the rightmost digit
Write an application that uses only the output statementsto display the checkerboard pattern that follows. A System.out.println method call with no arguments causes the program to output a single newline character. I System.out.print("* "); 2 System.out.print(" "); 3 System.out.println();
Write an application that asks for a number from the user and then keeps reading integer values from the user until the sum of those integers equals or becomes greater than the value that was input in the beginning.
What will be the value of x after executing the following java statement?Assume that value of x is 5 before the execution.x += x++ - 5;
Write an application that works as a comparator. Your program should read two numbers from the user and print 0 if they are equal to each other, 1 if the first number is greater, and –1 if the second number is greater.
Write an application that reads the x and y coordinates of two points on a plane and prints whether the points are located on a line perpendicular to an axis.
The factorial of a nonnegative integer n is written as n! (pronounced “n factorial”) and is defined for values of n greater than or equal to 1 as:n! = n · (n – 1) · (n – 2) · … · 1 and for the n value 0 as:n! = 1 For example, 5! = 5 · 4 · 3 · 2 · 1, which is 120.a) Write an
The explosive growth of Internet communications and data storage on Internet-connected computers has greatly increased privacy concerns. The field of cryptography is concerned with coding data to make it difficult (and hopefully—with the most advanced schemes—impossible) for unauthorized users
World population has grown considerably over the centuries. Continued growth could eventually challenge the limits of breathable air, drinkable water, arable cropland and other limited resources. There’s evidence that growth has been slowing in recent years and that world population could peak
If you need to execute the body of a loop at least once, would it be better to use a do…while statement or a while statement?
What does the following program do?
Modify the compound-interest application of Fig. 4.6 to repeat its steps for interest rates of 5%, 6%, 7%, 8%, 9% and 10%. Use a for loop to vary the interest rate.Fig. 4.6
Write an application that displays the following patterns separately, one below the other. Use for loops to generate the patterns. All asterisks (*) should be printed by a single statement of the form System.out.print('*'); which causes the asterisks to print side by side. A statement of the form
One interesting application of computers is to display graphs and bar charts. Write an application that reads five numbers between 1 and 30. For each number that’s read, your program should display the same number of adjacent asterisks. For example, if your program reads the number 7, it should
A group of five students earned the following grades: Student 1, ‘A’; student 2, ‘C’; student 3,‘B’; student 4, ‘A’and student 5, ‘B’. Write an application that reads a series of pairs of numbers as follows:a) Student name b) Student letter grade.Your program should use a
Modify the compound-interest application of Fig. 4.6 to repeat its steps for interest rates of 5%, 6%, 7%, 8%, 9% and 10%. Use a for loop to vary the interest rate.Fig. 4.6
Assume that i = 2, j = 3, k = 2 and m = 2. What does each of the following statements print?a) System.out.println(i == 2);b) System.out.println(j == 5);c) System.out.println((i >= 0) && (j j));
A right triangle can have sides whose lengths are all integers. The set of three integer values for the lengths of the sides of a right triangle is called a Pythagorean triple. The lengths of the three sides must satisfy the relationship that the sum of the squares of two of the sides is equal to
Modify Exercise 4.15 to combine your code from the four separate triangles of asterisks such that all four patterns print side by side. Make clever use of nested for loops.Exercise 4.15Write an application that displays the following patterns separately, one below the other. Use for loops to
Modify the application in Fig. 4.6 to use only integers to calculate the compound interest. Treat all monetary amounts as integral numbers of pennies. Then break the result into its dollars and cents portions by using the division and remainder operations, respectively. Insert a period between the
Write an application that prints the following two dimensional matrix. Use for loops to minimize the number of output statements. 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 55555
Fill in the blanks in each of the following statements:a) _________ is a platform independent programming language that was built with the objective of allowing programs to be written once and then run on a large variety of electronic devices without modification.b) _________, _________,
Explain what a just-in-time (JIT) compiler of Java does.
Some scientists believe that carbon emissions,especially from the burning of fossil fuels, contribute significantly to global warming and that this can be combated if individuals take steps to limit their use of carbon-based fuels. Various organizations and individuals are increasingly concerned
Fill in the blanks in each of the following statements:a) _______ are used to document a program and improve its readability.b) A decision can be made in a Java program with a(n) _________.c) The arithmetic operators with the same precedence as multiplication are and _________.d) When
Write Java statements that accomplish each of the following tasks:a) Display the message "Enter an integer: ", leaving the cursor on the same line.b) Assign the product of variables b and c to the int variable a.c) Use a comment to state that a program performs a sample payroll calculation.
State whether each of the following is true or false. If false, explain why.a) Addition is executed first in the following expression: a * b / (c + d) * 5.b) The following are all valid variable names: AccountValue, $value, value_in_$, account_no_1234, US$, her_sales_in_$, his_$checking_account,
Showing 300 - 400
of 421
1
2
3
4
5
Step by Step Answers