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 48E
Rewrite the if-else statement so that the method still behaves correctly but the error message is printed if the boolean expression is true but the balance is increased if the expression is false. You will obviously have to rewrite the condition to make things happen this way around.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Critically explain why you would consider the concept of using
methods in your program again running a couple of if-else
statements.
Write a note on the method with parameter and without return type. Give an
example.
Give a brief explanation of a method before going through its three main parts.
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
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
A file that contains a Flash animation uses the __________ file extension. a. .class b. .swf c. .mp3 d. .flash
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Essay Class Design an Essay class that extends the GradedActivity class presented in this chapter. The Essay cl...
Starting Out with Java: Early Objects (6th Edition)
Practice Problem 8.5 (solution page 797) Write a wrapper function for sleep, called snooze, with the following ...
Computer Systems: A Programmer's Perspective (3rd Edition)
Fat Gram Calculator Write a program that asks the user to enter the number of calories and fat grams in a food ...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
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
- Create a class with a method. The method has to decide whether a given year is a leap year or not. Note- A year is a leap year if: • It has an extra day i.e. 366 instead of 365. It occurs in every 4 year e.g. 2008, 2012 are leap years. For every 100 years a special rule applies-1900 is not a leap year but 2000 is a leap year. In those cases, we need to check whether it is divisible by 400 or not. > > ClassAssignmentEx2 ©LeapYearDecider javaclassnotes.assignments javaclassnotes.assignments ClassAssignmentEx2() LeapYearDecider() main(String):void A isLeapYear(int):booleanarrow_forwardWith your askForYesNo method, how would you get the same result with only using one if/else if/else statement?? (IN JAVA PROGRAMMING) You also need to fix up your styling: All your method comments need to be in a block comment (/** comment */) and should include the parameters taken and values returned All your variables need to have a line comment (//comment) next to them explaining what they are going to be used for import java.util.Scanner; /** * 4.3CR User Input Functions * a functions to read a number within a range, and read more natural boolean values from the user * * @author MEHAKPREET KAUR * @version 04/08/2021 */ public class UserInput { // method to diplay askForInt public static int askForInt(Scanner in, String ask, int min, int max){ int value; //value entered by user System.out.print(ask + "(" + min + "-" + max + "): "); value = in.nextInt(); //loop check for invalid value while(value < min || value > max){…arrow_forwardThe following technique is used in a game of chess: canMoveTo(int x, int y), boolean. A method in the Piece class returns if the piece may travel to position (x, y). Describe how you would put this method to the test.arrow_forward
- Write the code for the timeTick method in ClockDisplay that displays hours, minutes, and seconds, or even implement the whole class if you wish.arrow_forwardCopy your previous class definition for RectangularSolid from the previous problem, including both methods. Provide mutators (setters) and accessors (getters) for each of the three parameters. Use the naming convention for these methods that is demonstrated in your textbook (i.e. do not use the property function or decorators). These methods should allow a program using your code to modify the parameter values after creation and to read individual parameter values.arrow_forwardPlease do the following picture way. Write a method called isMultipleOfSeven which takes one integer parameter and returns a boolean indicating whether the value is divisible by 7 (return true if it's divisible by seven). At right you can see a single test case you can use to verify that your code compiles and to see what is the printed output of running your program, which you can use to ensure your method does the right thing. We recommend printing some cases in the run method to confirm what you have makes sense. We are auto-grading this problem with some hidden test cases which you cannot see. It is up to you to ensure your method does what is described above, otherwise you won't get points. HINT: We have discussed remainders. What is the remainder if int a is divisible by 7? isMultipleOfSeven(19); isMultipleOfSeven(49);arrow_forward
- Problem: To write the JUnit test cases for our methods, you need to create two test methods: testLeapYear: This method should test if the isLeapYear method returns true for a given leap year. For example, you can choose the year 2020 and verify if the method returns true for it. If it does, the test will pass. If it doesn't, the test will fail. testNotLeapYear: This method should test if the isLeapYear method returns false for a given non-leap year. For example, you can choose the year 1900 and verify if the method returns false for it. If it does, the test will pass. If it doesn't, the test will fail. --------------------------------------------------------------------------------------------------------------------------------------------------------- import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; public class LeapYearTest { // Test case to check if a year is a leap year @Test public void testLeapYear() { //create…arrow_forwardInclude the constructor as the book says "a method that stores the number of calories and fat grams in a food item". Also include the setters and getters for the field variables, and the additional method they talk about that "returns the percentage of the calories that come from fat". The last paragraph in the book needs clarification. Since the user will be entering the number of fat grams and not the number of calories from fat, the sentence should be more like: "Because the number of calories from fat cannot be greater than the total number of calories, if the user enters a number for the fat grams that calculates to contain more calories than the total number of calories for the food item, the program should display an error message indicating that the two input numbers are invalid." The program should then prompt for those inputs again, or at least prompt for the fat grams again. It is easier if you just prompt for the fat grams again. Please remember that all input and…arrow_forwardThis is wrong. Suppoeed to four method and call everything in main method. You can look at the question first.arrow_forward
- Write a method lastNameFirst that takes a string containing a name such as "Harry Smith" or "Mary Jane Lee", and that returns the string with the last name first, such as "Smith, Harry" or "Lee, Mary Jane".arrow_forwardThe following code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To help eliminate redundancy, convert the code into a method named spending that accepts two parameters: a Scanner for the console, and a String for a single person's name, and prints the appropriate information about that person's bills. Your method could be called twice (once for John and once for Jane) to replicate the original code's behavior.arrow_forwardComplete MyProgram such that you can test all conditions In the Theater constructor you need to instantiate each seat object based upon the information passed to the constructor, making sure they are available. In the reassign method, make sure the from and to seat assignments are within range and return false if not. There is test cases included with this exercise, so when you submit your screenshot, it needs to show the test cases passed.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
Java Math Library; Author: Alex Lee;https://www.youtube.com/watch?v=ufegX5o8uc4;License: Standard YouTube License, CC-BY