Computer Science, asked by dynamo979422, 10 months ago

Design a class program in java to calculate the discount given to a customer on purchasing LED television . the program also displays the amount paid by the customer after discount . The details are given as: <br />class name : television<br />Data members:int cost,int discount,int amount <br />Accept ():to input the cost of television <br />Calculate the discount <br />Display():to show the discount and the amount paid after discount​

Answers

Answered by sikhi
17

Answer:package com.sample.sample2;

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

     Television tv=new Television();

     tv.Accept();

     tv.CalculateDiscount();

     tv.Display();

   }

   public static class Television{

       int cost,discount;

       double amount;

/*the amount in the question was given in int data type but

       according to me you should prefer double data type*/

       public int Accept(){

           Scanner scan=new Scanner(System.in);

           System.out.println("Enter the cost of television");

           cost=scan.nextInt();

           return cost;

       }

       public int CalculateDiscount(){

           /*the criteria of discount is assumed as it was not specified in the question but if you want you can modify it in your own way

            */

           if(cost>=20000)discount=10;//the discount is in percent

           else if(cost<20000&&cost>=12000) discount=5;

           else discount=0;

           return discount;

       }

       public void Display(){

           if(discount ==0)

               amount=cost;

           else amount=(double)cost-(double)discount/100*cost;

           System.out.println("Discount applied:"+discount+"%");

           System.out.println("Amount to be paid: \u20B9"+amount);

       }

   }

}

Explanation: \u20B9 is used for adding rupee symbol.

The text which is not bold is called comments that are totally neglected by the compiler.

Answered by firstaid001
0

Answer:

class Television {

   int cost;

   int discount;

   int amount;

   void Accept() {

       /*

        * Input the cost

        * of Television

        */

   }

   void Calculate() {

       /*

        * Calculate the discount

        */

   }

   void Display() {

       /*

        * Show the discount and

        * the amount paid

        * after discount

        */

   }

}

Explanation:

Similar questions