Question

My values are not storing into my object and I keep returning zero. please explain my...

My values are not storing into my object and I keep returning zero. please explain my mistake thanks

public class CalanderDate {

int year = 0 ;
int day = 0;
int month= 0;
  
public static void main(String[] args) {
CalanderDate date;
date = new CalanderDate( 1, 10 ,1999);
System.out.print(date);
}
  
  
  

public CalanderDate(int month, int day , int year ) {
if (month < 1){
month = 1;
}
if (month> 12){
month = 12;
}
if (day < 1){
day = 1;
}
if (year < 1752){
year = 1752;
}
  
}
  
  


int getYear() {
return year;
}

int getMonth() {
return month;
}

  
int getDay() {
return day;
}
void setDate (int year, int month, int day) {
this.day = day;
this.year = year;
this.month = month;
}
String getMonthAsString(){
String[] strArr = new String[] {"jan", "feb","mar", "apr", "may","jun", "jul",
"aug", "sep","oct","nov","dec"};
String str = strArr.toString();
return str;
}
public String toString() {
String dayS = Integer.toString(day);
String monthS = Integer.toString(month);
String yearS = Integer.toString(year);
return dayS + monthS + yearS;
}   
public CalanderDate tomorrow() {
CalanderDate obj= new CalanderDate(year, month , day);
  
if (this.getDay() < this.daysInMonth() ){
++this.day;
}
else if (this.getDay() == this.daysInMonth() && this.getMonth() < 12){
++this.month;
this.day = 1;
}
else if (this.getMonth() == 12){
++this.year;
this.month = 1;
this.day= 1;
}
return obj;
}
public boolean equals (Object o){
if (o instanceof CalanderDate){
CalanderDate obj = (CalanderDate) o;

return this.year == obj.year && this.month == obj.month && this.day == obj.day;
}
else {
return false;
}
}

public int daysInMonth(){
int [] months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
/* if (this.isLeapYear()){
months[1] = 29;
}*/
if (this.month == 1){
return months[0];
}
else{
return months[this.month - 1];
}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class CalanderDate {

  int year = 0 ;
  int day = 0;
  int month= 0;

  public static void main(String[] args) {
    CalanderDate date;
    date = new CalanderDate( 1, 10 ,1999);
    System.out.print(date);
  }

  public CalanderDate(int month, int day , int year ) {
    setDate(year,month,day);
  }

  int getYear() {
    return year;
  }

  int getMonth() {
    return month;
  }

  int getDay() {
    return day;
  }

  void setDate (int year, int month, int day) {
    this.day = day;
    this.year = year;
    this.month = month;
  }
  
  String getMonthAsString(){
    String[] strArr = new String[] {"jan", "feb","mar", "apr", "may","jun", "jul",
      "aug", "sep","oct","nov","dec"};
    String str = strArr.toString();
    return str;
  }
  
  public String toString() {
    String dayS = Integer.toString(day);
    String monthS = Integer.toString(month);
    String yearS = Integer.toString(year);
    return dayS + monthS + yearS;
  }
  
  public CalanderDate tomorrow() {
    CalanderDate obj= new CalanderDate(year, month , day);

    if (this.getDay() < this.daysInMonth() ){
      ++this.day;
    }
    else if (this.getDay() == this.daysInMonth() && this.getMonth() < 12){
      ++this.month;
      this.day = 1;
    }
    else if (this.getMonth() == 12){
      ++this.year;
      this.month = 1;
      this.day= 1;
    }
    return obj;
  }
  
  public boolean equals (Object o){
    if (o instanceof CalanderDate){
      CalanderDate obj = (CalanderDate) o;

      return this.year == obj.year && this.month == obj.month && this.day == obj.day;
    }
    else {
      return false;
    }
  }

  public int daysInMonth(){
    int [] months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
/* if (this.isLeapYear()){
months[1] = 29;
}*/
    if (this.month == 1){
      return months[0];
    }
    else{
      return months[this.month - 1];
    }
  }
}

1011999

Add a comment
Know the answer?
Add Answer to:
My values are not storing into my object and I keep returning zero. please explain my...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to create a Java class file and a client file that does the following:  Ask user to enter Today’s date in the fo...

    I need to create a Java class file and a client file that does the following:  Ask user to enter Today’s date in the form (month day year): 2 28 2018  Ask user to enter Birthday in the form (month day year): 11 30 1990  Output the following: The date they were born in the form (year/month/day). The day of the week they were born (Sunday – Saturday). The number of days between their birthday and today’s...

  • I'm having trouble with the daysSince() Method in bold at the end of the program public...

    I'm having trouble with the daysSince() Method in bold at the end of the program public class Date { static final int [] daysInMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; private int day, month, year; public Date() { day = 1; month = 1; year = 2000; } public Date(int d, int m, int y) { day = d; month = m; year = y; } public Date (String s) { setDate(s);...

  • Problem Description: Expand on 2 by implementing Insertion Sort and displaying the dates sorted after adding...

    Problem Description: Expand on 2 by implementing Insertion Sort and displaying the dates sorted after adding one to all dates. Run your code using the attached input files outputlong.txtoutputlab3.txt. Please note that your the dates that are sorted will be the ones after 1 day has been added to them. Sample Output: (green is user input) Run #2 using sample file outputlab3.txt Enter name of file to import or the word null to bypass: outputlab3.txt How many assessments in this...

  • Need help figuring out what would be the all 12 days output public class Date {...

    Need help figuring out what would be the all 12 days output public class Date {    private int day;    private int month;    private int year;       private static int tracker;       public Date()    {        this(1, 1, 2000);        System.out.println("4");    }       public Date(int year)    {        this(1, 1, year);        System.out.println("3");    }       public Date(int month, int year)    {        this(1, month,...

  • this needs to be in Java: use a comparator class which is passed into the sort...

    this needs to be in Java: use a comparator class which is passed into the sort method that is available on the ArrayList. import java.util.Scanner; public class Assign1{ public static void main(String[] args){ Scanner reader = new Scanner (System.in); MyDate todayDate = new MyDate(); int choice = 0; Library library = new Library(); while (choice != 6){ displayMainMenu(); if (reader.hasNextInt()){ choice = reader.nextInt(); switch(choice){ case 1: library.inputResource(reader, todayDate); break; case 2: System.out.println(library.resourcesOverDue(todayDate)); break; case 3: System.out.println(library.toString()); break; case 4: library.deleteResource(reader,...

  • Java Programming: Hi, I need help Modifying my code that will throw an IllegalArgumentException. for the...

    Java Programming: Hi, I need help Modifying my code that will throw an IllegalArgumentException. for the following data entry error conditions: A number less than 1 or greater than 12 has been entered for the month A negative integer has been entered for the year utilizes a try and catch clause to display an appropriate message when either of these data entry errors exceptions occur. Thank you let me know if you need more info import java.util.*; //Class definition public...

  • java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the...

    java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the below classes: public class Date {    private String month;    private String day;    private String year;    public Date(String month, String day, String year) {       this.month = month;       this.day = day;       this.year = year;    }    public String getMonth() {       return month;    }    public String getDay() {       return day;    }    public String...

  • Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender {...

    Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }    public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...

  • Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then...

    Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then generate their documentation. Examine the documentation to see the logic used in creating each class. (Code given below) import java.util.ArrayList; import java.util.Iterator; class Calendar { private Year year; public Calendar() { year = new Year(); } public void printCalendar() { year.printCalendar(); } } class Year { private ArrayList<Month> months; private int number; public Year() { this(2013); } public Year(int number) { this.number = number;...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT