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
- Rewrite full code. Asparrow_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
- Consider the Account class in the below. In the class, the withdraw() method audits whenmoney is withdrawn. In order to test the withdraw() method, a stub should be provided for theaudit object. Implement the stub structure shown in the class diagram and test withdraw()method using the StubAudit class.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_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_forward
- Write in OOP with Javaarrow_forwardProgrammingarrow_forwardWrite the Boat class in Java Eclipse. A Boat has a registered name, a number of cabins, and a length.a) Define the instance variables (data fields).b) Include 2 constructors (default and one that receives the Boat registeredname, number of cabins and its length as an input).c) Write accessors (getters) and mutators (setters) methods for the instancevariables on your own. Verify/correct the answers with the help of Eclipse.arrow_forward
- How do I do this in python?arrow_forwardChange the Fraction class so that its instance variables (numerator and denominator) are hidden (i.e. private). Check that the client class (after this change) will now not compile. Why does it not compile? Provide the changes to the Fraction class and the TestFraction class such that the program can work with the private instance variables by implementing appropriate accessor and mutator methods. import java.util.Scanner;//test programpublic class testfraction{public static void main(String[] args) {//create a Scanner objectScanner in = new Scanner(System.in);//create new fractionFraction frac = new Fraction();//declare numerator and denominatorint n=1,d;System.out.print("Enter Fraction's Numerator: ");//input numeratorn = in.nextInt();System.out.print("Enter Fraction's Denominator: ");//input denominatord = in.nextInt();//loop execute until the numerator is negativewhile(n>=0){//call input with n and dfrac.input(n, d);//call displayfrac.display();System.out.print("Enter…arrow_forwardpackage customstring; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.*; /*** In this assignment, you will implement a simple class called CustomString. This class represents a more customizable version * of a String, with additional attributes and methods. * For example, the CustomString class has a “reverse” method* capitalization is reversed (i.e., lowercase to uppercase and uppercase to lowercase) for the alphabetical characters specified * in the given arg. For CustomString “abc, XYZ; 123.”, calling reverse("bcdxyz@3210.") will return "aBC, xyz; 123.". * * The CustomString class also has a “remove” method which returns a new string version of the current string where the alphabetical * characters specified in the given arg, are removed. For CustomString "my lucky numbers are 6, 8, and 19.", calling remove("ra6") * will return "my lucky numbes e 6, 8, nd 19.".* */public class CustomString {//instance variables/*** Current string.*/String…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