Ex No 06
Ex No 06
EX NO: 06
1)PROGRAM:
interface Book {
String getTitle();
String getAuthor();
boolean isAvailable();
void borrow();
void returnBook();
}
OUTPUT:
2)PROGRAM:
import java.util.Random;
import java.util.Scanner;
interface PasswordGenerator {
@Override
if (length < 1) {
password[i] = randomChar;
password[length - i - 1] = randomChar;
if (length % 2 != 0) {
password[halfLength] = getRandomCharacter();
@Override
return false;
return true;
if (generator.validatePassword(password)) {
} else {
scanner.close();
OUTPUT:
3)PROGRAM:
interface Product {
String getProductDetails();
double calculatePriceAfterDiscount();
boolean isAvailable();
this.name = name;
this.price = price;
this.stockQuantity = stockQuantity;
return "Name: " + name + ", Price: $" + price + ", Stock: " + stockQuantity;
if (stockQuantity <= 0) {
this.warrantyPeriod = warrantyPeriod;
@Override
this.size = size;
@Override
this.expirationDate = expirationDate;
}
@Override
public ShoppingCart() {
count = 0;
cart[count++] = product;
return true;
} else {
return false;
if (count == 0) {
System.out.println("Cart is empty.");
} else {
System.out.println(cart[i].getProductDetails());
double total = 0;
total += cart[i].calculatePriceAfterDiscount();
return total;
class Main {
public static void main(String[] args) {
cart.addProduct(laptop);
cart.addProduct(shirt);
cart.addProduct(apple);
cart.displayCart();
OUTPUT: