Prev Next

Exercises

1. Define a Java class for representing a polynomial of degree 9 of the form a9x9 + a8x8 + ..... + a1x + a0 where each ai denotes an integer coefficient. Your class must support the following features apart from initialization, get, set and print operations.

  • Finding the degree of a polynomial.
  • Addition and multiplication of two polynomials.
  • Compute the square roots if a given polynomial is quadratic.
  • Comparing two polynomials for equality.
  • Define, catch and handle possible exception(s) that may arise.
  • Write a driver to read the polynomial from stdin of form [a9, a8, ..., a1, a0] and invoke the above operations.

2. Define a Java class for representing vending machine. A vending machine holds certain amount of coffee powder, tea powder, milk powder, sugar and water. When switched on it maintains sufficient temperature. Sufficient water always exists. Customers are given three choices: coffee, tea and milk.

  • An 100 grams of coffee and tea powder each are loaded whenever they are empty.
  • 500 grams of milk powder and 200 grams of sugar are loaded whenever they run out.
  • 200 ml of water is used for making each cup.
  • Initially all ingradients are loaded as per the above mentioned quantities.
  • It takes 5 grams of coffee/tea powder, 25 grams of milk powder and 10 grams of sugar to make a cup of coffee/tea.
  • Whenever an ingradient is insufficient/run out while you make the order, it invokes the filling automatically.
  • A number of people use the vending machine through the day. Write a driver to simulate the use by making arbitrary choices.
  • At the end of the day you need to print how many customers were served, the number of milk, coffee and tea cups ordered, how many times each ingradient was loaded.

3. Define 3 Java classes: Student, Teacher and Course.

  • Student contains first name, last name, roll number, age, and any other relevant attributes.
  • Teacher contains first name, last name, department, staff id, courses assigned, and any relavant attributes.
  • Course contains course name, course code, number of credits, teacher handling the course, list of students registered for the course.
  • Implement the necessary operations for each class.
  • Write a driver class to create 50 students 3 courses, 5 teachers.