Course work 1 semester
Write a code accordingly
At first create a three pannel 3 pannels store,department,and retailer
In stores
Make jlabel and jtexfeild and display for each in one panel
Buttons add stores,display,clear,removed
add store id,store name,location,opening hour,total salses,totaldiscount,
In department
Make jlabel and jtexfeild and jcheckbox and display for each in one panel
Buttons add depatments,display,clear,removed,
Product name,marked price,selling price,isin sales
In reatailer
Make jlabel and jtexfeild and jcombox for year day month and display for each in
one panel
Vat inclisive price,loyalty point, is paymentonline,purchage day, month,year
Buttons add reatiler,display,clear,removed,calculate lotetypoint,cal
Note: i)The attributes isPaymentOnline should be displayed as JCheckBox and
purchasedYear should be displayed as JComboBox. ii)display button
Class should bediffrently called
Store.java
public class Store {
// Attributes
private int storeId;
private String storeName;
private String location;
private String openingHour;
private double totalSales;
private double totalDiscount;
// Constructor
public Store(int storeId, String storeName, String location, String openingHour) {
this.storeId = storeId;
this.storeName = storeName;
this.location = location;
this.openingHour = openingHour;
this.totalSales = 0; // Initialize total sales to zero
this.totalDiscount = 0; // Initialize total discount to zero
}
// Accessor methods
public int getStoreId() {
return storeId;
}
public String getStoreName() {
return storeName;
}
public String getLocation() {
return location;
}
public String getOpeningHour() {
return openingHour;
}
public double getTotalSales() {
return totalSales;
}
// Method to set total sales
public void setTotalSales(double newTotalSales) {
this.totalSales += newTotalSales; // Add new sales to previous total sales
}
// Method to set total discount
public void setTotalDiscount(double newDiscount) {
this.totalDiscount += newDiscount; // Add new discount to previous total
discount
}
// Display method
public void display() {
System.out.println("Store ID: " + storeId);
System.out.println("Store Name: " + storeName);
System.out.println("Location: " + location);
System.out.println("Opening Hour: " + openingHour);
if (totalSales == 0 && totalDiscount == 0) {
System.out.println("No sales and discount yet.");
} else {
System.out.println("Total Sales: " + totalSales);
System.out.println("Total Discount: " + totalDiscount);
}
}
}
Retailer.java
public class Retailer extends Store {
// Attributes
private int vatInclusivePrice;
private int loyaltyPoint;
private boolean isPaymentOnline;
private String purchasedYear;
// Constructor
public Retailer(int storeId, String storeName, String location, String openingHour,
double totalSales, double totalDiscount, int vatInclusivePrice,
boolean isPaymentOnline, String purchasedYear) {
super(storeId, storeName, location, openingHour); // Call superclass
constructor
super.setTotalSales(totalSales); // Set total sales using superclass method
super.setTotalDiscount(totalDiscount); // Set total discount using superclass
method
this.vatInclusivePrice = vatInclusivePrice;
this.isPaymentOnline = isPaymentOnline;
this.purchasedYear = purchasedYear;
this.loyaltyPoint = 0; // Initialize loyalty point to zero
}
// Accessor methods
public int getVatInclusivePrice() {
return vatInclusivePrice;
}
public int getLoyaltyPoint() {
return loyaltyPoint;
}
public boolean getIsPaymentOnline() {
return isPaymentOnline;
}
public String getPurchasedYear() {
return purchasedYear;
}
// Mutator method for isPaymentOnline
public void setIsPaymentOnline(boolean isPaymentOnline) {
this.isPaymentOnline = isPaymentOnline;
}
// Method to set loyalty points based on online payment
public void setLoyaltyPoint(boolean isPaymentOnline, int vatInclusivePrice) {
if (isPaymentOnline) {
this.loyaltyPoint = (int) (0.01 * vatInclusivePrice); // 1% of VAT inclusive price
}
}
// Method to remove product based on conditions
public void removeProduct() {
if (loyaltyPoint == 0 && (purchasedYear.equals("2020") ||
purchasedYear.equals("2021") || purchasedYear.equals("2022"))) {
System.out.println("Product removed.");
this.vatInclusivePrice = 0;
this.loyaltyPoint = 0;
this.isPaymentOnline = false;
}
}
// Display method
@Override
public void display() {
super.display(); // Call superclass display method
if (loyaltyPoint == 0 && (purchasedYear.equals("2020") ||
purchasedYear.equals("2021") || purchasedYear.equals("2022"))) {
System.out.println("Product has been removed.");
} else {
System.out.println("VAT Inclusive Price: " + vatInclusivePrice);
System.out.println("Loyalty Point: " + loyaltyPoint);
System.out.println("Purchased Year: " + purchasedYear);
}
}
}
Department.java
public class Department extends Store {
// Attributes
private String productName;
private double markedPrice;
private double sellingPrice;
private boolean isInSales;
// Constructor
public Department(int storeId, String storeName, String location, String
openingHour,
double totalSales, double totalDiscount, String productName, double
markedPrice) {
super(storeId, storeName, location, openingHour); // Call superclass
constructor
super.setTotalSales(totalSales); // Set total sales using superclass method
super.setTotalDiscount(totalDiscount); // Set total discount using superclass
method
this.productName = productName;
this.markedPrice = markedPrice;
this.sellingPrice = 0;
this.isInSales = true;
}
// Accessor methods
public String getProductName() {
return productName;
}
public double getMarkedPrice() {
return markedPrice;
}
public double getSellingPrice() {
return sellingPrice;
}
// Mutator method for marked price
public void setMarkedPrice(double newMarkedPrice) {
this.markedPrice = newMarkedPrice;
}
// Method to calculate selling price and apply discount
public void calculateDiscountPrice(boolean isInSales, double markedPrice) {
double discount = 0;
if (isInSales) {
if (markedPrice >= 5000) {
discount = 0.2;
} else if (markedPrice >= 3000 && markedPrice < 5000) {
discount = 0.1;
} else if (markedPrice >= 1000 && markedPrice < 3000) {
discount = 0.05;
}
}
this.sellingPrice = markedPrice - (markedPrice * discount);
super.setTotalDiscount(discount * markedPrice); // Update total discount in
superclass
super.setTotalSales(this.sellingPrice); // Update total sales in superclass
this.isInSales = false; // Product is no longer in sales
}
// Display method
@Override
public void display() {
super.display(); // Call superclass display method
if (isInSales) {
System.out.println("Product Name: " + productName);
System.out.println("Marked Price: " + markedPrice);
} else {
System.out.println("Product Name: " + productName);
System.out.println("Selling Price: " + sellingPrice);
}
}
}