using inheritance write a Program to calculate discount If customer purchase clothes on Offseason, set discount 15% and on Onseason 40%
Should use two classes, Onseason and Offseason
Use two methods- discount(method name should be same)
import java.util.Scanner;
public class Season {
public static void main(String[] args) {
Scanner scan= new Scanner(System.in);
Scanner scan1= new Scanner(System.in);
System.out.print("Enter type of clothes (season or off season): ");
String typeClothing=scan.nextLine();
System.out.print("Enter cost: ");
int clothingCost= scan1.nextInt();
OnSeason clothe=new OnSeason(clothingCost);
OffSeason clothe1=new OffSeason(clothingCost);
if(typeClothing.contains("off season")){
System.out.println(clothe1.Calculate());
}
else {
System.out.println(clothe.Calculate());
}
}
}
class OnSeason{
int cost;
public OnSeason(int cost) {
this.cost = cost;
}
double Calculate(){
double seasonCost= cost*0.60;
return seasonCost;
}
}
class OffSeason extends OnSeason{
public OffSeason(int cost) {
super(cost);
}
@Override
double Calculate() {
double offSeasonCost=cost*0.85;
return offSeasonCost;
}
}
Comments
Leave a comment