Question
Hello, I need help with a javascript program I am writing. Here is the assignments direction. 1. Write a class definition for Date, an object
Hello, I need help with a javascript program I am writing. Here is the assignments direction.
1. Write a class definition for Date, an object type that contains three integers, year, month and day. This class should provide two constructors. The first should take no parameters (default constructor) which initialises todays date. The second should take parameters named year, month and day (all variables as integer type) and use them to initialize the instance variables. (10 points)
Write a main method that creates a new Date object named current date which gives todays date and another object named birthday, the second object should contain your birthdate. If both dates are same print Today is your birthday, else print Somebodys Birthday with you day and Month of Birthday. (10 points)
Sample output if same day and month: 10 October - Today is your birthday
Sample output if different day and month: 10 October - Somebodys Birthday
Output in correct format (5 points)
Test the class using different dates give the tests as comments. (5 points)
Submit the debug window screen shots also as image file or word doc.(10 points)
Here is what I have so far with my program. However where I am stuck is if the string today and birthday are equal to each other they should run it is your birthday. However, no matter what it is running its someone else's birthday.
import java.util.Scanner; public class Birthday{ public static void main(String[] args) { int a,b,c; System.out.println("Enter your birth year: "); Scanner scnr = new Scanner(System.in); a=scnr.nextInt (); System.out.println("Enter your birth month in number form: "); b=scnr.nextInt (); System.out.println("Enter the day of the month you were born: "); c=scnr.nextInt (); Date birthday = new Date(a,b,c); Date today = new Date(); if(birthday.equals(today)){ System.out.println("Today is someone eles's birthday"); } else{ System.out.println("Today is your birthday"); } }
} class Date { private int year; private int month; private int day; public Date() { this.year = 2018; this.month = 2; this.day = 15;
}
public Date(int year, int month, int day) { this.year = year; this.month = month; this.day = day; } public String toString() { return month + " " + day;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started