हिंदी

An electronics shop has announced a special discount on the purchase of laptops as given below: Category Up to ₹ 25,000 ₹ 25,001 − ₹ 50,000 ₹ 50,001 − ₹ 1,00,000 More than ₹ 1,00,000 - Computer Applications

Advertisements
Advertisements

प्रश्न

An electronics shop has announced a special discount on the purchase of laptops as given below: 

Category Discount on Laptop
Up to ₹ 25,000 5.0%
₹ 25,001 − ₹ 50,000 7.5%
₹ 50,001 − ₹ 1,00,000 10.0%
More than ₹ 1,00,000 15.0%

Define a class Laptop described as follows:
Data members/Instance variables: name, price, dis, amt;
Member methods:

  1. a parameterised constructor to initialize the data members.
  2. to accept the details (name of the customer and the price).
  3. to compute the discount.
  4. to display the name, discount and amount to be paid after discount.

Write a main method to create an object of the class and call the member methods.

कोड लेखन

उत्तर

import java.util.*;
public class Laptop
{ Scanner ob = new Scanner(System.in);
String name; 2
double price, dis, amt;
Laptop (String a, double b, double c, double d)
{name = a;
price = b;
dis = c;
amt = d;
}

void input()
{System.out.println("Enter the name:");
name = ob.nextLine();
System.out.println("Enter the price");
price = ob.nextFloat();
}

void discount()
{if (price <= 25000)
dis = 5.0 / 100;
else if (price >= 25001 && price <= 50000)
dis = 7.5 / 100;
else if (price >= 50001 && price <= 100000)
dis = 10.0 / 100;
else if (price > 100000)
dis = 15.0 / 100;
dis = price * dis; // calculate discount
amt = price - dis; // amount after discount
}

void display()
{System.out.println("***Output***");
System.out.println("Name: " + name);
System.out.println("Discount: " + dis);
System.out.println("Amount Payable: " + amt);
}

public static void main(String args[])
{Laptop L = new Laptop ("", 0.0, 0.0, 0.0);
L.input();
L.discount(); 
L.display(); 
}} 
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 7: Constructors - EXERCISES [पृष्ठ ४१९]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
अध्याय 7 Constructors
EXERCISES | Q VI. 2. | पृष्ठ ४१९
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×