Explanation of Solution
Initial consideration:
There is a need to provide the modified version of theCreditCard class given in the code fragment 1.5 in the text book that contains
- TheCreditCard class description needs to be modified in such a way that a customer is allocated a minimum monthly payment in the form of percentage of the balance.
- The modified CreditCard class should also have the getBalance( ) methodas well to check the balance for a particular customer.
Modified version of CreditCard class:
The CreditCard class has to be modified that need to be referthe code fragment 1.5 given in the textbook which contains the CreditCardclass. This code is modified with the little change as follows.
- Anew instance variable balance is used thathas private visibility, but a new protected method isadded, with signature setBalance(newBalance) to get the new updated balance for that particular customer.
- Also the modified code has shown to implement the method called PredatoryCreditCard.processMonth()as follows:
Modified code:
//Class definition
public class CreditCard
{
// Instance variables:
private String customer; // name of the customer
private String bank; // name of the bank
private String account; // account identifier
private int limit; // credit limit
protected double newbalance;//The new updated balance
protected double balance; // current balance
// Constructors:
public CreditCard(String cust, String bk, String acnt, int lim, double initialBal)
{
customer = cust;
bank = bk;
account = acnt;
limit = lim;
//balance has private visibility
Private int balance = initialBal;
}
public CreditCard(String cust, String bk, String acnt, int lim)
{
// use a balance of zero as default
this(cust, bk, acnt, lim, 0.0);
}
// New Accessor method
public PredatoryCreditCard...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Data Structures and Algorithms in Java
- Answer the given question with a proper explanation and step-by-step solution. USING JAVA: ---Sorting the Invoices via dates--- Another error that will still be showing is that there is not Comparable/compareTo() method setup on the Invoice class file. That is something you need to fix and code. Implement the use of the Comparable interface and add the compareTo() method to the Invoice class. The compareTo() method will take a little work here. We are going to compare via the date of the invoice. The dates of the Invoice class are by default saved in a MM-DD-YYYY format. So they have a dash '-' between each part of the date. So you will need to split the date of the current invoice AND split the date of the object sent to the method. We have three things to compare against here. First we need to check the year. If the years are the same then you should go another step forward and compare the months. If the months are the same then you will lastly have to compare the day. Use whatever…arrow_forwardImagine you have two classes: Employee (which represents being an employee) and Ninja (which represents being a Ninja). An Employee has both state and behaviour; a Ninja has only behaviour. You need to represent an employee who is also a ninja (a common problem in the real world). By creating only one interface and only one class (NinjaEmployee), show how you can do this without having to copy method implementation code from either of the original classes.arrow_forwardImplement all the classes using Java programming language from the given UML Class diagram. Note: This problem requires you to submit only one class: Date.java. Do NOT include "public static void main()" method inside all of these classes. The class would be tested, using the unit-testing framework JUnit 4.arrow_forward
- Consider the Person class in Problem 1. Implement the interface PersonPriorityQueueInterface provided in the assignment. In your implementation, you must use an instance of AList (which you used in Problem 1) to store the list of persons. We consider that a person whose age is higher than a second person also has a higher priority. Thus, the method peek(), for example, should return the person who is the oldest in the list. Your implementation should be O(n) for add, and O(1) for the remaining methods. Consider the Person class in Problem 1. Implement the interface PersonPriorityQueueInterface provided in the assignment. In your implementation, you must use an instance of AList (which you used in Problem 1) to store the list of persons. We consider that a person whose age is higher than a second person also has a higher priority. Thus, the method peek(), for example, should return the person who is the oldest in the list. Your implementation should be O(n) for add, and O(1)…arrow_forwardIn this exercise, we are going to model some behaviors of a square. Since the Square object extends the Rectangle object, we see that a lot of the information we need is stored in the superclass and we will need to access it using the super keyword. Your job is to complete the Square class, as specified within the class. Upon completion, thoroughly test out your code using the SquareTester class.arrow_forwardImplement all the classes using Java programming language from the given UML Class diagram. Note: This problem requires you to submit just two classes: MyTriangle.java, MyPoint.java. Do NOT include "public static void main()" method inside all of these classes. The classes would be tested, using the unit-testing framework JUnit 4. A class called MyTriangle, which models a triangle with 3 vertices, is designed as shown. The MyTriangle class uses three MyPoint instances (created in the earlier exercise) as its three vertices. It contains: Three private instance variables v1, v2, v3 (instances of MyPoint), for the three vertices. A constructor that constructs a MyTriangle with three sets of coordinates, v1=(x1, y1), v2=(x2, y2), v3=(x3, y3). An overloaded constructor that constructs a MyTriangle given three instances of MyPoint. A toString() method that returns a string description of the instance in the format "MyTriangle[v1=(x1,y1),v2=(x2,y2),v3=(x3,y3)]". A getPerimeter() method that…arrow_forward
- Thank you for the reply. This needs to be done using the Lambda method. CAn you help me with that?arrow_forwardImplement all the classes using Java programming language from the given UML Class diagram. Note: This problem requires you to submit only one class: MyDate.java. Do NOT include "public static void main()" method inside all of these classes. The classes would be tested, using the unit-testing framework JUnit 4. A class called MyDate, which models a date instance, is defined as shown in the class diagram. The MyDate class contains the following private instance variables: year (int): Between 1 to 9999. month (int): Between 1 (Jan) to 12 (Dec). day (int): Between 1 to 28|29|30|31, where the last day depends on the month and whether it is a leap year for Feb (28|29). It also contains the following public static final variables (drawn with underlined in the class diagram): MONTHS (String[]), DAYS (String[]), and DAY_IN_MONTHS (int[]): static variables, initialized as shown, which are used in the methods. The MyDate class has the following public static methods (drawn with underlined in…arrow_forwardQ. Why not have a single Collection data type that uses methods for adding items, removing the most recently inserted items, removing the least recently inserted items, removing random items, iterating, returning the number of items in the collection, and performing any other actions we may require? Then we could combine them all into a single class that could be used by many customers.arrow_forward
- implement modi or stepping stone method without using the package.arrow_forwardAdd a toString() method to Fraction class that returns the fraction as aString in the form "x / y", where x and y are numerator and denominatorrespectively. As the method does not do any display itself, the output can be done by a client program that calls the method in an output statement. Use client program to test this functionality; i.e. provide an output statement to display a fraction as its String representation. class Fraction2{private int n, d;public Fraction(){this.n = this.d = 0; //Initialize the values}public Fraction(int n, int d){this.n = n; //Initialize the variablesthis.d = d;}//Define the getter function getNum() that returns the numeratorpublic int getNum(){//Returns numeratorreturn n;} //Define the getter function getDen() that returns the denominatorpublic int getDen(){//Returns denominatorreturn d;}//Define the boolean function isZero() that returns 0 if numerator is 0 and denominator is not equals to zeropublic boolean isZero(){return(getNum() == 0 &&…arrow_forwardImplement all the classes using Java programming language from the given UML Class diagram. Note: This problem requires you to submit only one class: Ball.java. Do NOT include "public static void main()" method inside all of these classes. Graders will be testing your classes, using the unit-testing framework JUnit 4. A class called Ball is designed as shown in the class diagram. The Ball class contains the following private instance variables: x, y and radius, which represent the ball's center (x, y) co-ordinates and the radius, respectively. xDelta (Δx) and yDelta (Δy), which represent the displacement (movement) per step, in the x and y direction respectively. The Ball class contains the following public methods: A constructor which accepts x, y, radius, speed, and direction as arguments. For user friendliness, user specifies speed (in pixels per step) and direction (in degrees in the range of (-180°, 180°]). For the internal operations, the speed and direction are to be…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