Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
6th Edition
ISBN: 9780134477367
Author: David J. Barnes, Michael Kolling
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 2, Problem 52E
After a ticket has been printed, could the value in the balance field ever be set to a negative value by subtracting price from it? Justify your answer.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
he Dice game of “Pig” can be played with the following rules.
Roll two six-sided dice. Add the face values together.
Choose whether to roll the dice again or pass the dice to your opponent.
If you pass, then you get to bank any points earned on your turn. Those points become permanent. If you roll again, then add your result to your previous score, but you run the risk of losing all points earned since your opponent had rolled.
Continue to roll as much as you want. However, once a “1” comes up on either die, your score is reduced to 0, leaving you only with points that you have previously "banked." Furthermore, you must pass the dice to your opponent.
The first person to 100 points is the winner.
When a player rolls two dice, the possible outcomes are as follows:
Die #2 Roll
Roll a 1
Roll a 2
Roll a 3
Roll a 4
Roll a 5
Roll a 6
Die #1 Roll
Roll a 1
0
0
0
0
0
0
Roll a 2
0
4
5
6
7
8
Roll a 3
0
5
6
7
8
9
Roll a 4
0
6
7
8
9
10
Roll a 5
0
7
8
9
10
11
Roll a 6
0
8
9
10…
this answer hasnt cover all the questiion. Would you cover the all part of the question?
Chiralitydef is_left_handed(pips): Even though this has no effect on fairness, pips from one to six are not painted on dice any which way, but so that the pips on the opposite faces always add up to seven. (This convention makes it easier to tell when someone tries to use gaffed dice that leave out some spot values.) In each corner of the cube, one value from each pair of opposites 1-6, 2-5 and 3-4 meets two values from the other two pairs of opposites. The math works out correctly in for the 23 = 8 corners of the cube. This still leaves two possibilities how to paint these pips. Look at the corner shared by the faces 1, 2, and 3, and read these numbers clockwise around that corner starting from 1. If these three numbers read out as 1-2-3, that die is left-handed, and if they read out as 1-3-2, that die is right-handed. Analogous to a pair of shoes made separately for the left and right foot, left- and right-handed dice are in one sense identical, yet no matter how you twist and turn,…
Chapter 2 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Ch. 2 - Create a TicketMachine object on the object bench...Ch. 2 - What value is returned if you get the machine's...Ch. 2 - Prob. 3ECh. 2 - Prob. 4ECh. 2 - Create another ticket machine for tickets of a...Ch. 2 - Prob. 6ECh. 2 - Does it matter whether we write...Ch. 2 - Prob. 8ECh. 2 - Put back the word public, and then check whether...Ch. 2 - From your earlier experimentation with the ticket...
Ch. 2 - Prob. 11ECh. 2 - Prob. 12ECh. 2 - Prob. 13ECh. 2 - Prob. 14ECh. 2 - In the following field declaration from the...Ch. 2 - Prob. 16ECh. 2 - Prob. 17ECh. 2 - To what class does the following constructor...Ch. 2 - How many parameters does the following constructor...Ch. 2 - Prob. 20ECh. 2 - Suppose that the class Pet has a field called name...Ch. 2 - Challenge exercise The following object creation...Ch. 2 - Compare the header and body of the getBalance...Ch. 2 - If a call to getPrice can be characterized as...Ch. 2 - If the name of getBalance is changed to getAmount,...Ch. 2 - Prob. 26ECh. 2 - Try removing the return statement from the body of...Ch. 2 - Compare the method headers of getPrice and...Ch. 2 - Do the insertMoney and printTicket methods have...Ch. 2 - Create a ticket machine with a ticket price of...Ch. 2 - How can we tell from just its header that setPrice...Ch. 2 - Complete the body of the setPrice method so that...Ch. 2 - Prob. 33ECh. 2 - Is the increase method a mutator? If so, how could...Ch. 2 - Prob. 35ECh. 2 - Write down exactly what will be printed by the...Ch. 2 - Add a method called prompt to the TicketMachine...Ch. 2 - Prob. 38ECh. 2 - What about the following version?
Ch. 2 - Prob. 40ECh. 2 - Add a showPrice method to the TicketMachine class....Ch. 2 - Create two ticket machines with differently priced...Ch. 2 - Modify the constructor of TicketMachine so that it...Ch. 2 - Give the class two constructors. One should take a...Ch. 2 - Implement a method, empty, that simulates the...Ch. 2 - Prob. 46ECh. 2 - Predict what you think will happen if you change...Ch. 2 - Rewrite the if-else statement so that the method...Ch. 2 - Prob. 49ECh. 2 - In this version of printTicket, we also do...Ch. 2 - Is it possible to remove the else part of the...Ch. 2 - After a ticket has been printed, could the value...Ch. 2 - So far, we have introduced you to two arithmetic...Ch. 2 - Write an assignment statement that will store the...Ch. 2 - Write an assignment statement that will divide the...Ch. 2 - Prob. 56ECh. 2 - Modify your answer to the previous exercise so...Ch. 2 - Why does the following version of refundBalance...Ch. 2 - What happens if you try to compile the...Ch. 2 - What is wrong with the following version of the...Ch. 2 - Add a new method, emptyMachine, that is designed...Ch. 2 - Rewrite the printTicket method so that it declares...Ch. 2 - Challenge exercise Suppose we wished a single...Ch. 2 - List the name and return type of this method:
Ch. 2 - Prob. 65ECh. 2 - Write out the outer wrapping of a class called...Ch. 2 - Write out definitions for the following fields:
Ch. 2 - Write out a constructor for a class called Module....Ch. 2 - Prob. 69ECh. 2 - Correct the error in this method:...Ch. 2 - Write an accessor method called getName that...Ch. 2 - Write a mutator method called setAge that takes a...Ch. 2 - Write a method called printDetails for a class...Ch. 2 - Draw a picture of the form shown in Figure 2.3,...Ch. 2 - Prob. 75ECh. 2 - Create a Student with name "djb" and id "859012"....Ch. 2 - Prob. 77ECh. 2 - Challenge exercise Modify the getLoginName method...Ch. 2 - Consider the following expressions. Try to predict...Ch. 2 - Open the Code Pad in the better-ticket-machine...Ch. 2 - Now add the following in the Code Pad:...Ch. 2 - Add the following: t1.InsertMoney500; What would...Ch. 2 - Prob. 83ECh. 2 - Prob. 84ECh. 2 - Add a field, pages, to the Book class to store the...Ch. 2 - Are the Book objects you have implemented...Ch. 2 - Add a method, printDetails, to the Book class....Ch. 2 - Add a further field, refNumber, to the Book class....Ch. 2 - Modify your printDetai 1 s method to include...Ch. 2 - Prob. 90ECh. 2 - Add a further integer field, borrowed, to the Book...Ch. 2 - Prob. 92ECh. 2 - Prob. 93ECh. 2 - Prob. 94E
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
In the circuit shown in Fig. P 7.26, both switches operate together; that is, they either open or close at the ...
Electric Circuits. (11th Edition)
Determine the force in each member of the truss and state if the members are in tension or compression. Prob. 6...
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Determine the maximum deflection of the simply supported beam. The beam is made of wood having a modulus of ela...
Mechanics of Materials (10th Edition)
2-1 List the five types of measurements that form the
basis of traditional ptane surveying-
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Write a for loop that displays all of the odd numbers, 1 through 49.
Starting Out with C++ from Control Structures to Objects (9th Edition)
Which of the metal transfer mechanisms is most used in arc welding?
Degarmo's Materials And Processes In Manufacturing
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
- TYPEWRITTEN ONLY PLEASE FOR UPVOTE. DOWNVOTE FOR HANDWRITTEN. DO NOT ANSWER IF YOU ALREADY ANSWERED THIS. I'LL DOWNVOTE.arrow_forwardCorrect answer will be upvoted else downvoted. Computer science. You have w white dominoes (2×1 tiles, the two cells are hued in white) and b dark dominoes (2×1 tiles, the two cells are shaded in dark). You can put a white domino on the board in case both board's cells are white and not involved by some other domino. Similarly, you can put a dark domino if the two cells are dark and not involved by some other domino. Would you be able to put all w+b dominoes on the board if you can put dominoes both on a level plane and in an upward direction? Input The main line contains a solitary integer t (1≤t≤3000) — the number of experiments. The primary line of each experiment contains three integers n, k1 and k2 (1≤n≤1000; 0≤k1,k2≤n). The second line of each experiment contains two integers w and b (0≤w,b≤n). Output For each experiment, print YES in case it's feasible to put all w+b dominoes on the board and negative, in any case. You might print each letter…arrow_forwardDetermine the value of the decision parameter for the circle drawing technique described by Bresenham on page. Bresenham's method for drawing circles is shown here in a stage-by-stage format.arrow_forward
- Q1. Let’s play a dice game with a pair of dice following these rules:1. At the beginning, you throw a pair of dice. If the two numbers add up to 5, 6, 7, 8, or 9, thegame immediately stops.2. If your first throw does not meet those 5 totals, you would continue until you get either 11 or12.Get 1000 simulations of this paired dice game. What is the average number of dice throw per game?You can use the sample() function to simulate the dice.arrow_forwardPlease help with code as not prevent previous..arrow_forwardThe fields timesGet and timesAvoid should each influence either the score, or the game-over condition, or both. For example, maybe getting something good increases the score, hitting something bad decreases the score, and the game ends after a set amount of time. Or alternatively, maybe getting something good increases the score, and hitting a certain number of bad things ends the game. Or alternatively, maybe the score depends only on how long the user has stayed alive, and the user dies when they've hit more bad things than good things. There are many possibilities here. Complete the getScore method, which should return the current game score. In determining the score, you may use timesGet, timesAvoid, and msElapsed. Then modify updateTitle to show the title of your game. (You're welcome to show other statistics in the title, in addition to the score.) Test that the score now updates correctly, as you play your game and collide with images.arrow_forward
- The game is played in the magic maze, as shown below. The squares are flaming lava pools. If you try to cross them you will die. The grid lines are passageways and are safe to travel in. You can start at any location on the grid but must travel in the passageways. You may travel as far as you want in any direction, but once you turn, you must repeat that distance and you may only make left turns. You may not reverse direction inside the tight passageways. You must end up at the same spot you started at. If you successful, then you gain a magic coin, which automatically appears. You can start over again and again in a different or same starting spot and earn new magic coins, but the routes you take must differ somehow for each magic coin. That is, no magic coins for the exact same route as previously done. If the route varies in any way (perhaps it is the same starting location and ending location as a previous route, but longer), it will earn a new magic coin. Mad Madame Mim has…arrow_forwardIn the game of blackjack, the cards 2 through 10 are counted at their face values, regardless of suit, all face cards (jack, queen, and king) are counted as 10, and an ace counted as either 1 or 11, depending on the total count of all the cards in a player's hand. The ace is counted as 11 only if the resulting total value all cards in a player's hand. The ace is counted as 11 only if the resulting total value of all cards in a player's hand does not exceed 21, else it is counted as a 1. Using this information write a C++ program that accepts three card values as inputs (a1 corresponding to an ace, a2 corresponding to a two, and so on), calculates the total value of the hand appropriately, and displays the value of the three cards with a printed message.arrow_forwardWe don't see the value in having them.arrow_forward
- How does one go about constructing an ADT? With your comment, fill in the spaces.arrow_forwardEmail me the answers to the following questions. If you are not familiar with Peg Solitaire, then look it up online. Peg Solitaire is a game consisting of a playing board with 33 holes together with 32 pegs. In the picture above, the hole in the center is empty and the remaining holes contain pegs. The goal is to remove all the pieces except one, which should be in the center. A piece can be removed by jumping an adjacent piece over it into an empty hole. Jumps are permitted horizontally or vertically, but not diagonally. Your assignment consists of one required part, plus one extra credit part: 1. Explain (in words) why Breadth First Search and Iterative Deepening are not good methods for this problem.arrow_forwardA school has been selling raffle tickets to raise funds for the school library. Each ticket is sold for $5,and the school has sold many such tickets. Each ticket has a code. When a ticket is presented at thelibrary book sale, it can be redeemed for $1, $5, or $10. The dollar amount being assigned to each ticketis determined by a lottery before the book sale. Heidi is wondering whether the school is actually losing money out of the raffle.(a) Formulate the null and alternative hypotheses that can be used to determine whether the school islosing money out of the raffle. Note that the issue is whether the school is losing money, not whetherthe school is breaking even. Please think about what the implication is when formulating the null andalternative hypothesesarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
Java Math Library; Author: Alex Lee;https://www.youtube.com/watch?v=ufegX5o8uc4;License: Standard YouTube License, CC-BY