Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 5.13, Problem 5.13.1CP
What happens to the
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C++
Create a Blackjack (21) game. Your version of the game will imagine only a SINGLE suit of cards, so 13 unique cards, {2,3,4,5,6,7,8,9,10,J,Q,K,A}. Upon starting, you will be given two cards from the set, non-repeating. Your program MUST then tell you the odds of receiving a beneficial card (that would put your value at 21 or less), and the odds of receiving a detrimental card (that would put your value over 21). Recall that the J, Q, and K cards are worth ‘10’ points, the A card can be worth either ‘1’ or ‘11’ points, and the other cards are worth their numerical values.
FOR YOUR ASSIGNMENT: Provide two screenshots, one in which the game suggests it’s a good idea to get an extra card and the result, and one in which the game suggests it’s a bad idea to get an extra card, and the result of taking that extra card.
In C++oldmanSea.txt contains:He was an old man who fished alone in a skiff in the Gulf of Mexico Stream and he had goneeighty-four days now without taking a fish . In the first forty days a boy had been with him . But after forty days without a fish the boy’s parents had told him that the old man was now definitely and finally salao , which is the worst form of unlucky , and the boy had gone at their orders in another boat which caught three good fish the first week . It made the boy sad to see the old man come in each day with his skiff empty and he always wentdown to help him carry either the coiled lines or the gaff and harpoon and the sail that was furled around the mast . The sail was patched with flour sacks and, furled , it looked like the flag of permanent defeat .The old man was thin and gaunt with deep wrinkles in the back of his neck . The brown blotches of the benevolent skin cancer the sun brings from its reflection on the tropic sea were on his cheeks .
1
Chapter 5 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 5.2 - Prob. 5.2.1CPCh. 5.2 - How many times are the following loop bodies...Ch. 5.2 - Prob. 5.2.3CPCh. 5.3 - What is wrong if guess is initialized to 0 in line...Ch. 5.4 - Revise the code using the System. nanoTime () to...Ch. 5.5 - Prob. 5.5.1CPCh. 5.6 - Prob. 5.6.1CPCh. 5.6 - What are the differences between a while loop and...Ch. 5.7 - Do the following two loops result in the same...Ch. 5.7 - What are the three parts of a for loop control?...
Ch. 5.7 - Suppose the input is 2 3 4 5 0. What is the output...Ch. 5.7 - What does the following statement do? for ( ; ; )...Ch. 5.7 - If a variable is declared in a for loop control,...Ch. 5.7 - Convert the following for loop statement to a...Ch. 5.7 - Count the number of iterations in the following...Ch. 5.8 - Can you convert a for loop to a while loop? List...Ch. 5.8 - Can you always convert a while loop into a for...Ch. 5.8 - Identify and fix the errors in the following code:...Ch. 5.8 - Prob. 5.8.4CPCh. 5.9 - How many times is the println statement executed?...Ch. 5.9 - Show the output of the following programs. (Hint:...Ch. 5.11 - Will the program work if n1 and n2 are replaced by...Ch. 5.11 - In Listing 5.11. why is it wrong if you change the...Ch. 5.11 - In Listing 5. 11, how many times the loop body is...Ch. 5.11 - Prob. 5.11.4CPCh. 5.11 - Prob. 5.11.5CPCh. 5.12 - What is the keyword break for? What is the keyword...Ch. 5.12 - The for loop on the left is converted into the...Ch. 5.12 - Rewrite the programs TestBreak and TestContinue in...Ch. 5.12 - After the break statement in (a) is executed in...Ch. 5.13 - What happens to the program if (low high) in line...Ch. 5.14 - Simply the code in lined 27-32 using a conditional...Ch. 5 - (Count positive and negative numbers and compute...Ch. 5 - (Repeat additions) Listing 5.4,...Ch. 5 - (Conversion from kilograms to pounds) Write a...Ch. 5 - (Conversion from miles to kilometers) Write a...Ch. 5 - (Conversion from kilograms to pounds and pounds to...Ch. 5 - Prob. 5.6PECh. 5 - (Financial application: compute future tuition)...Ch. 5 - (Find the highest score) Write a program that...Ch. 5 - (Find the two highest scores) Write a program that...Ch. 5 - (Find numbers divisible by 5 and 6) Write a...Ch. 5 - (Find numbers divisible by 5 or 6, but not both)...Ch. 5 - (Find the smallest n such that n2 12,000) Use a...Ch. 5 - (Find the largest n such that n3 12,000) Use a...Ch. 5 - (Compute the greatest common divisor) Another...Ch. 5 - (Display the ASCII character table) Write a...Ch. 5 - (Find the factors of an integer) Write a program...Ch. 5 - (Display pyramid) Write a program that prompts the...Ch. 5 - (Display four patterns using Loops) Use nested...Ch. 5 - (Display numbers in a pyramid pattern) Write a...Ch. 5 - (Display prime numbers between 2 and 1,000) Modify...Ch. 5 - Prob. 5.21PECh. 5 - For the formula to compute monthly payment, see...Ch. 5 - (Demonstrate cancellation errors) A cancellation...Ch. 5 - Prob. 5.24PECh. 5 - (Compute ) You can approximate by using the...Ch. 5 - (Compute e) You can approximate e using the...Ch. 5 - (Display leap years) Write a program that displays...Ch. 5 - (Display the first days of each month) Write a...Ch. 5 - (Display calendars) Write a program that prompts...Ch. 5 - (Financial application: compound value) Suppose...Ch. 5 - (Financial application: compute CD value) Suppose...Ch. 5 - (Game: lottery) Revise Listing 3.8, Lottery.java,...Ch. 5 - (Perfect number) A positive integer is called a...Ch. 5 - (Game: scissor; rock, paper) Programming Exercise...Ch. 5 - (Summation) Write a program to compute the...Ch. 5 - (Business application: checking ISBN) Use loops to...Ch. 5 - (Decimal to binary) Write a program that prompts...Ch. 5 - (Decimal to octal) Write a program that prompts...Ch. 5 - (Financial application: find the sales amount) You...Ch. 5 - (Simulation: heads or tails) Write a program that...Ch. 5 - (Occurrence of max numbers) Write a program that...Ch. 5 - (Financial application: find the sales amount)...Ch. 5 - (Math: combinations) Write a program that displays...Ch. 5 - (Computer architecture: bit-level operations) A...Ch. 5 - (Statistics: compute mean and standard deviation)...Ch. 5 - (Reverse a string) Write a program that prompts...Ch. 5 - (Business: check ISBN-13) ISBN -13 is a new...Ch. 5 - (Process string) Write a program that prompts the...Ch. 5 - (Count vowels and consonants) Assume that the...Ch. 5 - Prob. 5.50PECh. 5 - (Longest common prefix) Write a program that...
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
- For this C++ hw do the following: Your game, the player’s goal is to reach campus exactly. The player starts 14 miles away and has up to 4 turns to reach campus. At each turn the play can ride either use a Bus, a Subway, or a Jetpack: Riding a Bus moves the player forward 2 miles each turn. Riding a Subway moves the player forward 5 miles each turn Riding a Jetpack moves the player forward 10 mile each turn. Example:You are 14 mile(s) from campus!How do you wish to travel? (1 bus, 2 subway, 3 jetpack) The player chooses one. After each turn, the player is informed how much farther she must travel before reaching campus. Winning/Losing: After the last turn, if the player has reached campus exactly ("You have won!") Otherwise, explain the problem: "You have over-shot your target!" or "You haven't reached your target!" And then write “You lose!” The game will operate as follows: Report how far the user is from campus – the player starts 14 mile away For each turn: o Ask user to…arrow_forwardIN C++ programming This question is inspired by the famous Uno card game. Write an activity that takes two arguments: (1) the player's current hand and (2) the current upward card on the table. Work will be back true if the player is able to make the game, or false if the player must draw on the deck. A player can make a game if: They have a card the same color as the upside card. They have the same number card as the upside card. canPlay (["yellow 3", "yellow 7", "blue 8", "red 9", "red 2"], "red 1") => trutharrow_forwardHello, This is part of my hangman simulation in C++. If you compile and run it and type "Easy," the code should run. If you run it though, the body of the hangman doesn't align when you guess wrong. Could you help me with that and implement an if statement to repeat the program if user wants to play again? #include <iostream> #include <cstdlib> #include <ctime> #include <string> #include <iomanip>using namespace std; const int MAX_TRIES = 5;char answer; int letterFill(char, string, string&); int main() { string name; char letter; int num_of_wrong_guesses = 0; string word; srand(time(NULL)); // ONLY NEED THIS ONCE! // welcome the user cout << "\n\nWelcome to hangman!! Guess a fruit that comes into your mind."; // Ask user for for Easy, Average, Hard string level; cout << "\nChoose a LEVEL(E - Easy, A - Average, H - Hard):" << endl; cin >> level; // compare level if (level == "Easy") {//put all the string inside…arrow_forward
- Using C++ Write a program that plays a dice game called "21" It is a variation on BlackJack where one player plays against the computer trying to get as close to 21 as possible without going over. Here are the rules of the game: You will play with dice that have numbers from 1 to 11. To win, the player or the computer has to get to 21, or as close as possible without going over. If the player or computer goes over 21, they instantly lose. If there is a tie, the computer wins. Starting the game: The player is asked to give the computer a name. For now, we'll simply call the computer opponent, "computer." The game starts with rolling four dice. The first two dice are for the player. These two dice are added up and the total outputted to the screen. The other two dice are for the computer. Likewise, their total is outputted to the screen. Player Loop: If a total of 21 has been reached by either the player or the computer, the game instantly stops and the winner is…arrow_forward1. In the game of Monopoly, a pair of dice are rolled to move a player's piece around the board. If a double is rolled (the dice show the same number), the player receives another roll of the dice. If a double is rolled a second time, a third roll of the dice is received. If a double is rolled on the third occasion, the player forfeits their turn (and goes to Jail). Write a program which simulates two players having 50 turns each (a turn however many dice rolls a player has in a row before it's the other player's turn) and determines: a) the total number of spaces moved by each player; and b) how many times a player rolls a double which results in movement of a piece. Use the randi function. For fun, incorporate the rule that a player cannot leave Jail (cannot move) unless they either roll a double or three turns have passed without rolling a double.arrow_forwardDo in C++ programming A game to collecting coins. In level # 1, whenever the player takes a coin, the next coin is automatically blocked with an iron brick. Which coins should the player take in order to maximize his gains? EXAMPLE: COINS IN ORDER 3$ 9$ 2$ 7$ 3$ 6$ 9$ 1$ START COLLECTING COINS = (SKIP 3$) (TAKE 9$) (AUTOMATICALLY BLOCKED 2$) (TAKE 7$) (AUTOMATICALLY BLOCKED 3$) (SKIP 6$) (TAKE 9$) (AUTOMATICALLY BLOCKED 1$) = TOTAL COINS WILL BE 25$ (max coins) In level # 2, the same rules of level 1 apply, but with a twist: the player have a bag that can take only a limited number of coins. Which coins can the player take in order to maximize his gains (provided that the coins fit inside his bag)? fill the code: #include #include using namespace std; unsigned max_coins(vector coins, unsigned capacity) { //code here } int main() { vector coins = {3, 9, 2, 7, 3, 6, 9, 1}; unsigned capacity = 3; cout << max_coins(coins, capacity) << endl;…arrow_forward
- Do in C++ programming A game to collecting coins. In level # 1, whenever the player takes a coin, the next coin is automatically blocked with an iron brick. Which coins should the player take in order to maximize his gains? EXAMPLE:COINS IN ORDER 3$ 9$ 2$ 7$ 3$ 6$ 9$ 1$ START COLLECTING COINS = (SKIP 3$) (TAKE 9$) (AUTOMATICALLY BLOCKED 2$) (TAKE 7$) (AUTOMATICALLY BLOCKED 3$) (SKIP 6$) (TAKE 9$) (AUTOMATICALLY BLOCKED 1$) = TOTAL COINS WILL BE 25$ (max coins) In level # 2, the same rules of level 1 apply, but with a twist: the player have a bag that can take only a limited number of coins. Which coins can the player take in order to maximize his gains (provided that the coins fit inside his bag)? Implement the following function for level# 2 using C++: unsigned max_coins(vector<unsigned> coins, unsigned capacity)arrow_forwardWrite a C program for a match-stick game between the computer and a user. Your program should ensure that the computer always wins. Rules for the game are as follows: • There are 21 match-sticks. • The computer asks the player to pick 1, 2, 3, or 4 match sticks. • After the person picks, the computer does its picking. • Whoever is forced to pick up the last match-stick loses the game.arrow_forwardIN C++ Only Jessie has a lot of cooking with her (N). He often remembered the first few letters of the recipe and forgot the others. Like all great chefs, Jessie re-calculated the recipes according to the priority. So, looking at the list of recipes and priorities answers Jessie's questions. Response from Jessie: Giving the first few letters of the recipe; you have to print the perfect recipe in the most important way. Note: Every recipe has a unique value. Please answer this in C++ Only Input 1 flour-with-eggs 100 1 G Output 0arrow_forward
- Please code in C++. Write a program that simulates a coin-tossing game. At the beginning of the game, each of N players has a single fair coin and M points. The game performs a sequence of passes until only a minimum number of players remain. In a pass the players toss their coins into the air and when the coins fall to earth, the players count the number of coins that show heads and the number of coins that show tails. If the number of heads exceed the number of tails, then the players who tossed heads increase their points by an integer P and the players who tossed tails decrease their points by the same integer P. The players perform the opposite actions when the number of tails is greater than the number of heads. If the number of heads equals the number of tails, then no player’s points change. If any player’s points fall below one, then the player leaves the game, never to return. The game employs a second integer K to compute P’s value. K’s and P’s initial values are one.…arrow_forwardWrite a C++ program that reads five cards from the user, then analyzes the cards and prints out the category of poker hand that they represent. Poker hands are categorized according to the following labels: Straight flush, four of a kind, full house, straight, flush, three of a kind, two pairs, pair, high card. To simplify the program we will ignore card suits, aces, and face cards. The values that the user inputs will be integer values from 2 to 9. When your program runs it should start by collecting five integer values from the user. It might look like this (user input is in bold red for clarity): Enter five numeric cards, no face cards. Use 2 - 9.Card 1: 8 Card 2: 7Card 3: 8Card 4: 2Card 5: 3 (This is a pair, since there are two eights) Since we are ignoring card suits there won’t be any flushes. Your program should be able to recognize the following hand categories, listed from least valuable to most valuable: Hand Type Description Example High Card There are no…arrow_forwardProvide Full C++ Code Solutions for: Creature.h, Creature.cpp, Human.cpp. Human.h, Elf.h, Elf.cpp, Demon.h, Demon.cpp, Cyberdemon.h, Cyberdemon.cpp, Balrog.h, Balrog.cpp Suppose you are creating a fantasy role-playing game. In this game we have four different types of Creatures: Humans, Cyberdemons, Balrogs, and elves. To represent one of these Creatures we might define a Creature class as follows: class Creature { private: int type; // 0 Human, 1 Cyberdemon, 2 Balrog, 3 elf int strength; // how much damage this Creature inflicts int hitpoints; // how much damage this Creature can sustain string getSpecies() const; // returns the type of the species public: Creature(); // initialize to Human, 10 strength, 10 hitpoints Creature(int newType, int newStrength, int newHitpoints); int getDamage() const; // returns the amount of damage this Creature…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Algebraic Expressions – Algebra Basics; Author: TabletClass Math;https://www.youtube.com/watch?v=U-7nq7OG18s;License: Standard YouTube License, CC-BY
Python Tutorial for Beginners 3 - Basic Math, Mathematical Operators and Python Expressions; Author: ProgrammingKnowledge;https://www.youtube.com/watch?v=Os4gZUI1ZlM;License: Standard Youtube License