MIT-Curricular/OOP/Java/Lab/Week8/HardSoftWareComp/HardSoftWareComp.java

71 lines
1.7 KiB
Java

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()
);
}
}