Name: Ridhima Srivastava Uid: 2024200126 Experiment No. 7b Aim: Program 1 Problem Statement
Name: Ridhima Srivastava Uid: 2024200126 Experiment No. 7b Aim: Program 1 Problem Statement
UID: 2024200126
Experiment No. 7b
AIM:
Program 1
Sample Output:
Name: Sarah
Name: Emily
Name: David
Name: Bob
1. Clothes
2. Accessories
2
Choose payment method:
1. Cash
2. Credit Card
---------------------------------------
1. Clothes
2. Accessories
1. Cash
2. Credit Card
1. Clothes
2. Accessories
1. Cash
2. Credit Card
---------------------------------------
1. Clothes
2. Accessories
1
1. Cash
2. Credit Card
---------------------------------------
1. Clothes
2. Accessories
1. Cash
2. Credit Card
public Payment() {
this.amount = 25000.0;
}
@Override
public void paymentDetails() {
System.out.println("Payment of ₹5000.0 done using Cash. Remaining
balance: ₹" + amount);
}
}
@Override
public void paymentDetails() {
System.out.println("Payment of ₹5000.0 done using Credit Card.");
System.out.println("Card Name: " + cardHolderName);
System.out.println("Card Expiry: " + expiryDate);
System.out.println("Card Number: " + cardNumber);
System.out.println("Remaining balance: ₹" + amount);
}
}
class Westside {
private static int clothesStock = 10;
private static int accessoriesStock = 10;
private static final double ITEM_COST = 5000.0;
// Item selection
System.out.println("Choose item to buy:");
System.out.println("1. Clothes");
System.out.println("2. Accessories");
int itemChoice = scanner.nextInt();
scanner.nextLine();
if (Westside.purchaseItem(itemChoice)) {
double cost = 5000.0;
if (paymentMethodChoice == 1) { // Cash
CashPayment cashPayment = new CashPayment();
cashPayment.updateAmount(cost);
cashPayment.paymentDetails();
} else if (paymentMethodChoice == 2) { // Credit Card
System.out.print("Enter Card Holder Name: ");
String cardHolderName = scanner.nextLine(); // Read the
cardholder name
System.out.print("Enter Card Expiry Date (MM/YY): ");
String expiryDate = scanner.nextLine(); // Read the expiry date
System.out.print("Enter Card Number: ");
String cardNumber = scanner.nextLine(); // Read the card
number
System.out.println("\n---------------------------------------");
}
}
}
RESULT:
CONCLUSION: From the above programs i revised the concepts of abstarction,multiple
classes and revising previous concepts of java.