Java Class-Object Board Questions


  1. DTDC a courier company charges for the courier based on the weight of the parcel. Define a class with the following specifications: [15 MARKS-2024]

    Class name: courier

    Member variables:

    name – name of the customer

    weight – weight of the parcel in kilograms

    address – address of the recipient

    bill – amount to be paid

    type – 'D'- domestic, 'I'- international

    Member methods:

    (i) void accept ( ) — to accept the details using the methods of the Scanner class only.

    (ii) void calculate ( ) — to calculate the bill as per the following criteria:

    Weight in Kgs Rate per Kg
    First 5 Kgs Rs.800
    Next 5 Kgs Rs.700
    Above 10 Kgs Rs.500
    An additional amount of Rs.1500 is charged if the type of the courier is I (International)

    (iii) void print ( ) — To print the details

    (iv) void main ( ) — to create an object of the class and invoke the methods
  2. coming soon

  3. Design a class with the following specifications: [15 MARKS-2023]

    Class name: Student

    Member variables:

    name — name of student

    age — age of student

    mks — marks obtained

    stream — stream allocated

    (Declare the variables using appropriate data types)

    Member methods:

    (i) void accept() — Accept name, age and marks using methods of Scanner class.

    (ii) void allocation() — Allocate the stream as per following criteria:

    mks stream
    >= 300 Science and Computer
    >= 200 and < 300 Commerce and Computer
    >= 75 and < 200 Arts and Animation
    < 75 Try Again
    (iii) void print() – Display student name, age, mks and stream allocated.

    Call all the above methods in the main method using an object.
  4. coming soon

  5. Design a class name ShowRoom with the following description: [15 MARKS-2019]

    Instance variables / Data members:

    String name — To store the name of the customer

    long mobno — To store the mobile number of the customer

    double cost — To store the cost of the items purchased

    double dis — To store the discount amount

    double amount — To store the amount to be paid after discount

    Member methods:

    (i) ShowRoom() — default constructor to initialize data members

    (ii) void input() — To input customer name, mobile number, cost

    (iii) void calculate() — To calculate discount on the cost of purchased items, based on following criteria

    Cost Discount (in percentage)
    Less than or equal to Rs.10000 5%
    More than Rs.10000 and less than or equal to Rs.20000 10%
    More than Rs.20000 and less than or equal to Rs.35000 15%
    More than Rs.35000 20%
    (iv) void display() — To display customer name, mobile number, amount to be paid after discount.

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

  7. Design a class RailwayTicket with following description: [15 MARKS-2018]

    Instance variables/data members:

    String name — To store the name of the customer

    String coach — To store the type of coach customer wants to travel

    long mobno — To store customer’s mobile number

    int amt — To store basic amount of ticket

    int totalamt — To store the amount to be paid after updating the original amount

    Member methods:

    (i) void accept() — To take input for name, coach, mobile number and amount.

    (ii) void update() — To update the amount as per the coach selected (extra amount to be added in the amount as follows)

    Type of Coaches Amount
    First_AC 700
    Second_AC 500
    Third_AC 250
    sleeper None
    (iii) void display() — To display all details of a customer such as name, coach, total amount and mobile number.

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

  9. Define a class ElectricBill with the following specifications: [15 MARKS-2017]

    class : ElectricBill

    Instance variables / data member:

    String n — to store the name of the customer

    int units — to store the number of units consumed

    double bill — to store the amount to be paid

    Member methods:

    (i) void accept( ) — to accept the name of the customer and number of units consumed

    (ii) void calculate( ) — to calculate the bill as per the following tariff:

    Number of units Rate per unit
    First 100 units Rs.2.00
    Next 200 units Rs.3.00
    Above 300 units Rs.5.00
    A surcharge of 2.5% charged if the number of units consumed is above 300 units.

    (iii) void print( ) — To print the details as follows:

    Name of the customer: ………………………

    Number of units consumed: ………………………

    Bill amount: ………………………

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

  11. Define a class named BookFair with the following description: [15 MARKS-2016]

    Instance variables/Data members:

    String Bname — stores the name of the book

    double price — stores the price of the book

    Member methods:

    (i) BookFair() — Default constructor to initialize data members

    (ii) void Input() — To input and store the name and the price of the book.

    (iii) void calculate() — To calculate the price after discount. Discount is calculated based on the following criteria.

    Price Discount
    Less than or equal to Rs. 1000 2% of price
    More than Rs.1000 and less than or equal to Rs.3000 10% of price
    More than Rs.3000 15% of price
    (iv) void display() — To display the name and price of the book after discount.

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

  13. Define a class called ParkingLot with the following description: [15 MARKS-2015]

    Instance variables/data members:

    int vno — To store the vehicle number.

    int hours — To store the number of hours the vehicle is parked in the parking lot.

    double bill — To store the bill amount.

    Member Methods:

    (i) void input() — To input and store the vno and hours.

    (ii) void calculate() — To compute the parking charge at the rate of Rs.3 for the first hour or part thereof, and Rs.1.50 for each additional hour or part thereof.

    (iii) void display() — To display the detail.

    Write a main() method to create an object of the class and call the above methods.
  14. coming soon

  15. Define a class named movieMagic with the following description: [15 MARKS-2014]

    Data Members Purpose
    int year To store the year of release of a movie
    String title To store the title of the movie
    float rating To store the popularity rating of the movie (minimum rating=0.0 and maximum rating=5.0)
    Member Methods Purpose
    movieMagic() Default constructor to initialize numeric data members to 0 and String data member to "".
    void accept() To input and store year, title and rating
    void display() To display the title of the movie and a message based on the rating as per the table given below
    Rating Message to be displayed
    0.0 to 2.0 Flop
    2.1 to 3.4 Semi-Hit
    3.5 to 4.4 Hit
    4.5 to 5.0 Super-Hit
    Write a main method to create an object of the class and call the above member methods.
  16. coming soon

  17. Define a class named FruitJuice with the following description: [15 MARKS-2013]

    Data Members Purpose
    int product_code stores the product code number
    String flavour stores the flavour of the juice (e.g., orange, apple, etc.)
    String pack_type stores the type of packaging (e.g., tera-pack, PET bottle, etc.
    int pack_size stores package size (e.g., 200 mL, 400 mL, etc.)
    int product_price stores the price of the product
    Member Methods Purpose
    FruitJuice() constructor to initialize integer data members to 0 and string data members to ""
    void input() to input and store the product code, flavour, pack type, pack size and product price
    void discount() to reduce the product price by 10
    void display() to display the product code, flavour, pack type, pack size and product price
    Write a main method to create an object of the class and call the above member methods.
  18. coming soon

  19. Define a class called Library with the following description : [15 MARKS-2012]

    Instance variable/data members :

    int acc_num - stores the accession number of the book

    String title - stores the title of the book

    String author - stores the name of the author

    Member methods :

    (i) void input() - to input and store the accession number, title and author.

    (ii) void compute() - to accept the number of days late calculate and display the fine charged at the rate of Rs 2 per day

    (iii) void display() - to display the details in the following format :

    Accession Number	       Title		Author

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

  21. Define a class called Mobike with the following specifications: [15 MARKS-2011]

    Data Members Purpose
    int bno To store the bike number
    int phno To store the phone number of the customer
    String name To store the name of the customer
    int days To store the number of days the bike is taken on rent
    int charge To calculate and store the rental charge
    Member Methods Purpose
    void input() To input and store the details of the customer
    void compute() To compute the rental charge
    void display() To display the details in the given format

    The rent for a mobike is charged on the following basis:

    Days Charge
    For first five days Rs.500 per day
    For next five days Rs.400 per day
    Rest of the days Rs.200 per day
    Output:

    Bike No.    Phone No.   Name    No. of days     Charge       
    xxxxxxx     xxxxxxxx    xxxx    xxx             xxxxxx    
    
  22. coming soon

  23. Define a class Student as given below: [15 MARKS-2010]

    Data members/instance variables:

    name, age, m1, m2, m3 (marks in 3 subjects), maximum, average

    Member methods:

    (i) A parameterized constructor to initialize the data members.

    (ii) To accept the details of a student.

    (iii) To compute the average and the maximum out of three marks.

    (iv) To display the name, age, marks in three subjects, maximum and average.

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

  25. Define a class Employee having the following description : [15 MARKS-2008]

    Data members/instance variables:

    int pan — to store personal account number

    String name — to store name

    double tax_income — to store annual taxable income

    double tax — to store tax that is calculated

    Member functions:

    (i) input() — Store the pan number, name, taxable income

    (ii) calc() — Calculate tax for an employee

    (iii) display() — Output details of an employee

    Write a program to compute the tax according to the given conditions and display the output as per given format.

    Total annual Taxable Income Tax Rate
    Upto Rs. 1,00;000 No tax
    From 1,00,001 to 1,50,000 10% of the income exceeding Rs. 1,00,000
    From 1,50,001 to 2,50,000 Rs. 5,000 + 20% of the income exceeding Rs. 1,50,000
    Above Rs. 2,50,000 Rs. 25,000 + 30% of the income exceeding Rs. 2,50,000.
    Output

    PAN Number     Name     Tax Income     Tax
    _________     ______     _______     _____
    
  26. coming soon

  27. Define a class Salary described as below : [15 MARKS-2007]

    Data Members:

    Name, Address, Phone, Subject Specialisation, Monthly Salary, Income Tax.

    Member methods:

    (i) To accept the details of a teacher including the monthly salary.

    (ii) To display the details of the teacher.

    (iii) To compute the annual Income Tax as 5% of the annual salary above Rs. 1,75,000/-.

    Write a main method to create an object of a class and call the above member method.
  28. coming soon