Created
September 12, 2021 04:58
-
-
Save IAFahim/47199dd84b9361dfac320512f9fc9b1f to your computer and use it in GitHub Desktop.
CSE215 Lab Final Task B
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner sc=new Scanner(System.in); | |
double price=sc.nextInt(); | |
double discount=sc.nextInt(); | |
PercentageDiscount percentageDiscount=new PercentageDiscount(discount); | |
ThresholdDiscount thresholdDiscount=new ThresholdDiscount(100,10); | |
System.out.println(percentageDiscount.discountedPrice(price)); | |
System.out.println(thresholdDiscount.discountedPrice(price)); | |
} | |
} | |
class PercentageDiscount implements Discountable { | |
private double percentage; | |
public PercentageDiscount(double percentage) { | |
this.percentage = percentage; | |
} | |
public double getPercentage() { | |
return percentage; | |
} | |
public void setPercentage(double percentage) { | |
this.percentage = percentage; | |
} | |
@Override | |
public double discountedPrice(double price) { | |
return (price * (1 - percentage / 100)); | |
} | |
} | |
class ThresholdDiscount implements Discountable { | |
private double threshold; | |
private double discount; | |
public ThresholdDiscount(double threshold, double discount) { | |
this.threshold = threshold; | |
this.discount = discount; | |
} | |
public double getDiscount() { | |
return discount; | |
} | |
public void setDiscount(double discount) { | |
this.discount = discount; | |
} | |
public double getThreshold() { | |
return threshold; | |
} | |
public void setThreshold(double threshold) { | |
this.threshold = threshold; | |
} | |
@Override | |
public double discountedPrice(double price) { | |
if (price > threshold) { | |
return price * (1 - (discount / 100)); | |
} | |
return 0; | |
} | |
} | |
interface Discountable { | |
double discountedPrice(double price); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment