Docsity

Java Programming: Calculating Date Differences and Apartment Maintenance Charges, Assignments of Java Programming

Toggle sidebar
bg1
1. Define a class date with ( day, month, year, name of
the day). Create two dates and perform the
following operations using appropriate methods .
• Display the name of the day after three days of
both the dates
• Find the difference between two dates. Display the
result as number of days.
• Display both dates in the date format.(
DD/MM/YYYY)
Code:
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};
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Java Programming: Calculating Date Differences and Apartment Maintenance Charges and more Assignments Java Programming in PDF only on Docsity!

1. Define a class date with ( day, month, year, name of

the day). Create two dates and perform the

following operations using appropriate methods.

• Display the name of the day after three days of

both the dates

• Find the difference between two dates. Display the

result as number of days.

• Display both dates in the date format.(

DD/MM/YYYY)

Code:

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

• Display the final maintenance amount for all flats.

• Display the flat number with the floor details who

paid Maximum maintenance amount.

Code:

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