EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 5, Problem 3GZ
Program Plan Intro
Card game
Program plan:
- In a file “Card.java”, create a class “Card”,
- Declare and initialize the necessary variables.
- Define the method “get_Suit()” to return the suit value.
- Define the method “get_Value()” to return the value.
- Define the method “set_Suit()” to set the suit value.
- Define the method “set_Value()”,
- Check whether the value is greater than or equal to low and less than or equal to high value,
- If it is true, set the given integer as the value.
- Otherwise,
- Set the lowest value.
- Check whether the value is greater than or equal to low and less than or equal to high value,
- In a file “War.java”, create a class “War”,
- Define the method “main ()”,
- Declare and initialize the necessary variables.
- Create two objects for “Card” class.
- Generate the random value for the player.
- Generate the random value for the computer.
- Set the value for the player and the computer.
- Generate the random suit for the player and the computer.
- Check whether the random value and the suite value of the player is same as that of computer,
- If it is true, increment the computer’s suit value by “1”.
- Check whether the computer’s suit value is greater than the highest value,
- Set the computer’s suit value to “1”.
- Check whether the player’s suit is “1”,
- If it is true, call the method “set_Suit()” with “s” as the parameter.
- Otherwise, check whether the player’s suit is “2”,
- If it is true, call the method “set_Suit()” with “h” as the parameter.
- Otherwise, check whether the player’s suit is “3”,
- If it is true, call the method “set_Suit()” with “d” as the parameter.
- Otherwise,
- Call the method “set_Suit()” with “c” as the parameter.
- Check whether the computer’s suit value is “1”,
- If it is true, call the method “set_Suit()” with “s” as the parameter.
- Otherwise, check whether the computer’s suit is “2”,
- If it is true, call the method “set_Suit()” with “h” as the parameter.
- Otherwise, check whether the computer’s suit is “3”,
- If it is true, call the method “set_Suit()” with “d” as the parameter.
- Otherwise,
- Call the method “set_Suit()” with “c” as the parameter.
- Print the messages in the console.
- Check whether the player’s value is same as the computer’s value,
- If it is true, print the string “It’s a tie”.
- Otherwise, check whether the player’s value is greater than the computer’s value,
- If it is true, print the string “I win”.
- Otherwise, print the string “You win”.
- Define the method “main ()”,
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write code that creates a Random object and then assigns a random integer in the range of 100 through 399 to the variable randomNumber.
In Chapter 4, you created a Die application that randomly “throws” five dice for the computer and five dice for the player. The application displays the values. Modify the application to decide the winner based on the following hierarchy of Die values. Any higher combination beats a lower one—for example, five of a kind beats four of a kind.
Five of a kind
Four of a kind
Three of a kind
A pair
For this game, the dice values do not count; for example, if both players have three of a kind, it’s a tie, no matter what the values of the three dice are. Additionally, the game does not recognize other poker hand type combinations such as a full house (three of a kind plus two of a kind) or a straight (sequential values). Figure 8-21 shows a sample execution. Save the application as FiveDice2.java.
Improve the FiveDice2 game so that when both players have the same combination of dice, the higher value wins. For example, two 6s beats two 5s. Save the application as FiveDice3.java.
__eq__(self, other):
Method that returns True if self and other are considered the same Flight: if the origin and destination are the same for both Flights. Make sure that if “other” variable is not a Flight object, this means False should be returned.
getFlightNumber(self):
Getter that returns the Flight number
getStart(self):
Getter that returns the Plane Start
getgoingTo(self):
Getter that returns the Plane destination
isDomesticFlight(self):
Method that returns True if the flight is domestic, EX within a country (the Start and goingTo are in the same country); returns False if the flight is international (the Start and goingTo are in different countries)
setStart(self, origin):
Setter that sets (updates) the Plane Start
setgoingTo(self, destination):
Setter that sets (updates) the Plane GoingTo
Chapter 5 Solutions
EBK JAVA PROGRAMMING
Ch. 5 - Prob. 1RQCh. 5 - Prob. 2RQCh. 5 - Prob. 3RQCh. 5 - Prob. 4RQCh. 5 - Prob. 5RQCh. 5 - Prob. 6RQCh. 5 - Prob. 7RQCh. 5 - Prob. 8RQCh. 5 - Prob. 9RQCh. 5 - Prob. 10RQ
Ch. 5 - Prob. 11RQCh. 5 - Prob. 12RQCh. 5 - Prob. 13RQCh. 5 - Prob. 14RQCh. 5 - Prob. 16RQCh. 5 - Prob. 17RQCh. 5 - Prob. 18RQCh. 5 - Prob. 19RQCh. 5 - Prob. 20RQCh. 5 - Prob. 1PECh. 5 - Prob. 2PECh. 5 - Prob. 3PECh. 5 - Prob. 4PECh. 5 - Prob. 5PECh. 5 - Prob. 6PECh. 5 - Prob. 7PECh. 5 - Prob. 8PECh. 5 - Prob. 9PECh. 5 - Prob. 10PECh. 5 - Prob. 1GZCh. 5 - Prob. 2GZCh. 5 - Prob. 3GZCh. 5 - Prob. 4GZCh. 5 - Prob. 5GZ
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- The button1_Click() method that is generated by the IDE ___________. has a private access specifier is nonstatic contains parameters between its parentheses all of the abovearrow_forwardJava Program - GUI Number Guessing Look at the code, notice that the actionPerformed method is not complete. It just contains code that will print to the console when buttons are pressed. Make the following modifications to the code. When the Higher button is pressed invoke this.guesser.higher(), and then put the new guess into the this.guessField When the Lower button is pressed invoke this.guesser.lower() and then put the new guess into the this.guessField When the Reset button is pressed, invoke this.guesser.reset() and then put the new guess into the ghis.guessField When the Correct button is pressed, exit the app using System.exit(0). Wrap the invocation of lower() and higher() in try catch blocks that catch NumberGuesserIllegalStateExceptions. Show a JOptionPane that alerts the user that you are onto their schemes. Change the guessing algorithm from random-guess to binary search. You can do this by changing the object created for the guesser to a plain old NumberGuesser. It…arrow_forwardThis is the question I am stuck on - Radio station KJAVA wants a class to keep track of recordings it plays. Create a class named Recording that contains fields to hold methods for setting and getting a Recording’s title, artist, and playing time in seconds. Write an application that instantiates five Recording objects and prompts the user for values for the data fields. Then prompt the user to enter which field the Recordings should be sorted by—(S)ong title, (A)rtist, or playing (T)ime. Perform the requested sort procedure, and display the Recording objects. This is what I have so far - public class Recording { private String song; private String artist; private int playTime; public void setSong(String title) { this.song = title; } public void setArtist(String name) { this.artist = name; } public void setPlayTime(int time) { this.playTime = time; } public String getSong() { return song; } public String…arrow_forward
- // Question 4: // Declare an integer variable named "variables with an initial value of 10. // Write a method named "SetToOne" that takes one out parameter. // The method should set the out parameter to 1. // Call the method SetToOne passing variables in the btnQ4 click method. // Display the variable variables in the lblQ4. private void btn04_Click(object sender, EventArgs e) {arrow_forwardWrite code that creates a Random object and then assigns a random integer in the range of 1 through 100 to the variable intRandomNumber.arrow_forwardswitch_player(): we will allow the players to choose their own names, but for our purposes, it is easier to think of them as number (0 and 1, for indexing purposes). We will display their names to them on the screen, but in the background, we will keep track of them based on their number. This function should take 1 argument, an integer (either 0 or 1) representing the player and should return the opposite integer (1 if 0 is entered and 0 if 1 is entered). This is a simple function, but it will make our code cleaner later. Use your constants! Using Thonnyarrow_forward
- Questionarrow_forwardGradient FillIn this labwork are asked to write a GUI application again using AWT. This is a fairly easy labworkthat is more about getting used to synchronized online learning. You are expected to:• Draw two rectangles.• Both of them should be filled using GradientPaint() function of AWT. (Check out itsfunction definition that is listed below.)• The first gradient should be parallel to the diagonal of the first rectangle. The colorgradient should not be repeated (acyclic).• The second gradient should be horizontal. The color gradient should be repeated forthis one (cyclic).• You are free to choose the colors but other than that your output should be similar tothe example screenshot given below.arrow_forwardFor this interactive assignment, you will create an application that grades the written portion of the driver’s license exam. The exam has 20 multiple-choice questions. Here are the correct answers: B 2. D 3. A 4. A 5. B 6. A 7. B 8. A 9. C 10. D B 12. C 13. D 14. A 15. D 16. C 17. C 18. B 19. D 20. A Your program should store these correct answers in a list. The program should read the student’s answers for each of the 20 questions from a text file and store the answers in another list. (Create your own answer text file to test the application.) After the student’s answers have been read from the text file, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the…arrow_forward
- Carly’s Catering provides meals for parties and special events. In previous chapters, you have developed a class that holds catering event information and an application that tests the methods using four objects of the class. Now modify the Event and EventDemo classes as follows: Modify the method that sets the event number in the Event class so that if the argument passed to the method is not a four-character String that starts with a letter followed by three digits, then the event number is forced to A000. If the initial letter in the event number is not uppercase, force it to be so. Add a contact phone number field to the Event class. Add a set method for the contact phone number field in the Event class. Whether the user enters all digits or any combination of digits, spaces, dashes, dots, or parentheses for a phone number, store it as all digits. For example, if the user enters (920) 872-9182, store the phone number as 9208729182. If the user enters a number with fewer or more…arrow_forwardCreate an application that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows:1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Do not display the computer’s choice yet.)2. The user selects his or her choice of rock, paper, or scissors. To get this input you can use Button controls, or clickable PictureBox controls displaying some of the artwork that you will find in the student sample files.3. The computer’s choice is displayed.4. A winner is selected according to the following rules:• If one player chooses rock and the other player chooses scissors, then rock wins. (Rock smashes scissors.)• If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.)• If one player chooses…arrow_forwardPrompt: Create a virtual pet care game where players can choose a cute pet and then feed, train, or play-with it. The game is based on a simple game loop, where at the beginning of each loop, the game notifies the player of the current pet status (hungry, sleepy, bored, etc.) The player should then select the corresponding actions to improve the status of the pet. After each action, the game loop is repeated and the pet values are updated. The status should be displayed along with the corresponding messages as well as the menu of actions. Design Requirements: Implement the Pet class Create the base Pet class. It should manage variables that keep track of the pet's state, such as how hungry/sleepy/bored/happy the pet is currently. Include a function that updates the pet's state values to reflect the passage of time. If any of the variables are above some threshold (such as 40 out of 100), the function should output the corresponding message such as "<Pet name> is hungry!" Each…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY