Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java program Q1. [5 pts] Write class Citizen which has Five instance variables: - name: String - civillD: String - dateOfBirth: Date - expirationDate: Date

java program image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Q1. [5 pts] Write class Citizen which has Five instance variables: - name: String - civillD: String - dateOfBirth: Date - expirationDate: Date - currentDate: Date This is static/final and set to today's date. Class Date is provided for you, so you do not need to implement it. Your Citizen class should have: - A constructor that initializes the name, civillD, dateOfBirth, expirationDate. - A second constructor that takes 0 arguments and initializes name and civillD to " N/A"; and initializes the dateOfBirth (day, month, and year) (of class Date) to 1,1,2000, respectively, and finally the expirationDate to 1,1,3000. - A third constructor that takes only name and civillD, initializes the dateOfBirth day, month, and year to 1,1,2000, and initializes expirationDate to 1,1, 3000 respectively. - set and get methods for all your instance variables with valid values. The class also should include methods that: 1. checkExpiration: check the object's expiration has occurred (need to check current date for this) and print a statement that alerts the user. Write another class called Citizentest that includes the main method. Your main should do the following: - Print the Current Date at the top of the console. - Create an array of type Citizen with a size of 5. - Create each object of the array manually and initialize it as follows: Array element 0 : When you create the object, pass to the constructor 0 parameters Array element 1: pass to the constructor only: "Ahmed" "299060700244" Array element 2: pass to the constructor: "Sara", 298060300744" 6,3,1998,6,3,2026 Array element 3: pass to the constructor: "Noura", "290170500284", 17,5,1990, 18,5,2030 Array element 4: pass to the constructor: "Ali", "295200100994",20,1,1995, 21,1,2020 - Finally, use a for loop to go through each element of the array and print the name and date of birth (use the method formattedDate from the class Date to get the date of birth in a formatted string). int: use "import java.time.LocalDateTime;" and the variable of the class called ocalDateTime" assigned to "LocalDateTime.now()" with methods .getDayOfMonth(), ..getMonthValue(), ..getYear()" to get the ay/month/year format for today's date. our output should look exactly as shown below: dit Format View Help rt java.time. LocalDateTime; ic class Date \{ private int day; private int month; private int year; / ========= Constructor ================ public Date (int day, int month, int year) \{ if ( day 31) \{ System.out.println("Error: Day out of range") this. day =1; \} else this. day = day; if ( month 12) \{ System.out.println("Error: Month out of range" this. month =1; \} else this. month = month; if (year =2000; 3 else this year = year; \}//end of constructor public string formattedDate() \{ return String. format("\%02d/\%02d/\%d", getDay(), getMonth(), getYear () \}//end of formated Date lend of class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago