0% found this document useful (0 votes)
4 views3 pages

OOP Lab Assignment

The document defines an interface 'Product' and two implementations: 'CentralLocking' and 'GearLocking'. It also includes an abstract class 'Car' with two subclasses 'BMW' and 'Mercedes', which utilize the product implementations to assemble and produce car models. The main class 'BanglaCarMain' demonstrates the creation and usage of these classes to produce and display details of specific car models.

Uploaded by

erensneha
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)
4 views3 pages

OOP Lab Assignment

The document defines an interface 'Product' and two implementations: 'CentralLocking' and 'GearLocking'. It also includes an abstract class 'Car' with two subclasses 'BMW' and 'Mercedes', which utilize the product implementations to assemble and produce car models. The main class 'BanglaCarMain' demonstrates the creation and usage of these classes to produce and display details of specific car models.

Uploaded by

erensneha
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/ 3

interface Product {

String getProductName();
void produce();
}

class CentralLocking implements Product {


private String productName;

public CentralLocking(String productName) {


this.productName = productName;
}

@Override
public String getProductName() {
return productName;
}

@Override
public void produce() {
System.out.println("Producing Central Locking System");
}
}

class GearLocking implements Product {


private String productName;

public GearLocking(String productName) {


this.productName = productName;
}

@Override
public String getProductName() {
return productName;
}

@Override
public void produce() {
System.out.println("Producing Gear Locking System");
}
}

abstract class Car {


protected Product product;
protected String carType;
public Car(Product product, String carType) {
this.product = product;
this.carType = carType;
}

public void printDetails() {


System.out.println("Car Type: " + carType);
System.out.println("Product Name: " + product.getProductName());
}

protected abstract void assemble();


protected abstract void produceProduct();
}

class BMW extends Car {

public BMW(Product product, String carType) {


super(product, carType);
}

@Override
protected void assemble() {
System.out.println("Assembling [" + product.getProductName() + "] for
[" + carType + " Model]");
}

@Override
protected void produceProduct() {
product.produce();
System.out.println("Modifying product [" + product.getProductName() +
"] according to [" + carType + " Model]");
}
}

class Mercedes extends Car {

public Mercedes(Product product, String carType) {


super(product, carType);
}

@Override
protected void assemble() {
System.out.println("Assembling [" + product.getProductName() + "] for
[" + carType + " Model]");
}
@Override
protected void produceProduct() {
product.produce();
System.out.println("Modifying product [" + product.getProductName() +
"] according to [" + carType + " Model]");
}
}

public class BanglaCarMain {


public static void main(String[] args) {

CentralLocking centralLocking = new CentralLocking("Central Locking


System");
GearLocking gearLocking = new GearLocking("Gear Locking System");

BMW bmw = new BMW(gearLocking, "BMW X5");


Mercedes mercedes = new Mercedes(centralLocking, "Mercedes GLS");

bmw.assemble();
bmw.produceProduct();
bmw.printDetails();

System.out.println("\n-----------------\n");

mercedes.assemble();
mercedes.produceProduct();
mercedes.printDetails();
}
}

[Copied from IntelliJ IDEA]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy