






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Two separate Java programs. The first program demonstrates how to define a Date class and calculate the difference between two dates. The second program shows how to create an Apartment class, calculate maintenance charges for each flat, and display the final maintenance amount for all flats. Both programs include initialization and display methods.
What you will learn
Typology: Assignments
1 / 11
This page cannot be seen from the preview
Don't miss anything!
import java.util.Date; import java.util.Calendar; import java.time.LocalDate; import java.time.temporal.ChronoUnit; class date { int day, diff,year,month,d,m,y; String name_day; date d1,d2; static int monthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// Intialization void enterdate(int d,int m,int y) { day=d; month=m; year=y; int n1 = d1.y * 365 + d1.d; // Add days for months in given date for (int i = 0; i < d1.m - 1; i++) { n1 += monthDays[i]; } int n2 = d2.y * 365 + d2.d; for (int i = 0; i < d2.m - 1; i++) { n2 += monthDays[i]; } diff=n2 - n1; System.out.println("Date - " +diff); } // display method
class date { int Flat_number,floor_number; double length,breadth , area,maintenance_amount,total_maintenance_charge; // Intialization void enterdata(int a , double l ,double b ,int c) { Flat_number=a; length=l; breadth=b; floor_number=c; area=lb; maintenance_amount=area1.25; total_maintenance_charge=maintenance_amount+maintenance_amount/10; } // display method void displayInformation()
System.out.println("Flat number - " +Flat_number+ " Floor number - "+floor_number+" Length - "+length+" Breadth - "+breadth); System.out.println( "Total_maintenance_charge- " +total_maintenance_charge+" Rs"); System.out.println(); } } class Main { public static void main(String args[]) { date d1=new date(); date d2=new date(); date d3=new date(); date d4=new date(); date d5=new date(); date d6=new date(); date d7=new date(); date d8=new date(); date d9=new date(); date d10=new date(); // Initialization method call