Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

I need help with this java program. My code will be below the instructions. Start with the Birthday program discussed in class and available on

I need help with this java program. My code will be below the instructions.

Start with the Birthday program discussed in class and available on the website, and make these changes:

  • Change the array startsOn with the values when the months start for this year (Sunday is counted 0).
  • The original program has three private data members; add two more: the number of the month (1..12) and the day of the year (1..365).
  • Change the CalculateDay function to initialize the number of the month after it searches for the month-string.
  • Add a public static nal array of integers for the number of days in each month.
  • Write a function that will use the new array and data member to calculate the day of the year.
  • Be sure you test January 1 and December 31.
  • Sample output:

Birthday Day Calculator, Welcome!

Months are: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

Please enter your birth month and date:

May 20

Your May 20 birthday is on Wednesday this year

it is day 140 of the year

package comexample; import java.util.Scanner; public class Birthday {

//----------------------------------------------------------------------------- public static final String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; public static final String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; public static final int[] startsOn = {2, 5, 5, 1, 3, 6, 1, 4, 0, 2, 5, 0, };

// The collection of data members stores the STATE of an object. // Data members of a class are normally private. Document each one. private String month; // 3-letter abbreviation for the month. private int date; // Will be 1..31 private String day; // The day of the week.

//---------------------------------------------------------------------- // Compute a new random value for the die. // Postcondition: the return value is between 1 and faces. Birthday( String m, int d){ month = m; date = d; calculateDay(); }

//---------------------------------------------------------------------- private void calculateDay() { int found, k, answer; for(k=0; k<12; ++k) { if (months[k].equals(month)) break; } found = k; if (found == 12) System.out.println("Your month name was not a valid 3-letter abbreviation."); else { answer = (startsOn[k] + date -1)%7; day = days[answer]; } }

//------ A get function gives read-only access to a private data member. public String getDay(){ return day; }

//---------------------------------------------------------------------- // Define toString for every class. // Return a string that reports the state of the class. // Used for debugging. public String toString(){ return month +" " + date ; }

//---------------------------------------------------------------------- public static void main( String[] args ) { int date; String monthname; Scanner sc = new Scanner( System.in );

System.out.println(" Birthday Day Calculator, Welcome!"); System.out.print ("Months are: "); for( String s : months) System.out.print( s+" " );

System.out.println(" Please enter your birth month and date:"); monthname = sc.next(); date = sc.nextInt(); Birthday b = new Birthday (monthname, date);

System.out.printf ( "Your %s birthday is on %s this year ", b.toString(), b.getDay() ); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions