Professional Documents
Culture Documents
3:
NAME: umaima zahoor
PROGRAM 1:
class Product {
this.name = name;
this.price = price;
return name;
this.name = name;
return price;
super(name, price);
this.author = author;
return author;
this.author = author;
super(name, price);
this.brand = brand;
}
public String getBrand() {
return brand;
this.brand = brand;
class ShoppingCart {
this.capacity = capacity;
itemCount = 0;
items[itemCount] = product;
itemCount++;
} else {
}
public double calculateTotalPrice() {
totalPrice += items[i].getPrice();
return totalPrice;
cart.addProduct(book);
cart.addProduct(phone);
OUTPUT 1:
PROGRAM 2:
class Product {
private String name;
private double price;
interface Promotion {
double calculateDiscount(double price);
}
@Override
public double calculateDiscount(double price) {
return price * (1 - discountPercentage / 100);
}
}
class ShoppingCart {
private Product[] items;
private int itemCount;
private Promotion promotion;
OUTPUT 2:
Total price with 10% discount: $494.99099999999999
Total price with buy one get one free: $464.99