2.99 See Answer

Question: Write an application that asks a user


Write an application that asks a user to enter three integers. Display them in ascending and descending order.
Save the file as AscendingAndDescending.java.


> 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

> 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 wi

> 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â&#12

> 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 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

> Write an application that prompts a user for the number of years the user has until retirement and the amount of money the user can save annually. If the user enters 0 or a negative number for either value, reprompt the user until valid entries are made.

> Write an application that includes final constants named START and STOP that are set to 5 and 500, respectively. The application counts by five from 5 through 500 inclusive, and it starts a new line after every multiple of 50 (50, 100, 150, and so on). S

> Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set method for the sale amount, calculate the sales tax as 5 percent

> The Huntington High School basketball team has five players named Ali, Bob, Cai, Dan, and Eli. Accept the number of points scored by each player in a game, and create a bar chart that illustrates the points scored by displaying an asterisk for each point

> Assume that the population of Mexico is 128 million and the population of the United States is 323 million. Accept two values from a user: an assumption of an annual increase in the population of Mexico and an assumption for an annual decrease in the U.S

> Use the Web to locate the lyrics to the traditional song “The Twelve Days of Christmas.” The song contains a list of gifts received for the holiday. The list is cumulative so that as each “day” passes, a new verse contains all the words of the previous v

> In previous chapters, you have created a Rental class for Sunshine Seashore Supplies. The class contains a default constructor as well as an overloaded version that requires a contract number (a letter followed by three digits), a time for the rental (in

> Create a class named Apartment that holds an apartment number, number of bedrooms, number of baths, and rent amount. Create a constructor that accepts values for each data field. Also create a get method for each field. Write an application that creates

> Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, and miles per gallon. Include get and set methods for each field. Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do

> Create a class named JobApplicant that holds data about a job applicant. Include a name, a phone number, and four Boolean fields that represent whether the applicant is skilled in each of the following areas: word processing, spreadsheets, databases, and

> Acme Parts runs a small factory and employs workers who are paid one of three hourly rates depending on their shift: first shift, $17 per hour; second shift, $18.50 per hour; third shift, $22 per hour. Each factory worker might work any number of hours p

> Write an application that uses the LocalDate class to access the current date. Prompt a user for a month, day, and year. Display a message that specifies whether the entered date is (1) not this year, (2) in an earlier month this year, (3) in a later

> Search the Internet for information about how to use a JTextArea, its constructors, and its setText() and append() methods. Write an application that allows the user to select options for a dormitory room. Use JCheckBoxes for options such as private room

> Write an application that allows the user to choose insurance options in JCheckBoxes. Use a ButtonGroup to allow the user to select only one of two insurance types—HMO (health maintenance organization) or PPO (preferred provider organization). Use regula

> Write an application that allows a user to select a country from a list box that contains at least seven options. After the user makes a selection, display the country’s capital city. Save the file as JCapitals.java.

> Design an application for the Sublime Sandwich Shop. The user makes sandwich order choices from list boxes, and the application displays the price. The user can choose from three main sandwich ingredients of your choice (for example, chicken) at three di

> Write an application that allows a user to select one of at least five television shows to watch on demand. When the user selects a show, display a brief synopsis. Save the file as JTVDownload.java. b. Change the JTVDownload application to include an edi

> In previous chapters, you have created an Event class for Yummy Catering. The class contains a default constructor as well as an overloaded constructor that requires an event number (a letter followed by three digits) and a number of guests attending the

> Write an application for Lambert’s Vacation Rentals. Use separate ButtonGroups to allow a client to select one of three locations, the number of bedrooms, and whether meals are included in the rental. Assume that the locations are parkside for $600 per w

> Create an application with a JFrame and at least six labels that contain facts about your favorite topic—for example, the French Revolution or astronomy. Every time the user clicks a JButton, remove one of the labels and add a different one. Save the fil

> Write an application that instantiates a JFrame that contains a JButton. Disable the JButton after the user clicks it. Save the file as JFrameDisableButton.java. b. Modify the JFrameDisableButton program so that the JButton is not disabled until the user

> Create an application for Paula’s Portraits, a photography studio. The application allows users to compute the price of a photography session. Paula’s base price is $40 for an in-studio photo session with one person. The in-studio fee is $75 for a sessio

> Write an application that displays a JFrame containing the opening sentence or two from your favorite book. Save the file as JBookQuote.java. b. Add a button to the frame in the JBookQuote program. When the user clicks the button, display the title of th

> Write a program that prompts a user for two Strings and two integers. Send the two Strings to a generic method that sends them to another method to display, swaps their values, and then sends them to the display method again. Then send the two integers t

> Roberto has purchased buildings that contain apartments to rent. Create an Apartment class that contains fields for the street address, apartment number, monthly rent amount, and number of bedrooms for each Apartment that he owns. Include a constructor t

> Write a program that creates two ArrayLists—one to hold Strings and one to hold Integers. Prompt the user for a word, and while the user does not enter a sentinel value, continue to add each entered word to the ArrayList, sort the list, pass the list to

> Write a program that creates a String ArrayList. Continually prompt the user for Strings to add to the list until a sentinel value is entered. Use an iterator to display all the Strings, then continually ask the user for a String to eliminate until a sen

> Write a program that creates a String ArrayList. Continually prompt the user for Strings to add to the list until the user enters a sentinel value. Display the Strings in a single line separated by commas and ending with a period. Save the file as CommaP

> Sunshine Seashore Supplies rents beach equipment to tourists. In previous chapters, you developed a Rental class that holds equipment rental information, including a contract number and hours and minutes for each Rental. Now write an application that cre

> Write a program that creates an Integer ArrayList and store at least four integers in it. Use an iterator to display all the numbers. Then prompt the user for a value to remove from the list. If the number appears in the list, remove it. Display the list

> Create a Purchase class similar to the one described in a “You Do It” section earlier in this chapter. The Purchase class contains a String category for the purchase (such as groceries) and a numeric price. Include a c

> Loris Manufacturing makes 1,000 products per month and has been increasing production at a rate of 6 percent each month. Write a program that accepts a production goal from the user. If the entered goal is less than 1,000, display a message that indicate

> Assume that the current population of California is 39 million and that the population of Texas is 28 million. The population of Texas appears to be growing at a faster rate than that of California. Write an application that accepts values for the projec

> The Fibonacci sequence is the series of numbers 1, 1, 2, 3, 5, 8, 13, 21, and so on. The last number in the Fibonacci sequence is always the sum of the preceding two numbers. For example, 13 is the sum of 5 and 8, and 21 is the sum of 8 and 13. The seque

> Figure 12-27 shows two typical executions of a program that displays a large V on the screen after the user enters a height. Write a program that passes the following values to a recursive method that produces the V: the current line number, the number o

> Figure 12-26 shows two typical executions of a program that displays a triangle. Create this program by prompting the user for a number of lines to display. The first row of the output contains the number of spaces that equals the number of lines that wi

> Figure 12-20 earlier in this chapter shows the output of a program that displays any number of Os running diagonally from top left to bottom right. Now, write a program that prompts the user for a number of lines to display, and then use a recursive meth

> Write a program that creates an array of at least 20 integers and do the following: ❯ Prompt the user for a starting position, and continually reprompt the user for a new value if the starting position is less than 0 or greater than the highest allowed s

> Write a program that prompts the user for two integers. Pass them to a recursive method that returns the product of the two integers without using multiplication. In other words, instead of using the multiplication operator, write the method using the kn

> Yummy Catering provides meals for parties. In previous chapters, you have created an Event class that holds details for scheduled events, including an event number and number of guests. Now write an application that creates an array of five Event objects

> Write a program that prompts the user for an integer. Pass the integer to a method that determines whether the number is greater than 0; if it is, the method displays the number and passes one less than the parameter value to a second method. The second

> Write a program that prompts a user for two integers and then sums all the values between and including the two integers. Ensure that the second integer entered is larger than the first by continuing to reprompt the user until it is. Then pass the two in

> Write a program that allows you to create a file of customers for a company. The first part of the program should create an empty file suitable for writing a three-digit ID number, six-character last name, and five-digit zip code for each customer. The s

> The Rochester Bank maintains customer records in a random access file. Write an application that creates 10,000 blank records and then allows the user to enter customer account information, including an account number that is 9998 or less, a last name, a

2.99

See Answer