Question

Need comments added please. public class TenDate {    private int NMnth;    private int NDy;...

Need comments added please.

public class TenDate
{
   private int NMnth;
   private int NDy;
   private int NYr;
   private String [] MnthNm =
       {"", "January", "February", "March", "April", "May", "June", "July",
           "August", "September", "October", "November", "December"};
   private int [] MnthD =
       {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
   public TenDate()
   {
       NMnth = 1;
       NDy = 1;
       NYr = 1900;
   }
  
   public TenDate(int Mnth, int Dy, int Yr)
   {
       NMnth = Mnth;
       NDy = Dy;
       NYr = Yr;
   }
   public void SetDate(int Mnth, int Dy, int Yr)
   {
       NMnth = Mnth;
       NDy = Dy;
       NYr = Yr;
   }
   public int GetMonth()
   {
       return NMnth;
   }
   public void SetMonth(int IMnth)
   {
       if(IMnth > 0 && IMnth < 13)
           NMnth = IMnth;
       else
           NMnth= 1;
   }
   public int GetDay()
   {
       return NDy;
   }
   public int GetYear()
   {
       return NYr;
   }
   public void SetDay(int IDy)
   {
       if(IDy > 0 && IDy <= MnthD[NMnth])
           NDy= IDy;
       if(NMnth == 2 && IDy == 29 && LeapYr())
           NDy= IDy;
       else
           NDy = 1;
   }
   public void SetYear(int IYr)
   {
       NYr = IYr;
   }
   public boolean LeapYr()
   {
       if((NYr % 400 == 0) || (NYr % 4 == 0 && NYr % 100 != 0))
           return true;
       else
           return false;
   }
   public String DateString()
   {
       return(NMnth + "-" + NDy + "-" + NYr);
   }
   public int DyInMnth()
   {
       if(LeapYr() && NMnth == 2)
           return MnthD[NMnth] + 1;
       else
           return MnthD[NMnth];
   }
   public int ConvDOY()
   {
       int DOY = 0;
       for(int i = 1; i < NMnth; i++)
       {
           if(LeapYr() && i == 2)
               DOY += 29;
           else
               DOY += MnthD[i];
       }
       DOY += NDy;
       return DOY;
   }
   public int DyLft()
   {
       return 365 - ConvDOY();
   }
   public void NewDy(int Days)
   {
       int DLoop = Days / 30 + 3;
       int j, DoneDy = 0, DyInMnth, MinusDy;
       for(j = 1; j <= DLoop; j++)
       {
           if(DoneDy == 1)
               return;
           switch(NMnth)
       {
           case 9:
           case 4:
           case 6:
           case 11: DyInMnth = 30;
           break;
           case 2: DyInMnth = 28;
           if(NYr % 4 == 0)
           {
               if(NYr % 100 != 0)
                   DyInMnth = 29;
               else
                   if(NYr % 400 == 0)
                       DyInMnth = 29;
           }
           break;
           default: DyInMnth = 31;
       }
           MinusDy = DyInMnth - NDy;
           if(Days > MinusDy)
           {
               NMnth =++ NMnth % 13;

                if(NMnth == 0)
               {
                   NYr++;
                   NMnth++;
               }
               Days -= MinusDy;
               NDy = 0;
           }
           else
           {
               NDy += Days;
               DoneDy = 1;
           }
       }
   }
}

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Need comments added please. public class TenDate {    private int NMnth;    private int NDy;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • public class Date { private int month; private int day; private int year; /** default constructor...

    public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...

  • Programming Exercise 11-8 PROBLEM:The class dateType defined in Programming Exercise 6 prints the date in numerical...

    Programming Exercise 11-8 PROBLEM:The class dateType defined in Programming Exercise 6 prints the date in numerical form. Some applications might require the date to be printed in another form, such as March 24, 2019. Derive the class extDateType so that the date can be printed in either form. Add a member variable to the class extDateType so that the month can also be stored in string form. Add a member function to output the month in the string format, followed...

  • Take your MonthDay class from Assignment #6 and modify it to throw an IllegalArgumentException when the user of the class attempts to pass an invalid value for month and year. Make sure you have your...

    Take your MonthDay class from Assignment #6 and modify it to throw an IllegalArgumentException when the user of the class attempts to pass an invalid value for month and year. Make sure you have your main method(function) in a separate source file demonstrating use of the try/catch block to catch the IllegalArgumentException that the MonthDay class may throw in the event of an invalid month, or year. class MonthDays {    private int month;    private int year;    public MonthDays(int aMonth, int...

  • Hello, I have a bug in my code, and when I run it should ask the...

    Hello, I have a bug in my code, and when I run it should ask the user to enter the month and then the year and then print out the calendar for the chosen month and year. My problem with my code is that when I run it and I enter the month, it doesn't ask me for the year and it prints all the years of the month I chose. Please help! Code: #include "calendarType.h" #include <iostream> using namespace...

  • C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep...

    C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep track of a date, but it has very limited operations. Redefine the class dateType so that it can perform the following operations on a date, in addition to the operations already defined: Set the month. Set the day. Set the year. Return the month. Return the day. Return the year. Test whether the year is a leap year. Return the number of days in...

  • 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...

  • Write Junit Test for the following class below: public class Turn {    private int turnScore;    private Dice dice;    private boolean isSkunk;    private boolean isDoubleSkunk;    public Turn()    {...

    Write Junit Test for the following class below: public class Turn {    private int turnScore;    private Dice dice;    private boolean isSkunk;    private boolean isDoubleSkunk;    public Turn()    {        dice = new Dice();    }    public Turn(Dice dice) {        this.dice = dice;    }       public void turnRoll()    {        dice.roll();        if (dice.getDie1Value() == 1 || dice.getDie2Value() == 1 && dice.getLastRoll() != 2)        {            turnScore = 0;            isSkunk = true;        }        else if (dice.getLastRoll() == 2)        {            turnScore = 0;            isDoubleSkunk = true; }        else        {           ...

  • public class PQueue<E extends Comparable<E>> { private E[] elements; private int size; private int head; private...

    public class PQueue<E extends Comparable<E>> { private E[] elements; private int size; private int head; private int tail; Private int count;   } public void enqueue(E item) { if(isFull()){ return; } count++; elements[tail] = item; tail = (tail + 1) % size; } public E dequeue() { if(isEmpty()) return null; int ct = count-1; E cur = elements[head]; int index = 0; for(i=1;ct-->0;i++) { if(cur.compareTo(elements[head+i)%size])<0) cur = elements[(head+i)%size]; index = i; } } return remove((head+index%size); public E remove(int index) { E...

  • Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring;...

    Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring; public Person() {    this.numOffspring = 0; } public Person (int numOffspring) {    this.numOffspring = numOffspring; } public Person(String name, int birthYear, double weight, double height, char gender, int numCarryOn, int numOffspring) {    super(name, birthYear, weight, height, gender, numCarryOn);       if(numOffspring < 0) {        this.numOffspring = 0;    }    this.numOffspring = numOffspring; } public int getNumOffspring() {   ...

  • #include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;...

    #include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;        int dday;        int dyear;       public:       void setdate (int month, int day, int year);    int getday()const;    int getmonth()const;    int getyear()const;    int printdate()const;    bool isleapyear(int year);    dateType (int month=0, int day=0, int year=0); }; void dateType::setdate(int month, int day, int year) {    int numofdays;    if (year<=2008)    {    dyear=year;...

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
ADVERTISEMENT