From ea71c33c388ed24947954c31d90abf0e46f60677 Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Sat, 14 Sep 2024 01:57:43 +0530 Subject: [PATCH] Upload files to "OOP/Java/Lab/Week8/HardSoftWareComp" --- .../HardSoftWareComp/HardSoftWareComp.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 OOP/Java/Lab/Week8/HardSoftWareComp/HardSoftWareComp.java diff --git a/OOP/Java/Lab/Week8/HardSoftWareComp/HardSoftWareComp.java b/OOP/Java/Lab/Week8/HardSoftWareComp/HardSoftWareComp.java new file mode 100644 index 0000000..a74925b --- /dev/null +++ b/OOP/Java/Lab/Week8/HardSoftWareComp/HardSoftWareComp.java @@ -0,0 +1,70 @@ +interface Item { + double calculateSales(); +} + +class Hardware implements Item { + + private String category; + private String manufacturer; + private double[] salesLastThreeMonths = new double[3]; + + public Hardware(String category, String manufacturer, double[] sales) { + this.category = category; + this.manufacturer = manufacturer; + this.salesLastThreeMonths = sales; + } + + @Override + public double calculateSales() { + double total = 0; + for (double sale : salesLastThreeMonths) { + total += sale; + } + return total; + } +} + +class Software implements Item { + + private String type; + private String operatingSystem; + private double[] salesLastThreeMonths = new double[3]; + + public Software(String type, String operatingSystem, double[] sales) { + this.type = type; + this.operatingSystem = operatingSystem; + this.salesLastThreeMonths = sales; + } + + @Override + public double calculateSales() { + double total = 0; + for (double sale : salesLastThreeMonths) { + total += sale; + } + return total; + } +} + +public class HardSoftWareComp { + + public static void main(String[] args) { + Hardware hardware = new Hardware( + "Laptop", + "Dell", + new double[] { 1000, 1500, 2000 } + ); + Software software = new Software( + "Antivirus", + "Windows", + new double[] { 500, 750, 1000 } + ); + + System.out.println( + "Total Hardware Sales: INR " + hardware.calculateSales() + ); + System.out.println( + "Total Software Sales: INR " + software.calculateSales() + ); + } +}