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
Ask a Question
Search
Search
Sign In
Register
study help
computer science
java how to program late objects
Questions and Answers of
Java How To Program Late Objects
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
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
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
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
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
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
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
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.”
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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 =
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
(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
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
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
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.
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
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.,
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
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
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
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
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
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)
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,
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
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
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
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
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)
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
Showing 300 - 400
of 421
1
2
3
4
5