import java.io.*;
import java.util.Date;
public abstract class Customer { //super class customer
String customerName;
String customerID;
String customerAdd;
String customerPhone;
String dateOfMembership;
public Customer(String name, String id, String add, String phone, String date) { //constructor
this.customerName = name;
this.customerID = id;
this.customerAdd = add;
this.customerPhone = phone;
this.dateOfMembership = date;
}
public String getCustomerName() {
return this.customerName;
}
public void setCustomerName(String name) {
this.customerName = name;
}
public String getCustomerID() {
return this.customerID;
}
public void setCustomerID(String id) {
this.customerID = id;
}
public String getCustomerAdd() {
return this.customerAdd;
}
public void setCustomerAdd(String add) {
this.customerAdd = add;
}
public String getCustomerPhone() {
return this.customerPhone;
}
public void setCustomerPhone(String phone) {
this.customerPhone = phone;
}
public String getDateOfMembership() {
return this.dateOfMembership;
}
public void setDateOfMembership(String date) {
this.dateOfMembership = date;
}
public abstract int getPointsBalance(); //abstract method getPointsBalance() for toString method
public String toString() { //tString method to display customer name, id, add, phone and dateofmembership
return("Customer name:" +getCustomerName() + "\n" + "Customer ID:" + getCustomerID() + "\n" + "Customer address:" +getCustomerAdd() + "\n" + "Customer phone:" +getCustomerPhone() + "\n" + "Customer membership date:" +getDateOfMembership() + "Customer points balance:" +getPointsBalance());
}
}
class CherasOutletCustomer extends Customer { //sub class CherasOutletCustomer
public static final int POINTS = 100; //declare final POINTS
private int pointsUsed; //later use for mutator method
public CherasOutletCustomer(String name, String id, String add, String phone, String date) { //constructor
super(name, id, add, phone, date);
}
public int getPointsUsed() { //customer points used
return this.pointsUsed ;
}
public void setPointsUsed(int pointsUsed) {
this.pointsUsed = pointsUsed;
}
public int getPointsBalance(){ //calculate customer points balance
return POINTS - pointsUsed;
}
public String toString() { //toString method to display customer name, id, add, phone and dateofmembership
return(super.toString() + "\n" + "Branch=Cheras");
}
}
class CustomerLoyaltyRewards extends CherasOutletCustomer { //sub class CustomerLoyaltyRewards
private double customerPurchase;
double customerVoucher;
int extraPoints;
public CustomerLoyaltyRewards(String name, String id, String add, String phone, String date, double voucher, int extra) { //constructor
super(name, id, add, phone, date);
this.customerVoucher = voucher;
this.extraPoints = extra;
}
public void setCustomerPurchase(double purchase) { //customer purchase amount
this.customerPurchase = purchase;
}
public double getCustomerVoucher() { //calculate customer voucher amount
if(customerPurchase > 500)
customerVoucher += customerVoucher + 10;
else
customerVoucher += customerVoucher + 5;
return this.customerVoucher;
}
public int getExtraPoints() { //calculate customer extra points given
if(customerPurchase > 500)
extraPoints += extraPoints + 10;
else
extraPoints += extraPoints + 5;
return this.extraPoints;
}
public int getPointsBalance() { //calculate final customer points balance
return (getPointsBalance() + getExtraPoints());
}
public String toString() { //tString method to display customer name, id, add, phone and dateofmembership
return(super.toString() + "Customer voucher:" +getCustomerVoucher() + "Customer extra points:" +getExtraPoints());
}
}
class Test {
public static void main(String[] args) {
CustomerLoyaltyRewards cus = new CustomerLoyaltyRewards();
}
}