0% found this document useful (0 votes)
9 views

EXP (5)-1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

EXP (5)-1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EXP NO : 5

QUESTION :

Create an interface “CreditCardInterface” with methods to viewCreditAmount,


viewPin,changePin and payBalance. Create a class Customer (name, card number,
pin,creditAmount – initialized to 0). Implement all methods of the interface
“CreditCardInterface” in Customer class. Create an array of customer objects and perform the
following actions. Pay Balance,Change Pin

CODE:

interface CreditCardInterface {

void viewCreditAmount();

void viewPin();

void changePin(int newPin);

void payBalance(double amount);

class Customer implements CreditCardInterface {

String name;

String cardNumber;

int pin;

double creditAmount;

Customer(String name, String cardNumber, int pin) {

this.name = name;

this.cardNumber = cardNumber;

this.pin = pin;

this.creditAmount = 0.0; // Initial credit amount is 0


}

public void viewCreditAmount() {

System.out.println("Current Credit Amount for " + name + " (" + cardNumber + "): $" +
creditAmount);

public void viewPin() {

System.out.println("Current PIN for " + name + " (" + cardNumber + "): " + pin);

public void changePin(int newPin) {

this.pin = newPin;

System.out.println("PIN changed successfully for " + name + " (" + cardNumber + ")");

public void payBalance(double amount) {

if (amount > creditAmount) {

System.out.println("Insufficient credit for " + name + " to pay $" + amount);

} else {

creditAmount -= amount;

System.out.println(name + " paid $" + amount + " towards the balance. Remaining
Credit: $" + creditAmount);

}
public void addCredit(double amount) {

creditAmount += amount;

System.out.println("Credit of $" + amount + " added to " + name + "'s account.");

public class CreditCardApp {

public static void main(String[] args) {

Customer[] customers = new Customer[2];

customers[0] = new Customer("John Doe", "1234-5678-9101", 1234);

customers[1] = new Customer("Alice Smith", "9876-5432-1098", 5678);

customers[0].addCredit(1000.0); // Adding $1000 to John Doe's account

customers[1].addCredit(500.0); // Adding $500 to Alice Smith's account

customers[0].viewCreditAmount();

customers[0].viewPin();

customers[0].payBalance(200.0); // Pay $200

customers[0].changePin(4321); // Change PIN

customers[1].viewCreditAmount();

customers[1].viewPin();

customers[1].payBalance(100.0); // Pay $100

customers[1].changePin(8765); // Change PIN

}
}

OUTPUT:

Credit of $1000.0 added to John Doe's account.

Credit of $500.0 added to Alice Smith's account.

Current Credit Amount for John Doe (1234-5678-9101): $1000.0

Current PIN for John Doe (1234-5678-9101): 1234

John Doe paid $200.0 towards the balance. Remaining Credit: $800.0

PIN changed successfully for John Doe (1234-5678-9101)

Current Credit Amount for Alice Smith (9876-5432-1098): $500.0

Current PIN for Alice Smith (9876-5432-1098): 5678

Alice Smith paid $100.0 towards the balance. Remaining Credit: $400.0

PIN changed successfully for Alice Smith (9876-5432-1098)

You might also like