Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 2, Problem 15R
If the parameter to the makePayment method of the CreditCard class (see Code Fragment 1.5) were a negative number, that would have the effect of raising the balance on the account. Revise the implementation so that it throws an IllegalArgumentException if a negative amount is sent as a parameter.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Implement the below pseudo-code in a Java program using a while loop and aswitch-case statement. The program should be well structured, and the taskperformed under each option (at least options 'b' to 'e') should be implementedas a separate method.NOTE: The Scanner class does not have a method to input a character. Inorder to read a character from the keyboard, use one of the following methods(after declaring the Scanner object):static Scanner kb = new Scanner(System.in);1. char ch = kb.nextLine().charAt(0); OR2. char ch = kb.nextLine().toLowerCase().charAt(0);where kb is a Scanner class object.The second method above also converts the input to lowercase, which is oftenuseful. Though these methods allow the user to input more than one characteron the input line, the rest of the line (after capturing the first character withcharAt(0)) is discarded.If you also want to ignore the leading spaces before the first character thenuse:1. char ch = kb.nextLine().trim().charAt(0); OR2. char ch =…
UOWD Library is asking you to write a Java program that manages all the items in the Library. The library has books, journals, and media (DVD for example). All items have a name, author(s), and year of publication. A journal also has a volume number, while a media has a type (audio/video/interactive). The user of your program should be able to add an item, delete an item, change information of an item, list all items in a specific category (book, journal, or media), and print all items (from all categories). A menu asks the user which operation s/he wants to perform.
Important: make use of collections, inheritance, interfaces, and exception handling wherever appropriate.
Must be written in Python. Please include docstring and show how output should look like. Remember that all data members should be private. An object can access it's own private data members directly. It can also access the private data members of other objects of the same class directly. But when accessing a private data member of an object of another class, it needs to call the appropriate get method. If that sounds complicated, just remember this: if a method is in the same class as a private data member, then it can access that data member directly, otherwise, it needs to use a get method.
Write a class named Point that has two data members, x_coord and y_coord, representing the two coordinates of the point. It should have:
an init method that takes two arguments, an x-coordinate and y-coordinate (in that order), and uses them to initialize the two data members.
get methods for the two data members: get_x_coord and get_y_coord.
a method named distance_to that takes a Point object…
Chapter 2 Solutions
Data Structures and Algorithms in Java
Ch. 2 - Give three examples of life-critical software...Ch. 2 - Give an example of a software application in which...Ch. 2 - Prob. 3RCh. 2 - Prob. 4RCh. 2 - Prob. 5RCh. 2 - Give a short fragment of Java code that uses the...Ch. 2 - Prob. 7RCh. 2 - Prob. 8RCh. 2 - Prob. 9RCh. 2 - Prob. 10R
Ch. 2 - Prob. 11RCh. 2 - Draw a class inheritance diagram for the following...Ch. 2 - Prob. 13RCh. 2 - Prob. 14RCh. 2 - If the parameter to the makePayment method of the...Ch. 2 - Prob. 16CCh. 2 - Most modern Java compilers have optimizers that...Ch. 2 - The PredatoryCreditCard class provides a...Ch. 2 - Modify the PredatoryCreditCard class so that a...Ch. 2 - Prob. 20CCh. 2 - Write a program that consists of three classes, A,...Ch. 2 - Prob. 22CCh. 2 - Prob. 23CCh. 2 - Write a Java class that extends the Progression...Ch. 2 - Redesign the Progression class to be abstract and...Ch. 2 - Use a solution to Exercise C-2.25 to create a new...Ch. 2 - Use a solution to Exercise C-2.25 to reimplement...Ch. 2 - Write a set of Java classes that can simulate an...Ch. 2 - Write a Java program that inputs a polynomial in...Ch. 2 - Write a Java program that inputs a document and...Ch. 2 - Prob. 31PCh. 2 - Write a Java program that simulates a system that...Ch. 2 - Define a Polygon interface that has methods area()...Ch. 2 - Prob. 35PCh. 2 - Write a Java program that can make change. Your...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Big data Big data describes datasets with huge volumes that are beyond the ability of typical database manageme...
Management Information Systems: Managing the Digital Firm (15th Edition)
It has been suggested that the control software for a radiation therapy machine, used to treat patients with ca...
Software Engineering (10th Edition)
The pipe clip temperature sensors shown here are robust sensors that can be clipped directly onto copper pipes ...
Big Java Late Objects
Explain what must be done when fully replicating a database but allowing only one computer to process updates.
Database Concepts (8th Edition)
Write Java statements that will cause the following to be written to the screen; Onetwobuckleyourshoe.Threefour...
Absolute Java (6th Edition)
Why might doctors and nutritionists be interested in a device like DietSensor?
Using MIS (10th 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
- Add another public method dblValue() to the Fraction class which returns the double precision approximation value of the fraction. That is, the floating point result of actually dividing numerator by denominator. N.B. this method does not do any display itself, but can be called by a client program to be used in an output statement. Eg: if a client has a fraction frac that represents 1 / 2,then a method call to frac.dblValue() should return the double number 0.5.Use the client program to test this functionality; i.e. provide an outputstatement to display the double value of a fraction. import java.util.ArrayList;import java.util.Scanner; //Define the class Fractionclass Fraction{private int n, d;public Fraction(){//Initialize the valuesthis.n = this.d = 0;}public Fraction(int n, int d){//Initialize the variablesthis.n = n;this.d = d;}//Define the getter function getNum() that returns the numeratorpublic int getNum(){//Returns numeratorreturn n;}//Define the getter function getDen()…arrow_forwardIn the module point.py Create class Point, with a constructor (initializer) method that takes two integers, x and completed this step, test case TO CanconstructPoint should succeed. Add a method move that takes two integer arguments, dx and dy. This method should increase self.x by dx and increase self.y by dy . (If dx or dy are and stores them as instance variables self.x and self.y. When you have negative, the result will be decreasing self.x and/or self.y.) When you have completed this step, test case T1 CanMovePoint should succeed. • Now test case T2 EqualMeansIdentical will be --. You can fix this by creating a method with the special name _eq which takes, in addition to self, another Point object. This method should return a boolean. If the x and y fields of the self object and the other Point object are equal, should return True, and otherwise, it should eq return False. Now you have defined Point objects that can be created, moved, and compared for equality. But if you print a…arrow_forwardWrite a java code for online food delivery system to manage the data of customers who order the food using online application. User have different option for the payment i.e. Credit Card, Debit Card and Cash on Delivery. Credit card user get 10% discount on total bill, debit card customers get 7% discount while cash on delivery customers get 5% discount. Other than food bill each user have to pay delivery charges RS. 100/- Carefully think about number of classes and attribute for each class. All attributes of classes must be private and exposed via getter and setter. For all classes, create fully parameterized constructor. Only Java Write a test class named TerminalTest. In test class, show a menu to user to input data of customers, as well as food items. To input data you have to create static methods. Create another static method to order food items and calculate bill. Input data will be stored in database. Your program should handle all checked exceptions. Once data is saved in…arrow_forward
- In Java, give an example of a method that requests Name input. Then show another method, in the same application, that searches an object array in an object class for duplicates and reports an error when there is one. How would you utilize the second method with the first one?arrow_forwardModify the program below and add a public method called isZero() to the Fraction class. This method will determine if a Fraction represents a zero fraction. A zero fraction has a numerator == 0, no matter what the denominator is. Your isZero() method should return a Boolean resultindicating a zero fraction or otherwise. The method will be used by the client class to test whether the ‘calling fraction’ is equal to the number zero. Modify the program so that it now loops until a fraction representing zero is entered. //Import the essential package import java.util.ArrayList; import java.util.Scanner; //Define the class Fraction class Fraction { private int n, d; public Fraction() { //Initialize the values this.n = this.d = 0; } public Fraction(int n, int d) { //Initialize the variables this.n = n; this.d = d; } //Define the getter function getNum() that returns the numerator public int getNum() {…arrow_forwardCan I get a help with this in Java please? Introduce a new class, called Borrower to the project. Its purpose is to represent the borrower of the CD. It should have two fields surname and libraryId; where the latter is a mix of letters and numbers, and a suitable constructor with parameters for only these two fields in the order specified above as well as appropriate accessor methods.arrow_forward
- FOR JAVAarrow_forwardAdd a method called multiplesOfFive to the Exercise class. The method must have a void return type and take a single int parameter called limit. In the body of the method, write a while loop that prints out all multiples of 5 between 10 and limit (inclusive) on a single line. For instance, if the value of limit were 15 then the method will print: 10 15 You can use the printEvenNumbers method that is already in the Exercise class as an example to help you work out how to complete this method. In the main method of the Main class, add a call on the Exercise object to your multiplesOfFive method that prints the multiples of 5 between 10 and 25. Add a method called sum to the Exercise class. The method must have a void return type and take no parameters. In the body of the method, write a while loop to sum the values 1 to 10 and print the sum once the loop has finished. In the main method of the Main class, add a call on the Exercise object to your sum method. Check that it prints: 55 Add…arrow_forwardFor JAVAarrow_forward
- Modify the above code to use the alternative method for multithreading (i.e., implementing the Runnable interface). Name your main class RunnableHelloBye and your subsidiary classes Hello and Goodbye respectively. The fi rst should display the message ‘Hello!’ ten times (with a random delay of 0–2 s between consecutive displays), while the second should do the same with the message ‘Goodbye!’. Note that it will NOT be the main class that implements the Runnable interface, but each of the two subsidiary classes.arrow_forwardAdd another public method dblValue() to your Fraction class which returns the double precision approximation value of the fraction. That is, the floating point result of actually dividing numerator by denominator. N.B. this method does not do any display itself, but can be called by a client program to be used in an output statement. Eg: if a client has a fraction frac that represents 1 / 2, then a method call to frac.dblValue() should return the double number 0.5. Use your client program to test this functionality; i.e. provide an output statement to display the double value of a fractionhere are my codes /** To change this license header, choose License Headers in Project Properties.* To change this template file, choose Tools | Templates* and open the template in the editor.*/package lab4; /**** @author engko*/public class Fraction {//Define the class Fraction// declaring instance variablesString res;private int num, denom; // default constructor to initialize instance…arrow_forwardCan i get this question in java plsA repository of library manages books. A book has a title, one or more authors, the publishing name, list of keywords, number of pages, publication date, figures and tables. The class Library contains the collection of books. In Library you have a method checkRepo() which, if it finds two books with same name, it modifies the name of one of them (adding _(1) at the end). Implement the needed interfaces and methods for the classes. The repository has a method which specifies how many times figures and tables each book has. Create a main method which tests the program with relevant data based on data which is read from a file and output the books which were published during the last 2 years..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