Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 4.2, Problem 21STQ
What is the bug in the code in the section “Tracing Variables”?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
This should give you an error notice on the Code Pad. setValue(5); The error notice isn't particularly helpful. Can you figure out what's wrong with this setValue call and fix it? It's also worth remembering this error message because it stems from a common beginner's blunder.
Can you code a loop using any of loop types in C++ (while, do-while and for)? Please support your statement with sample code. If your answer is yes, which loop type do you prefer in your sample code? Why?
Hi there,
I am making a snake game in python. My game over function thrwos an error though. I have attached a screenshot of the error an my code. the game should be over when the head of the snake collides with the rest of the snake. Can you help fixing it? also where exactly should i call the game_over function, is it it correct in my code?
thanks you so much in advance
my code:
import snakelibfrom snakelib import SnakeUserInterfaceimport importlibwidth = 0 # initialized in play_snakeheight = 0 # initialized in play_snakeui = None # initialized in play_snakeSPEED = 1direction = "r"keep_running = True#WIDTH = 10#HEIGHT = 10#SCALE = 0.75#ui = SnakeUserInterface(WIDTH,HEIGHT,SCALE)#ui.set_animation_speed(5)class Coordinate:def __init__(self,x,y):self.x = xself.y = ydef equals(self, coordinate):if self.x == coordinate.x and self.y == coordinate.y:return Truedef shift(self,x_shift,y_shift):self.x += x_shiftself.y += y_shiftdef copy(self):return Coordinate(self.x, self.y)class…
Chapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Can the body of a while loop execute zero times?...Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Revise the following code so that it uses a while...Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Imagine a program that reads the population of a...Ch. 4.1 - Prob. 7STQCh. 4.1 - What output is produced by the following code? int...Ch. 4.1 - What output is produced by the following code? for...Ch. 4.1 - What output is produced by the following code? for...
Ch. 4.1 - Prob. 11STQCh. 4.1 - Write a for statement that displays the even...Ch. 4.1 - Prob. 13STQCh. 4.2 - Write a Java loop that will display the phrase One...Ch. 4.2 - Write a Java loop that will set the variable...Ch. 4.2 - Write a Java loop that will read a list of numbers...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - Revise the loop shown in Listing 4.6 to use a...Ch. 4.2 - What is the bug in the code in the section Tracing...Ch. 4.2 - Add some suitable output statements to the...Ch. 4.2 - What is the bug in the code in the previous...Ch. 4.2 - Prob. 24STQCh. 4.2 - Suppose that you did not have assertion checking...Ch. 4.3 - Prob. 26STQCh. 4 - Write a fragment of code that will read words from...Ch. 4 - Develop an algorithm for computing the...Ch. 4 - Develop an algorithm for a simple game of guessing...Ch. 4 - Write a fragment of code that will compute the sum...Ch. 4 - Convert the following code so that it uses nested...Ch. 4 - Write a for statement to compute the sum 1 + 22 +...Ch. 4 - (Optional) Repeat the previous question, but use...Ch. 4 - Write a loop that will count the number of blank...Ch. 4 - Write a loop that will create a new string that is...Ch. 4 - Write a program that will compute statistics for...Ch. 4 - Suppose we attend a party. To be sociable, we will...Ch. 4 - Define an enumeration for each of the months in...Ch. 4 - Write a fragment of code that computes the final...Ch. 4 - Suppose that you work for a beverage company. The...Ch. 4 - Suppose that we want to compute the geometric mean...Ch. 4 - Prob. 16ECh. 4 - Create an applet that draws a pattern of circles...Ch. 4 - Prob. 18ECh. 4 - What does the following fragment of code display?...Ch. 4 - Repeat Practice Program 4 of Chapter 3, but use a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Repeat Practice Program 5 of Chapter 3, but use a...Ch. 4 - Write a program to read a list of nonnegative...Ch. 4 - Write a program to read a list of exam scores...Ch. 4 - Combine the programs from Programming Projects 5...Ch. 4 - Write a program that simulates the Magic 8 Ball...Ch. 4 - Whats for dinner? Let the computer decide. Write a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Prob. 2PPCh. 4 - Write a program that reads a bank account balance...Ch. 4 - Modify Programming Project 5 from Chapter 2 to...Ch. 4 - Write a program that asks the user to enter the...Ch. 4 - Write a program that simulates a bouncing ball by...Ch. 4 - You have three identical prizes to give away and a...Ch. 4 - Prob. 9PPCh. 4 - Holy digits Batman! The Riddler is planning his...Ch. 4 - Your country is at war and your enemies are using...Ch. 4 - Prob. 12PPCh. 4 - Prob. 13PPCh. 4 - Prob. 14PPCh. 4 - Prob. 15PPCh. 4 - Prob. 16PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Given that y=ax3+7, which of the following are correct Java statements for this equations? int y = a x (x x +...
Java How To Program (Early Objects)
Average Rainfall Write a program that uses nested loops to collect data and calculate the average rainfall over...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Describe a method that can be used to gather a piece of data such as the users age.
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
A(n) __________ is a member function with the same name as the class.
Starting Out with C++ from Control Structures to Objects (9th Edition)
What output would be produced in Self-Test Exercise 24 if the sign were replaced with ?
Absolute Java (6th Edition)
What is pseudocode?
Starting Out With Visual Basic (7th Edition)
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
- Please help with the rest of the subparts of the code! The first three were very good!arrow_forwardin Swift Programming: The Big Nerd Ranch Guide (2nd Ed.) e-book: Repeat the silver challenge, but this time make sure that the formatting above matches what you print to the console. You may need to search the documentation for how to represent special characters in String literals (e.g., how do you represent a newline in a String?). You will also want to look at the documentation for the print() function to use a new parameter called terminator. This parameter defaults to printing a new line after each String logged to the console, but you will want to do something else. There are many ways to solve this challenge, but one way would be to print a String with a certain number of empty spaces (it is up to you to figure out how many!) when you print specific zip codes.arrow_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
- programming in c++arrow_forwardIn c++. Read all instructions.arrow_forwardI need help with creating an Algorithm and Green text/comments for this C++ code. My professor told me that the code needs to look ORGANIZE AND NEAT and BE EASY TO READ. He recommends writing notes/comments ( I assumed he's referring to the GREEN TEXT). I MUST HAVE A ALGORITHM AT THE TOP OF THE CODE AND COMMENTS FOR THIS CODE. THE PHOTOS SHOWS AN EXAMPLE OF CODE THAT IS ORGANIZED IN THE WAY MY PROFESSOR WANTS IT. I NEED HELP WITH CREATING AN ALGORITHM AND ORGANIZING THE CODE IN THE WAY MY PROFESSOR WANTS IT. PLEASE HELP. I ALREADY CREATED THE CODE JUST NEED HELP WITH I MENTION ABOVED.arrow_forward
- Can you help me code this?arrow_forwardIs there a way you can put the output of the code? And also indent the code.arrow_forwardDo a trace on the for loop below, and show each iteration of the loop in the tracing table until the loop finishes. Each row in the table corresponds to one iteration of the for loop. int j=3, k=2; for(int i = 12; i >7; i--){ k = k + j - - * i ; } The tracing table is here: i i > 7 j karrow_forward
- I am struggling with creating arrays program on eclipse. Struggling with getting the result as asked in assignment. Need help with problem a and b. Please help as soon as you can.arrow_forwardWhat error message do you see in the Code Pad if you type the following? nd.setValue(int 5); The error message is not actually very helpful at all. Can you work out what is incorrect about this call to setValue, and correct it? It would also be worth remembering this error message because it results from an easy error to make in the early stages of learningarrow_forwardHow is the looping action of a basic loop stopped? a, It's stopped when the condition in the LOOP statement is FALSE. Answers: b. This type of loop has a predetermined number of loops to complete. c. The condition in an EXIT WHEN statement is FALSE. d. The condition in an EXIT WHEN statement is TRUE.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ Programming Tutorial 36 - Intro to Loops; Author: Caleb Curry;https://www.youtube.com/watch?v=M3o7Y0juEP0;License: Standard YouTube License, CC-BY