Question

Complete the SpeedDating Class Write the method bodies for the 2 SpeedDating methods. Study the method...

  1. Complete the SpeedDating Class

Write the method bodies for the 2 SpeedDating methods. Study the method declarations and Javadoc comments so that you understand what each method is supposed to do.

To receive credit for a method, it must use one of the Java loops (your choice). Nested loops are not necessary.

  1. Write a Test Class for Your SpeedDating Class

Your test class will have a main method that does the following:

  1. Create a SpeedDating object
  2. Since 1971, Columbus Day has been fixed by law in the USA as the second Monday in October. Prompt the user to enter a year, call the discoverColumbusDay method, and print the Date object returned. Print the Date, properly labeled, in the main method, not in SpeedDating.

  3. Prompt the user to enter a day of the week as a String (e.g. Sunday, Monday, ..., Saturday). Call the auldLangSync method to get the next year in which New Year’s Day will fall on that day of the week. Print the year and the day of the week, properly labeled, in your main method and not in auldLangSync.

  1. Using The Date Class - Examples

The Date class is a class for manipulating dates. A Date object represents a date in the Gregorian calendar (i.e., dates after October 15, 1582). Any attempt to create an invalid date will throw an exception.

Creating Objects

Date d1 = new Date(month, day, year) ;   // initializes Date object d1 to int arguments month, day, and year.

// e.g.,

Date d1 = new Date(3,19,2020); // initializes d1 to March 19th, 2020

d1 = new Date(1,1,2021) ;     // d1 is now January 1, 2021

Accessor Methods

d1.getMonth()       // returns the month as int 1..12

d1.getDay()        // returns the day of the month, as an int

d1.getYear()     // returns the year

d1.getMonthName() // returns the month as a String (e.g. “March") d1.getDayOfWeek() // returns the day of the week as a string (e.g. // “Friday”)

d1.equals(d2)     // returns true if d1 is the same date as d2 // otherwise, returns false

d1.getShortDate() // returns the date as mm/dd/yyyy (e.g. 3/19/2020)

d1.getMediumDate() // returns the date in the form of “March 19, 2020”

d1.getLongDate() // returns the date in the form of // “Thursday, March 19th, 2020”

Mutator Methods

Date d = new Date(1,1,2020) ; // d is January 1, 2020 (a leap year)

d.next() ;                     // d is January 2, 2020

d.previous() ;                 // d is January 1, 2020

d.add(31) ;                 // d is February 1, 2020

d.subtract(32) ;              // d is December 31, 2019

d.next() ;                    // d is January 1, 2020

d = new Date(3,1,2020) ;     // d is March 1, 2020

d.previous() ;                 // d is now February 29, 2020

