Answer to Question #321167 in Java | JSP | JSF for kochu

Question #321167

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)


1
Expert's answer
2022-04-08T17:54:41-0400
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;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS