Concept explainers
Rewrite the printTicket method so that it declares a local variable, amountLeftloPay. This should then be initialized to contain the difference between price and balance. Rewrite the test in the conditional statement to check the value of amountLeftloPay. If its value is less than or equal to zero, a ticket should be printed; otherwise, an error message should be printed stating the amount left to pay. Test your version to ensure that it behaves in exactly the same way as the original version. Make sure that you call the method more than once, when the machine is in different states, so that both parts of the conditional statement will be executed on separate occasions.
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
Computer Systems: A Programmer's Perspective (3rd Edition)
Computer Science: An Overview (12th Edition)
Starting Out with Python (3rd Edition)
Starting Out With Visual Basic (7th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
- This is wrong. Suppoeed to four method and call everything in main method. You can look at the question first.arrow_forwardQuestion: Why I can't run this coding? I think I got problem at main method, but don't know how to fix public class Student{ private String name; // the student’s full name private String id; // the student ID private int credits; // the amount of credits for study taken so far // Create a new student with a given name and ID number. public Student(String fullName, String studentID) { name = fullName; id = studentID; credits = 0; // set credits to be 0 }// Return the full name of this student. public String getName() { return name;// returns the name } // Set a new name for this student. public void setName(String n) { name = n;// set n as name of Studentt } // Return the student ID of this student. public String getId() { return id;// return the id of the student } //Add some credit points to the student’s accumulated credits. public void addCreditPoints(int points) { credits = credits + points;// add to existing credits } /* *…arrow_forwardTake a look at the header of the method below, and then implement a sample call to it in your code.empty public ShowValue ()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_forwardUse the debugger to examine the clock-display project. Set breakpoints in the ClockDisplay constructor and each of the methods, and then singlestep through them. How do you feel about the way it's behaving? Have you gained any fresh insights as a result of this? If this is the case, what exactly were they?arrow_forwardIs there any difference in the result of writing return value + ""; rather than return "" + value; in the getDisplayValue method?arrow_forward
- I need help doing this assignment using the nextDouble method. The formula of savings is [ (total miles driven / MPG) x gas price per gallon ] - [ (total miles driven x EV kWh consumption per miles) x utility rate per kWh] .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_forwardWrite 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_forward
- PLEASE ENSURE TO USE THE FRAMEWORK PROVIDED IN THE IMAGES, AND THAT IT WORKS WITH THE TESTER CLASS. PLEASE EDIT BOTH THE TEST CLASS, DO NOT EDIT THE MAIN METHOD. Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result.arrow_forwardWhat will be returned from the following method? public double testing ( ) { double a = 9.5 + 9.3; return a; }arrow_forwardWrite a compareTo method that compares two Song objects based on the artist, and title within artist. For example, given the following Songobjects: "Glass Animals""Heat Waves" "Elton John, Dua Lipa""Cold Heart" "Adele""Easy on Me" "Doja Cat""Kiss Me More" "Adele""My Little Love" They will be put in the following order: "Adele""Easy on Me" "Adele""My Little Love" "Doja Cat""Kiss Me More" "Elton John, Dua Lipa""Cold Heart" "Glass Animals""Heat Waves" In which class does the compareTo method belong?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