How to call a class so that a method performs specific operations based on variables in that class

I apologize greatly for the title, im open to sugguestions to rename it to something more clear

My problem is i have a task in which there are 3 seperate cards representing different membership statuses within a particular Shop. Theres a Basic card, silver card and a Gold card. Depending on the card different coupon is issued to the customer at the end of the Year. Right now im creating the coupon method within the main class. Im stuck on trying to get the method to work with the different ways each card operates.

In essence the method sees what card the customer has and applies the appropriate discount, for example if a customer is using a basic card and the balance(total spent) is more than $2000 then the coupon is 3%

Below is what i currently have(note im not worried about creating the 3 card classes, i just want to get one working)

    public class storeCard {

        public static void main(String[] args) {

            cardDetails detailsObject1 = new cardDetails(0001, "Adam Gong", 7000);
            Date date = new Date(04, 8, 2019);
            storeCard store = new storeCard();
            basicCard card = new basicCard();

            System.out.println("***** Customer Details ******");
            System.out.println("Customers name: " + detailsObject1.getName());
            System.out.println("Customers ID: " + detailsObject1.getID());
            System.out.println("Customers balance: " + detailsObject1.getBalance());
            System.out.println("Created Date: " + date.getDay() + "/" + date.getMonth() + "/" + date.getYear());
            Address addressObject1 = new Address(63, "Boyd Street", "Eagle Vale", "Campbelltown", "NSW", 2558);

        }

        public void calCoupon(double balance) {

            if(balance < 2000);
            System.out.println("Coupon is 2%");


        }

    }


    import java.util.*;

class cardDetails {

    private int ID;
    private String name;
    private double balance;

    public cardDetails(int ID, String name, double balance) {

        this.ID = ID;
        this.name = name;
        this.balance = balance;

    }

    public int getID() {

        return this.ID;
    }

    public void setID(int customerID) {

        this.ID = customerID;

    }

    public String getName() {
        return this.name;
    }

    public void setName(String customerName) {

        this.name = customerName;
    }

    public double getBalance() {
        return this.balance;
    }

    public void setBalance() {
        this.balance = balance;
    }

}




import java.util.*;

class Date {

    private int day, month, year;

    public Date(int day, int month, int year) {
        this.day = day;
        this.month = month;
        this.year = year;
    }

    public int getDay() {

        return this.day;
    }

    public void seDay(int Day) {

        this.day = day;

    }

    public int getMonth() {
        return this.month;
    }

    public void setMonth(int Month) {

        this.month = Month;
    }

    public int getYear() {
        return this.year;
    }

    public void setYear(int Year) {
        this.year = Year;
    }

    public String toString() {
        return new String("date=" + day + ",month=" + month + ",year=" + year);

    }
}

  import java.util.*;

class Address {

    private int streetNumber;
    private String streetName;
    private String suburb;
    private String city;
    private String state;
    private int postcode;

    public Address(int streetNumber, String streetName, String suburb, String city, String state, int postcode) {
        this.streetNumber = streetNumber;
        this.streetName = streetName;
        this.suburb = suburb;
        this.city = city;
        this.state = state;
        this.postcode = postcode;

        System.out.println("Customers Address: " + this);

    }

    public String toString() {
        return new String( streetNumber + " " +streetName + " " + suburb + " " + city + " " + state + " " + postcode);

    }
}

class basicCard { 
    final double discount = 0.03;
    double annuelFee = 10;
}

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

It’s not entirely clear if this is what you’re asking, but you probably want to create an interface for what the card does and let the concrete cards implement it. interface Card { double getDiscount(double moneySpent); } class BasicCard implements Card { public double getDiscount(double spent) { return spent < 2000d ? 0 : 3; } } class SilverCard implements Card { public double getDiscount(double spent) { return spent < 2000d ? 1 : 5; } } class PremiumCard implements Card { public double getDiscount(double spent) { return spent < 2000d ? 3 : 8; } } Then the money… Read more »

Jason
Guest

You have two information : The CardDetail that conveys the details of the card (id, name, balance) and the type of card. A simple approach would be to specify a card type field in CardDetails and to introduce an enum which each value will store these data : class BasicCard { final double discount = 0.03; double annuelFee = 10; } CardDetails would be : public class CardDetails { public static enum CardType{ BASIC(0.03, 10), SILVER(0.05, 15), GOLD(0.1, 20); final double discount; final double annuelFee; CardType(double discount, int annuelFee) { this.discount = discount; this.annuelFee = annuelFee; } public double getDiscount(){… Read more »