Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

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

  • What is the difference between the two dates displayed in the first Java program?
  • How is the Apartment class defined in the second Java program?
  • Which flat pays the maximum maintenance amount in the second Java program?
  • What is the total maintenance charge for each flat in the second Java program?
  • How is the Date class defined in the first Java program?

Typology: Assignments

2020/2021

Uploaded on 02/22/2022

arun-kumawat-20bce1226
arun-kumawat-20bce1226 🇮🇳

5 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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