Concept explainers
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.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Additional Engineering Textbook Solutions
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Management Information Systems: Managing The Digital Firm (16th Edition)
SURVEY OF OPERATING SYSTEMS
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting Out with Python (4th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- Write a note on the method with parameter and without return type. Give an example.arrow_forwardGive a brief explanation of a method before going through its three main parts.arrow_forwardCreate 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_forward
- Create another scenario question that involves if/elif/else statements with Boolean expressions. Then, code the solution to your question. (Remember there has to be a scenario involved).arrow_forwardYou are responsible for adding the appropriate testing code to your main. a. The getValedictorian method returns the valedictorian of the class, that is the student with the highest grade point average. Implement this new method. b. The getHonorsPercent method returns the percentage of students in the class who are in the honors program. Use 3.75 as the cutoff GPA. Implement this method. Also print the list of students, by using the isHonor method, in the Honors program. c. An alternate implementation for the School class is being considered, in which the students are stored in an ArrayList instead of an array. Show how the declaration of the data field students would look in this alternate design. MAIN CLASS: import java.util.ArrayList; public class Main { public static void main(String[] args) { System.out.println("Unit07Project2 by Your Name"); System.out.println(); int size = 10; School onw = new School(size); /* Add the code…arrow_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_forward
- The 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_forwardWrite 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_forward
- Please 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_forwardProblem: 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_forward
- 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