Name: B.
Latha Sagar
Reg No: 12204652
Roll No: 42
Section: D2212
Course Code: CAP680
source code:
interface ElectronicProduct {
public void turnOn();
public void turnOff();
}
interface FootwearProduct {
public void wear();
public void remove();
}
interface SportswearProduct {
public void playSports();
}
class Product implements ElectronicProduct, FootwearProduct, SportswearProduct
{
private String name;
private double price;
private int quantity;
public Product(String name, double price, int quantity) {
this.name = name;
this.price = price;
this.quantity = quantity;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public void turnOn() {
System.out.println("Turning on " + name);
}
public void turnOff() {
System.out.println("Turning off " + name);
}
public void wear() {
System.out.println("Wearing " + name);
}
public void remove() {
System.out.println("Removing " + name);
}
public void playSports() {
System.out.println("Playing sports with " + name);
}
public void sell(int quantity) {
if (quantity > this.quantity) {
System.out.println("Not enough " + name + " in stock.");
} else {
this.quantity -= quantity;
System.out.println(quantity + " " + name + " sold.");
}
}
// Method to purchase the product
public void purchase(int quantity) {
this.quantity += quantity;
System.out.println(quantity + " " + name + " purchased.");
}
}
public class Main {
public static void main(String[] args) {
Product product1 = new Product("Laptop", 1000.00, 10);
Product product2 = new Product("Running Shoes", 50.00, 20);
Product product3 = new Product("Sports Jersey", 30.00, 30);
product1.sell(5);
product2.sell(15);
product3.sell(20);
product1.purchase(5);
product2.purchase(10);
product3.purchase(15);
product1.turnOn();
product1.turnOff();
product2.wear();
product2.remove();
product3.playSports();
}
}
Output: