Java Practice Exercise – Classes and methods

  • Write a Java program that determines the number of days in a month
  • Write a Java program that prompts the user for an integer and then prints out all prime numbers up to that Integer
  • Develop the Internal mark calculation system based on the attendance percentage using Java. Get the student name, register number, total number of working days in the semester and Number of days present. Calculate attendance percentage of the students and award attendance mark based on the following condition.
    • Attendance percentage >=90 – 5 Marks
    • Attendance percentage >=80 and < 90 – 4 Marks
    • Attendance percentage >=75 and < 80 – 3 Marks
    • Attendance percentage < 75  – 0 Marks
  • Prepare Electricity bill using Java. Create a class with the following member: Consumer number, Consumer name, previous month reading, current month reading, type of EB connection. Calculate the domestic connection bill amount using the following tariff:
    • First 100 units – Rs. 1.50 per unit
    • 101-200 units  – Rs. 3 per unit
    • 201- 500 units – Rs. 4.50 per unit
    • >501 units       – Rs. 7 per unit
  • Write a java program to perform the following functions using classes, objects and constructors where essential.
    • Get as input the marks of 5 students in 5 subjects
    • Calculate the total and average
    • Print the formatted results on the screen
  • Define a class named COMPLEX for representing complex numbers that contains necessary data members and member functions. A complex number has the general form a + ib, where a is the real part and b is the imaginary part (i stands for imaginary). Include methods for all the four basic arithmetic operators
  • Create a Java class Shape with constructor to initialize the one parameter “dimension”. Now create three subclasses of Shape with following methods:
    • “Circle” with methods to calculate the area and circumference of the circle with dimension as radius.
    • “Square” with methods to calculate the area and length of diagonal of square with dimension as length of one side.
    • “Sphere” with methods to calculate the volume and surface area of sphere with dimension as radius of sphere. Write appropriate main method to create object of each class and test every method
  • Develop a Java application to generate Electricity bill. Create a class with the following members: Consumer no., consumer name, previous month reading, current month reading, type of EB connection (i.e domestic or commercial). Compute the bill amount using the following tariff,
    • If the type of the EB connection is domestic, calculate the amount to be paid as follows:
      • First 100 units-Rs.1 per unit
      • 101-200 units – Rs. 2.50 per unit
      • 201 -500 units – Rs. 4 per unit
      • 501 units – Rs. 6 per unit
    • If the type of the EB connection is commercial, calculate the amount to be paid as follows:
      • First 100 units – Rs. 2 per unit
      • 101-200 units – Rs. 4.50 per unit
      • 201-500 units-Rs.6 per unit
      • 501 units – Rs. 7 per unit
  • Write a Java program to read 5 subject marks of a student and calculate the total and grade. The grade system is as follows
Letter Grade
Grade points
Marks Range
O (Outstanding)
10
91 – 100
A+ (Excellent)
9
81 – 90
A (Very Good)
8
71 – 80
B+ (Good)
7
61 – 70
B (Average)
6
50 – 60
RA
0
< 50