Create a new project, cardCredit-exercise, within BlueJ. Create a class, CreditCard, that contains the following fields: • credit - The current available card credit of type double • creditLimit - The card credit limit of type double • numericPin - The (numeric) pin of the credit card of type int • isLoggedIn - A field of type boolean that indicates whether the user is logged in or out Define a constructor that takes two parameters (of the appropriate type) and sets the values of creditLimit and numericPin accordingly. In the constructor the credit field should be initially set equal to the credit limit and the value of isLoggedIn should be set to false. Define the method logIn that takes a pin as a parameter and if this pin is correct sets the isLoggedIn field to true, otherwise print a message to the user indicating that the inserted pin is wrong. Define the method logOut that sets the value of the field isLoggedIn to false. Define an accessor method getCurrentCredit that, only when the user is logged in, returns the available credit of the card, and a method getCurrentBalance that returns the balance of the card. (Please note that these methods should always return a double, even if you are not logged in. In this case just pick a “meaningful” value) Finally, define the methods withdraw and deposit that take an amount of money as parameter (of the appropriate type), whose effect is to increase or decrease the available credit of the card only when the user is logged in. In the withdraw method, it should be checked that the available credit of the card is sufficient. Add a check both to the deposit method and withdraw method to prevent a negative value from being passed as argument. Test that the class works as you would expect it to by creating some CreditCard objects within BlueJ and calling
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Create a new project, cardCredit-exercise, within BlueJ. Create a class, CreditCard, that contains the following
fields:
• credit - The current available card credit of type double
• creditLimit - The card credit limit of type double
• numericPin - The (numeric) pin of the credit card of type int
• isLoggedIn - A field of type boolean that indicates whether the user is logged in or out
Define a constructor that takes two parameters (of the appropriate type) and sets the values of creditLimit and
numericPin accordingly. In the constructor the credit field should be initially set equal to the credit limit and the
value of isLoggedIn should be set to false.
Define the method logIn that takes a pin as a parameter and if this pin is correct sets the isLoggedIn field to true,
otherwise print a message to the user indicating that the inserted pin is wrong. Define the method logOut that sets the
value of the field isLoggedIn to false.
Define an accessor method getCurrentCredit that, only when the user is logged in, returns the available credit of the
card, and a method getCurrentBalance that returns the balance of the card. (Please note that these methods should
always return a double, even if you are not logged in. In this case just pick a “meaningful” value)
Finally, define the methods withdraw and deposit that take an amount of money as parameter (of the appropriate
type), whose effect is to increase or decrease the available credit of the card only when the user is logged in. In the
withdraw method, it should be checked that the available credit of the card is sufficient. Add a check both to the
deposit method and withdraw method to prevent a negative value from being passed as argument.
Test that the class works as you would expect it to by creating some CreditCard objects within BlueJ and calling the
respective method
Step by step
Solved in 2 steps with 1 images