public class SpeedDating
 {
    // Note: this class has no instance variables!
        
    /**
     * Create a SpeedDating object
     */
     public SpeedDating()
     {}    
     // Note: The constructor takes no parameters.  This is known as
     // a "default" constructor.  This one also happens to have an empty body,
     // but that is not true for all default constructors
     
    /**
     * Computes and returns the Date of Columbus Day in the USA - the second
     * Monday in October - for a given year   
     * @param year the year for which to compute Columbus Day
     * @return the Date of Columbus Day for the given year
     */
     public Date discoverColumbusDay(int year)
     {
        // bogus return value so program skeleton will compile and run - 
        // replace it with the correct Date and delete this comment
        return null ;
     }
                
     /**
      * Computes and returns the next year - beginning with 2021 - in which
      * New Year's Day will fall on a specified day of the week
      * @param dayOfWeek the day of the week 
      * @return the year in which New Year's Day will fall on dayOfWeek
      */
      public int auldLangSynch(String dayOfWeek) 
      {
        // bogus return value so program skeleton will compile and run - 
        // replace it with the correct number and delete this comment
        return -999 ;
      }
 }
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The given statements in the question appear incomplete but you can use following method to calculate Columbus day of the given input year by the user.

 public class SpeedDating { 
 public static void main(String[] args) {   int nYear;
     Scanner scanner = new Scanner(System.in);
     System.out.print("Enter year for which Columbus day needs to be calculated: ");
     nYear = scanner.nextInt();
 public Date discoverColumbusDay(int nYear)
      { 
     int nX;
     int nMonth = 9; // October, because it is on the second Monday of the month October.
     Date dtD;
     dtD = new Date(nYear, nMonth, 1);
     nX = dtD.getDay();
     switch(nX)
         {
         case 0 : // Sunday
         return new Date(nYear, nMonth, 9);
         case 1 : // Monday
         return new Date(nYear, nMonth, 15);
         case 2 : // Tuesday
         return new Date(nYear, nMonth, 14);
         case 3 : // Wednesday
         return new Date(nYear, nMonth, 13);
         case 4 : // Thursday
         return new Date(nYear, nMonth, 12);
         case 5 : // Friday
         return new Date(nYear, nMonth, 11);
         default : // Saturday
         return new Date(nYear, nMonth, 10);
         }

System.out.print("Date in which Columbus day will fall is",+dtD);

}

}

}

Add a comment
Know the answer?
Add Answer to:
Complete the SpeedDating Class Write the method bodies for the 2 SpeedDating methods. Study the method...
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
  • Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java,...

    Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java, which will contain code that utilizes your Date.java class. You will submit both files (each with appropriate commenting). A very similar project is described in the Programming Projects section at the end of chapter 8, which you may find helpful as reference. Use (your own) Java class file Date.java, and a companion DateClient.java file to perform the following:  Ask user to enter Today’s...

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

  • Write a class called Date that represents a date consisting of a year, month, and day....

    Write a class called Date that represents a date consisting of a year, month, and day. A Date object should have the following methods: public Date(int year, int month, int day) Constructs a new Date object to represent the given date. public void addDays(int days) Moves this Date object forward in time by the given number of days. public void addWeeks(int weeks) Moves this Date object forward in time by the given number of seven-day weeks. public int daysTo( Date...

  • Use Java and creat proper classes to finish this problem Write a class called Date that...

    Use Java and creat proper classes to finish this problem Write a class called Date that represents a date consisting of a year, month, and day. A Date object should have the following methods: public Date(int year, int month, int day) Constructs a new Date object to represent the given date. public void addDays(int days) Moves this Date object forward in time by the given number of days. public void addWeeks(int weeks) Moves this Date object forward in time by...

  • In Java You are to write a program that determines the day of the week for...

    In Java You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program: /** Interface for Date objects to be used by the Year3000 driver program. @author Jon Sorenson */ public interface DateInterface { /** @return the day of the month (1-31) */ public int getDay(); /** @return the day of...

  • General Requirements: • You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand; • You sho...

    General Requirements: • You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand; • You should create identifiers with sensible names; • You should make comments to describe your code segments where they are necessary for readers to understand what your code intends to achieve. • Logical structures and statements are properly used for specific purposes. Objectives This assignment requires you to write...

  • Zeller's congruence is an algorithm developed to calculate the day of the week. Write a program...

    Zeller's congruence is an algorithm developed to calculate the day of the week. Write a program that prompts the user to enter a year, month, day of month and it displays the name of the week. Here is my source code. I need it broke down into a flowchart. public static void main(String[] args) {        //all variables are initialized to 0, because local variables require at least an initial value before use        Scanner input = new...

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

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

  • Below are the Car class and Dealership class that I created In the previous lab import...

    Below are the Car class and Dealership class that I created In the previous lab import java.util.ArrayList; class Car { private String make; private String model; private int year; private double transmission; private int seats; private int maxSpeed; private int wheels; private String type; public Car() { } public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) { this.make = make; this.model = model; this.year = year; this.transmission = transmission; this.seats =...

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