Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm supposed to create a program that: 1. Prompts the user for the first day of class 2. Reads a string in the format mm/dd/yy,

I'm supposed to create a program that:

1. Prompts the user for the first day of class 2. Reads a string in the format mm/dd/yy, parses the string into 3 integers representing the month, day, and year. 3. Does the 2 steps above for the last day of class. 4. constructs 2 date objects fir the first and last day of class and sets the values of their instance variable using the data that was entered. 5. using appropriate methods of the date class, prints the first day of class and the last day of class as shown in the input.

Sample Run: Enter the first day of class -> 2/7/1900 Enter the last day of class -> 1/19/1901

First day of class: Wednesday, February 7, 1900 Last day of class: Saturday, January 19, 1901

This is the outline for this project

Date Class public class Date { // instance variables private int month, day, year;

// Returns the name of the month as a string (it does not return the // instance variable month) public String getMonth() { // Define an array of month names String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; // Then use month-1 as the index of the months array to get and return // the name of the month as a string ... } // Returns the instance variable day public int getDay() { ... } // Returns the instance variable year public int getYear() { ... } // Sets the instance variables month, day, year to the input parameters m, d, y public void setDate(int m, int d, int y) { ... } // Calculate and return the day of the week as a string public String getWeekDay() { // Define an array of weekday names, starting with Sunday String[] weekDays = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

// Implement the algorithm on the assignment sheet down through the step // to calculate day of the week // Hint: Replace mod with % // Hint: Use year/100 to get the first two didits of the year // Hint: Use year%100 to get the last two digits of the year ... // Use your variable for day of the week (for example, dayOfWeek) as the index // of the weekDays array to get and return the day of the week as a string ... } }

DateDemo Class

import java.util.Scanner;

public class DateDemo { public static void main(String[] args) { Scanner in = new Scanner(System.in); // Prompt the user for the first day of class. // Read a string in the format mm/dd/yyyy and parse the string into 3 integers // representing the month, day and year. System.out.print("Enter the first day of class -> "); String line = in.nextLine(); String[] nums = line.split("/"); int m1 = Integer.parseInt(nums[0]); int d1 = Integer.parseInt(nums[1]); int y1 = Integer.parseInt(nums[2]); // Do the dame thing for the last day of class ... // Construct two objects of the class Date for the first day of class // and the last day of class. ... // Call the setDate method on each of the two objects to set the values // of their instance variables using the data that was entered. ... // Call the getWeekDay method on each of the two objects to get the day of // the week as a string and store it in a string variable. ... // Call the getMonth method on each of the two objects to get the name of // the month as a string and store it in a string variable. ... // Print a blank line (System.out.println();) and then write two println // statements to print the first day of class and the last day of class // as shown in the output on the assgnment sheet. When you write the two // println statements, use the string variables defined above for the day // of the week and the name of the month, and call the getDay and getYear // methods on the objects to get the day and year as integers. ... }

Thank you so much!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

Ability to work comfortably in a team environment

Answered: 1 week ago