Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mns;
- import java.util.Scanner;
- public class Date {
- private int monthdate;
- private int daydate;
- private int yeardate;
- public Date (int month, int day, int year) {
- monthdate = month;
- daydate = day;
- yeardate = year;
- }
- public void setMonth (int month) {
- monthdate = month;
- }
- public int getMonth() {
- return monthdate;
- }
- public void setday (int day) {
- daydate = day;
- }
- public int getDay() {
- return daydate;
- }
- public void setYear (int year ) {
- yeardate = year;
- }
- public int getYear() {
- return yeardate;
- }
- public void displayDate () {
- System.out.printf ("%d/%d/%d\n", getMonth(), getDay(), getYear());
- }
- public static void main (String [] args) {
- Date display = new Date (0,0,0);
- Scanner inp = new Scanner (System.in);
- int month;
- int day;
- int year;
- System.out.print("Enter the month, day and year:");
- month = inp.nextInt();
- display.setMonth(month);
- day = inp.nextInt();
- display.setday(day);
- year = inp.nextInt();
- display.setYear(year);
- System.out.print("The Date is: ");
- display.displayDate();
- System.out.print("Enter a new year:");
- year = inp.nextInt();
- display.setYear(year);
- System.out.print("The New Date is: ");
- display.displayDate();
- System.out.print("Enter a new day:");
- day = inp.nextInt();
- display.setday(day);
- System.out.print("The New Date is: ");
- display.displayDate();
- System.out.print("Enter a new month:");
- month = inp.nextInt();
- display.setMonth(month);
- System.out.print("The New is: ");
- display.displayDate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment