Upload files to "OOP/Java/Lab/Week8/HardSoftWareComp"
This commit is contained in:
parent
50fb2e24af
commit
ea71c33c38
70
OOP/Java/Lab/Week8/HardSoftWareComp/HardSoftWareComp.java
Normal file
70
OOP/Java/Lab/Week8/HardSoftWareComp/HardSoftWareComp.java
Normal file
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user