In the children’s game Out of Order, the user is presented with a series of values—for example, A, B, C, E, D, F—and is asked to identify the first item in the list that is out of order. Write a program that stores lists of letters, numbers, and words with one element in each list out of order. The lists do not need to be the same size. Inturn, pass each list to a generic method named display() that displays the list and the instructions for the game. Accept the user’s answer, and then pass the user’s answer and the correct answer to a generic method named checkAnswer() that displays both parameters. Save the program as OutOfOrder.java.
> Each week, the Pickering Trucking Company randomly selects one of its 30 employees to take a drug test. Write an application that determines which employee will be selected each week for the next 52 weeks. Use the Math.random() function explained in Appe
> Write an application that stores nine integers in an array named numbers. Display the integers from first to last, and then display the integers from last to first. Save the file as NineInts.java.
> Write an application that accepts up to 20 Strings, or fewer if the user enters a terminating value. Store each String in one of two lists—one list for short Strings that are 10 characters or fewer and another list for long Strings that are 11 characters
> Write an application that accepts a word from a user and converts it to Pig Latin. If a word starts with a consonant, the Pig Latin version removes all consonants from the beginning of the word and places them at the end, followed by ay. For example, cri
> Three-letter acronyms are common in the business world. For example, in Java you use the IDE (Integrated Development Environment) in the JDK (Java Development Kit) to write programs used by the JVM (Java Virtual Machine) that you might send over a LAN (l
> Write an application that accepts three Strings from the user and, without regard to case, appropriately displays a message that indicates whether the Strings were entered in alphabetical order. Save the file as Alphabetize.java. b. Write an application
> Write an application that counts the words in a String entered by a user. Words are separated by any combination of spaces, periods, commas, semicolons, question marks, exclamation points, or dashes. Figure 7-17 shows a typical execution. Save the file
> Write an application that prompts the user for a password that contains at least two uppercase letters, at least three lowercase letters, and at least one digit. Continually reprompt the user until a valid password is entered. Display a message indicatin
> Create a Card class that holds a suit and value for each Card object. Save the file as Card.java. b. Create an abstract CardGame class similar to the one described in this chapter. The class contains a virtual deck of 52 playing cards that uses a Card cl
> Create a program that contains a String that holds your favorite inspirational quote and display the total number of spaces contained in the String. Save the file as CountSpaces.java. b. Write an application that counts the total number of spaces contain
> Write an application that prompts the user for three first names and concatenates them in every possible two name combination so that new parents can easily compare them to find the most pleasing baby name. Save the file as BabyNameComparison.java.
> Create a TaxReturn class with fields that hold a taxpayer’s Social Security number, last name, first name, street address, city, state, zip code, annual income, marital status, and tax liability. Include a constructor that requires argu
> Write an application that determines whether a phrase entered by the user is a palindrome. A palindrome is a phrase that reads the same backward and forward without regarding capitalization or punctuation. For example, Dot saw I was Tod, Was it a car or
> Write a program that inserts parentheses, a space, and a dash into a String of 10 user-entered numbers to format it as a phone number. For example, 5153458912 becomes (515)345-8912. If the user does not enter exactly 10 digits, display an error message.
> Modify the CharacterInfo class shown in Figure 7-3 so that the tested character is retrieved from user input. Save the file as InputCharacterInfo.java.
> The Freemont Automobile Factory has set a goal that each worker will eventually produce 10,000 parts per month. The company has discovered that the longer a worker has been on the job, the more parts the worker can produce. Write an application that prom
> Write an application that allows a user to enter any number of student quiz scores until the user enters a sentinel 99. If the score entered is less than 0 or greater than 10, display an appropriate message and do not use the score. After all the scores
> Accept a digit from the user, then display a seven-line triangle pattern that uses the digit. Figure 6-33 shows a typical execution. The program can contain no more than three output statements. Save the file as TriangleWithLoops.java.
> Which of the following can be specified by using a parameter in one or more versions of the JTextField constructor? a. the initial text in the field b. requiring that the value entered be nonnumeric c. requiring that the entered value be numeric d. makin
> In previous chapters, you developed classes that hold rental contract information for Sunshine Seashore Supplies. Now modify the Rental class to include an integer field that holds an equipment type. Add a final String array that holds names of the types
> A JFrame is a descendant of each of the following classes except the _________________ class. a. Component b. Container c. Jar d. Window 2. Unlike a Window, a JFrame _________________. a. has a title bar and border b. can be made visible c. can have des
> The method that can be used to sort an ArrayList is _________________. a. Collections.sort() b. ArrayList.sort() c. List.sort() d. Sorting.sort() 12. All of the following classes contain a built-in compareTo() method except _________________. a. Integer
> In programming, a(n) _________________ is a group of objects that can be operated on together. a. collision b. anthology c. assemblage d. collection 2. A difference between a collection and an array is that a collection _________________. a. can hold re
> In a recursive method, there typically are _________________. a. more base cases than if statements b. more recursive cases than base cases c. more base cases than while loops d. more base cases than recursive cases 12. The case in a recursive method th
> Recursion is a(n) _________________. a. problem-solving method b. iterative technique c. object-oriented technique d. set of standards 2. Recursion is often used when a problem’s solution relies on a _________________. a. more complicated solution to th
> If you fail to close an output file, _________________. a. there are usually no serious consequences b. you might lose access to the written data c. Java will close it for you automatically d. it becomes an input file 12. Which of the following is true
> Which of the following statements is true? a. Volatile storage lasts only a few seconds. b. Volatile storage is lost when a computer loses power. c. Computer disks are volatile storage devices. d. Volatile storage is also known as persistent storage. 2.
> When a try block does not generate an Exception and you have included multiple catch blocks,_________________. a. no catch blocks execute b. only the first catch block executes c. only the first matching catch block executes d. all the catch blocks execu
> In object-oriented programming terminology, an unexpected or error condition is a(n) _________________. a. anomaly b. exception c. deviation d. aberration 2. All Java Exceptions are _________________. a. Errors b. Omissions c. Throwables d. RunTimeExcep
> When a parent class contains a static method, child classes _________________ override it. a. frequently b. seldom c. must d. cannot 12. Abstract classes differ from other classes in that you _________________. a. must not code any methods within them b
> In previous chapters, you developed classes that work with catering event information for Yummy Catering. Now modify the Event class to include an integer field that holds an event type. Add a final String array that holds names of the types of events th
> Employing inheritance reduces errors because _________________. a. subclasses have access to fewer data fields b. subclasses have access to fewer methods c. methods that have been created in the superclass can be copied and pasted into the subclass d. ma
> A parallel array is one that _________________. a. holds values that correspond to those in another array b. holds an even number of values c. is placed adjacent to another array in code d. is placed adjacent to another array in memory 12. When you pass
> An array is a list of data items that all _________________. a. have the same type b. have different names c. are integers d. are null 2. When you declare an array, _________________. a. you always reserve memory for it in the same statement b. you migh
> If String movie = new String("Finding Dory");, the value of movie.indexOf('i') is _________________. a. true b. false c. 1 d. 2 12. The String class replace() method replaces _________________. a. a String with a character b. one String with another Str
> A sequence of characters enclosed within double quotation marks is a _________________. a. literal string b. symbolic string c. prompt d. command 2. To create a String object, you can use the keyword _________________ before the constructor call, but yo
> 11. If m = 9, then after n = m++, the value of n is ____________. a. 8 b. 9 c. 10 d. 11 12. If j = 5 and k = 6, then the value of j++ == k is ____________. a. 5 b. 6 c. true d. false 13. You must always include ____________ in a for loop’s parentheses.
> 1. A structure that allows repeated execution of a block of statements is a ____________. a. cycle b. ring c. loop d. band 2. A loop that never ends is a(n) ____________ loop. a. infinite b. iterative c. structured d. illegal 3. To construct a loop tha
> The operator that combines two conditions into a single Boolean value that is true only when both of the conditions are true is ____________. a. $$ b. && c. || d. !! 12. The operator that combines two conditions into a single Boolean value that is true
> The logical structure in which one instruction occurs after another with no branching is a ____________. a. sequence b. selection c. loop d. case 2. Which of the following is typically used in a flowchart to indicate a decision? a. square b. rectangle c
> Sunshine Seashore Supplies rents beach equipment to tourists. In previous chapters, you developed a Rental class that holds equipment rental information and an application that tests the methods using three objects of the class. Now create a RentalDemo c
> a. Sunshine Seashore Supplies rents beach equipment to tourists. In previous chapters, you have developed a Rental class that holds equipment rental information. Now modify the Rental class as follows: ❯❯ Modify the method that sets the contract number i
> Create a Die class from which you can instantiate an object containing a random value from 1 through 6. Save the class as Die.java. Write an application that randomly “throws” two dice and displays their values. Determine whether the two dice are the sam
> Design a Card class that contains a character data field to hold a suit (s for spades, h for hearts, d for diamonds, or c for clubs) and an integer data field for a value from 1 to 13. Include a setValue() method that does not allow a Card’s value to be
> Create a lottery game application. Generate three random numbers (see Appendix D for help in doing so), each between 0 and 9. Allow the user to guess three numbers. Compare each of the user’s guesses to the three random numbers and display a message that
> Create a class called RandomGuess2 that contains a game in which a player guesses a random number. (See Appendix D for help with creating a random number.) Allow a player to enter a guess, and then display a message indicating whether the player’s guess
> Create a game called Last Man Standing in which the objective is to select the last remaining JCheckBox. The game contains 10 JCheckBoxes. The player can choose one, two, or three boxes, and then click a JButton to indicate the turn is complete. The comp
> Create a lottery game that uses check boxes. For this game, generate six random numbers, each between 0 and 30 inclusive. Allow the user to choose six check boxes to play the game. (Do not allow the user to choose more than six boxes.) After the player h
> Create a quiz game that displays, in turn, five questions about any topic of your choice. All five questions should have the same three possible multiple-choice answers. For example, you might ask trivia questions about U.S. states for which the correct
> Tower of Hanoi is a pyramid puzzle that uses three rods and a number of disks that have different diameters. The disks can slide onto any rod. The puzzle starts with the disks on the first rod, stacked from the smallest at the top to the largest on the b
> Scrabble and Words with Friends are games in which players score points by placing letters on a game board divided into squares. After the first word is placed on the board, subsequent plays must form words that intersect with other letters already in pl
> Yummy Catering provides meals for parties and special events. In previous chapters, you developed a class named Event that holds catering event information. Now create an EventDemo application to do the following: ❯❯ Create three Event objects. ❯❯ Contin
> Use a text editor to create a comma-delimited file of user IDs and passwords. Save the file as GamePlayers.txt. b. Revise any one of the games you have created throughout this course to use the file GamePlayers.txt. Require the user to enter a correct ID
> Create a multiple-choice quiz on any topic. Include at least 10 questions. Store the player’s highest score from any previous game in a file, and display the previous high score at the start of each new game. (The first time you play the game, the previo
> In several Game Zone assignments earlier in this course, you created games similar to Hangman in which the user guesses a secret phrase by selecting a series of letters. These versions had limited appeal because each contained only a few possible phrases
> Create a class that contains an array of 10 multiple-choice questions to which the user is required to respond with an A, B, or C. Display an error message if the user enters a character other than A, B, or C. If the user enters nothing—that is, if the u
> Create an application that generates a random integer for a player to guess. When the player’s guess is not entered as an integer, catch the Exception that is thrown and allow the player to try again. When the guess is an integer that is too high or too
> Create a Card class that holds a suit and value for each Card object. Save the file as Card.java. b. Create an abstract CardGame class similar to the one described in this chapter. The class contains a virtual deck of 52 playing cards that uses a Card cl
> Create an abstract Alien class. Include at least three protected data members of your choice, such as the number of eyes the Alien has. Include a constructor that requires a value for each data field and a toString() method that returns a String containi
> Create a Die class that you can use to instantiate objects that each hold a value from 1 through 6. The field that holds the value of the Die should be protected, which will allow a child class to access the value. Save the file as Die.java. b. Create a
> Create a Tic Tac Toe game. In this game, two players alternate placing Xs and Os into a grid until one player has three matching symbols in a row, horizontally, vertically, or diagonally. Create a game in which the user is presented with a three-by-three
> Create a guessing game called “Does It Have Legs?”, in which you think of an animal and the computer tries to guess what it is. The game continually becomes “smarter” as you play because you teach it how to become more specific with its questions. For ex
> a. Sunshine Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists. In Chapter 4, you created a Rental class for the company. Now, make the following change to the class: ❯❯ Currently, a rental price is ca
> Magic 8 Ball is a toy developed in the 1950s and used for fortune-telling or advice-seeking. A player asks or thinks of a yes-or-no question such as Will I be rich someday? The player then turns the ball over to see one of 20 randomly chosen responses—fo
> Create a Secret Phrase game similar to Hangman, in which the user guesses letters in a partially hidden phrase in an attempt to determine the complete phrase. Within the program: ❯❯ The phrase to be guessed is selected randomly from a list of at least 10
> Create a Card class so that each Card holds the name of a suit (Spades, Hearts, Diamonds, or Clubs) as well as a value (Ace, King, Queen, Jack, or a number value). Save the file as Card.java. b. Create an array of 52 Card objects, assigning a different v
> Create a Die class whose constructor sets a value from 1 to 6. Include a method to return the value. Save the file as Die.java. Create an application that randomly “throws” five dice for the computer and five dice for
> Write an application that contains an array of 10 multiple-choice quiz questions related to your favorite hobby. Each question contains three answer choices. Also create an array that holds the correct answer to each question—A, B, or C. Display each que
> Eliza is a famous 1966 computer program written by Joseph Weizenbaum. It imitates a psychologist (more specifically, a Rogerian therapist) by rephrasing many of a patient’s statements as questions and posing them to the patient. This type of therapy (som
> Create a simple guessing game, similar to Hangman, in which the user guesses letters and then attempts to guess a partially hidden phrase. Display a phrase in which some of the letters are replaced by asterisks: for example, G* T*** (for Go Team). Each t
> Create a Rock Paper Scissors game in which the user enters a string rock, paper, or scissors. Allow the choice to be valid whether the player enters a choice in uppercase letters, lowercase letters, or a combination of the two. To allow for player misspe
> Design a Card class. The class holds fields that contain a Card’s value and a suit that is one of the four strings Spades, Hearts, Diamonds, or Clubs. Also, add a field to the class to hold the String representation of a Cardâ
> Two people play the game of Count 21 by taking turns entering a 1, 2, or 3, which is added to a running total. The player who adds the value that makes the total reach or exceed 21 loses the game. Create a game of Count 21 in which a player competes agai
> a. Yummy Catering provides meals for parties and special events. In Chapter 4, you created an Event class for the company. Now, make the following changes to the class: ❯❯ Currently, the class contains a constant for the price per guest ($35) that is use
> a. Create a Die class from which you can instantiate an object containing a random value from 1 through 6. The constructor sets the value. Include a method to return the value. Save the file as Die.java. b. Use the Die class to create a simple dice game
> Many games use coin tosses, particularly to determine events such as which player takes the first turn in a game. When you toss one coin, the probability of getting “heads” is 50 percent. When you toss two coins, the probability of getting exactly one “h
> Create a game that generates a random number from 1 to 10. Include a loop that continually prompts the user for the number, indicating whether the guess is high or low, until the user enters the correct value. After the user correctly guesses the number,
> Write an application that creates a quiz. The quiz should contain at least five questions about a hobby, popular music, astronomy, or any other personal interest. Each question should be a multiple-choice question with at least four answer options. When
> In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows:
> Each of the following files in the Chapter08 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded
> Each of the following files in the Chapter07 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the application. After you correct the errors, save each file using the same filename prece
> Each of the following files in the Chapter06 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded
> Each of the following files in the Chapter05 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded
> Each of the following files in the Chapter14 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded
> In previous chapters, you have created a number of programs for Sunshine Seashore Supplies. Now, create an interactive GUI program that allows the user to enter a rental time in hours into a text field; if the value entered is not numeric, set the rental
> Each of the following files in the Chapter13 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded
> Each of the following files in the Chapter12 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the errors. After you correct the errors, save each file using the same filename preceded w
> Each of the following files in the Chapter11 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded
> Each of the following files in the Chapter10 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded
> Each of the following files in the Chapter09 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded
> Write a program for Horizon Phones, a provider of cellular phone service. Prompt a user for maximum monthly values for talk minutes needed, text messages needed, and gigabytes of data needed, and then display a recommendation for the best plan for the c
> Write an application for the Shady Rest Hotel; the program determines the price of a room. Ask the user to choose 1 for a queen bed, 2 for a king, or 3 for a king and a pullout couch. The output echoes the input and displays the price of the room: $125 f
> Write an application that asks a user to enter three integers. Display them in ascending and descending order. Save the file as AscendingAndDescending.java.
> Write an application that asks a user to enter an integer. Pass the integer to a method that determines whether the number is even and returns a Boolean value. Display a statement that indicates whether the integer is even or odd. Save the file as EvenOd
> Write an application that prompts the user for a single-digit integer and uses a loop to create the pattern shown in the example in Figure 6-32. In the example, the user entered a 3, and 10 lines are displayed; each 3 appears one additional space to the
> In previous chapters, you have created a number of programs for Yummy Catering. Now, create an interactive GUI program that allows the user to enter the number of guests for an event into a text field; if the value entered is not numeric, set the event p
> Write an application that displays every perfect number from 1 through a user-supplied limit. A perfect number is one that equals the sum of all the numbers that divide evenly into it. For example, 6 is perfect because 1, 2, and 3 divide evenly into it,
> Write an application that prompts a user for two integers and displays every integer between them. Display a message if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger. Save the fi
> Write an application that displays the factorial for every integer value from 1 to a user-entered limit. A factorial of a number is the product of that number multiplied by each positive integer lower than it. For example, 4 factorial is 4 * 3 * 2 * 1, o
> Write an application that asks a user to type an even number or the sentinel value 999 to stop. When the user types an even number, display the message Good job! and then ask for another input. When the user types an odd number, display an error message