LearnFrenzy
Sign in Take a free test

Classes and Objects · Exercise 4 of 4

Classes and Objects Classes and Objects Programs

  • 10 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Java programs that model real things with classes and objects. Write each one yourself first, then open the solution – every solution was compiled and run on Java 21, and the output shown is the real output.

Question 1 Easy

Write a Student class with a name and an array of marks, methods for total, percentage and grade, and print a report for three students.

Question page & discussion
Question 2 Medium

Model Product (name, price) and Cart (a list of products with quantities) classes; add items, change a quantity, remove one, and print the bill.

Question page & discussion
Question 3 Easy

Write Rectangle and Circle classes, each with area(), perimeter() and toString(), create several shapes and print the one with the largest area.

Question page & discussion
Question 4 Medium

Write a Theatre class that holds a 2D seat map, books seats like "B3", refuses invalid or taken seats, and prints the seat map and occupancy.

Question page & discussion
Question 5 Medium

Write Item and Inventory classes: add items, record sales and restocks by item code, and print a report that flags items below their reorder level.

Question page & discussion
Question 6 Hard

Implement a small singly linked list with a private Node class: addFirst, addLast, remove a value, contains, size and toString.

Question page & discussion
Question 7 Easy

Write Task (title, priority, done) and TodoList classes: add tasks, mark one done by title, and print pending tasks sorted by priority.

Question page & discussion
Question 8 Medium

Write an Account class with deposit, withdraw and a transferTo(Account other, amount) method that moves money only when the balance allows; print balances after a series of transfers.

Question page & discussion
Question 9 Medium

Create Employee objects (name, department, monthly salary), give a 10% raise to one department, and print each department's head count and total salary.

Question page & discussion
Question 10 Hard

Model a parking lot with a fixed number of slots: park vehicles (number, type), refuse when full, unpark by number with a fee based on hours (bike ₹10/h, car ₹30/h), and print the status.

Question page & discussion
All exercises doneBack to Classes and ObjectsRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links