In ruby Write a program that prompts the user to enter a year and first day of the year, and displays the calendar table of that year. For example, if the user entered the year 2019, and 2 for Tuesday, January 1, 2019, your program should display the calendar for each month in the year 2019.
Firstly let us get the input by using the below modules.
require 'date'
puts "Enter the year"
iyear = gets
puts "Enter the day"
iday = gets
Now let's pass the input values and build the program. I recommend you to use Visual Studio Code IDE to build the solution. Please import the required modules and debug the code.
Replace the date input from the input commands above. This can be customized based on your output.
require 'date'
date = Date.new(2019, 1, 1)
daysOfWeek = Date::ABBR_DAYNAMES.map { |x| " #{x}"}
monthName = Date::MONTHNAMES[date.month]
yearMonthStr = "#{date.year} - #{monthName}"
cellLength = daysOfWeek.first.length
lineLength = cellLength * daysOfWeek.length
padding = lineLength / 2 - yearMonthStr.length / 2
puts yearMonthStr.rjust(yearMonthStr.length + padding, '
')
puts daysOfWeek.join("")
currWeekDay = date.wday
currMonth = date.month
prevPadding = "".ljust( currWeekDay * cellLength, ' ')
while date.month == currMonth
while currWeekDay < daysOfWeek.length and date.month == currMonth
dayStr = date.day.to_s.rjust(cellLength, ' ')
cell = "#{prevPadding}#{dayStr}"
prevPadding = ""
print cell
date = date + 1
end
currWeekDay = 0
puts
end
Please let me know if you need any clarifications.Happy
Learning!
In ruby Write a program that prompts the user to enter a year and first day...
Write a program named CheckMonth2 that prompts a user to enter a birth month and day. Display an error message that says Invalid date if the month is invalid (not 1 through 12) or the day is invalid for the month (for example, not between 1 and 31 for January or between 1 and 29 for February). If the month and day are valid, display them with a message. For example, if the month entered is 2, and the day...
Write a C# program that prompts a user to enter a birth month and day. Display an error message if the month is invalid (not 1 through 12) or the day is invalid for the month (for example, not between 1 and 31 for January or between 1 and 29 for February). If the month and day are valid, display them with a message.
JAVA Write a program that prompts the user to enter a year and the first three letters of a month name (with the first letter in uppercase) and displays the number of days in the month. If the input for month is incorrect, display a message as shown in the following sample run. SAMPLE RUN 1: Enter a year: 2001 Enter a month: Jan Jan 2001 has 31 days SAMPLE RUN 2: Enter a year: 2016 Enter a month: Feb...
Write a program that prompts the user to enter the date in mm/dd/yyyy format. The program should use a single input statement to accept the date, storing each piece of the date into an appropriate variable. Demonstrate that the input was obtained correctly by outputting the month, day, and year to the screen. Sample output: Enter (date (mm/dd/yyyy): 02/08/2011 Month entered: 2 Day entered: 8 Year entered: 2011 Challenge: Although the user entered 02, C++ drops the 0 as insignificant...
Write a program in visual c# program named CheckMonth that prompts a user to enter a birth month. If the value entered is greater than 12 or less than 1, display an error message; otherwise, display the valid month with a message such as 3 is a valid month.
Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs: 1) The year for which you are generating the calendar. 2) The day of the week that January first is on, you will use the following notation to set the day of the week: 0 Sunday 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday Your program should...
Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. The program prompts the user for two inputs: 1) The year for which you are generating the calendar. 2) The day of the week that January first is on, you will use the following notation to set the day of the week: ...
Program must be in Python 3.
Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...
(InputMismatchException) and (ArrayIndexOutOfBoundsException): Using the two arrays shown below, write a program that prompts the user to enter an integer between 1 and 12 and then displays the months and its number of days corresponding to the integer entered. 1. Your program should display “Wrong number - Out of Bounds” if the user enters a wrong number by catching ArrayIndexOutOfBoundsException. 2. Also the program should display “Mismatch – not a number” if the user enters anything other than an integer...
(Python Programming)Write a Python program that prompts the user to enter a list of words and stores in a list only those words whose first letter occurs again within the word (for example, 'Baboon'). The program should display the resulting list.