0% found this document useful (0 votes)
11 views7 pages

Mon Aoop

Advanced oop

Uploaded by

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

Mon Aoop

Advanced oop

Uploaded by

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

Assignments of lab

Submitted by: MEHWISH MALIK

Submitted to: MS HUMAIRA BATOOL

Subject: Advanced OOP

Submission Date:28 october,2024


[2:49 pm, 28/10/2024] Mehwish: public abstract class Product
{
protected int id;
protected String category;
protected String brand;
protected String size;
protected double cost;
protected double price;

public Product(int id, String category, String brand, String


size, double cost, double price) {
this.id = id;
this.category = category;
this.brand = brand;
this.size = size;
setCost(cost);
setPrice(price);
}
public void setCost(double cost) {
if (cost > 0) {
this.cost = cost;
} else {
System.out.println("Cost must be positive.");
}
}

public void setPrice(double price) {


if (price >= cost) {
this.price = price;
} else {
System.out.println("Price cannot be less than cost.");
}
}

public void applyDiscount(double discountPercentage) {


this.price -= this.price * discountPercentage / 100;
}

public abstract void showProduct();


}
[2:50 pm, 28/10/2024] Mehwish: public class Shoes extends
Product {
private String heel;
private String leather;

public Shoes(int id, String brand, String size, double cost,


double price, String heel, String leather) {
super(id, "Shoes", brand, size, cost, price);
this.heel = heel;
this.leather = leather;
applyDiscount(10); // Default discount of 10%
}

@Override
public void showProduct() {
System.out.println("Product ID: " + id);
System.out.println("Category: " + category);
System.out.println("Brand: " + brand);
System.out.println("Size: " + size);
System.out.println("Cost: " + cost);
System.out.println("Price (after discount): " + price);
System.out.println("Heel Type: " + heel);
System.out.println("Leather Type: " + leather);
}
}
[2:50 pm, 28/10/2024] Mehwish: public class Shirt extends
Product {
private String fabric;
private String sleeves;
private String collarType;

public Shirt(int id, String brand, String size, double cost,


double price, String fabric, String sleeves, String collarType) {
super(id, "Shirt", brand, size, cost, price);
this.fabric = fabric;
this.sleeves = sleeves;
this.collarType = collarType;
applyDiscount(10); // Default discount of 10%
}

@Override
public void showProduct() {
System.out.println("Product ID: " + id);
System.out.println("Category: " + category);
System.out.println("Brand: " + brand);
System.out.println("Size: " + size);
System.out.println("Cost: " + cost);
System.out.println("Price (after discount): " + price);
System.out.println("Fabric: " + fabric);
System.out.println("Sleeves: " + sleeves);
System.out.println("Collar Type: " + collarType);
}
}
[2:50 pm, 28/10/2024] Mehwish: public class ProductApp {
public static void main(String[] args) {
// Adding default products
Shoes shoes = new Shoes(1, "Nike", "42", 1000, 2000,
"High Heel", "Genuine Leather");
Shirt shirt = new Shirt(2, "Gucci", "M", 1000, 2000,
"Cotton", "Long", "Classic");

// Displaying product details


System.out.println("Shoe Details:");
shoes.showProduct();

System.out.println("\nShirt Details:");
shirt.showProduct();
}
}

You might also like