Question

Script #2 – Leap Year Description:  Given a year, report if it is a leap year. Purpose:...

Script #2 – Leap Year

Description:  Given a year, report if it is a leap year.

Purpose: Learn the use of if statements.

Instructions:  Complete this assignment to make sure that you know how to use if statements in Powershell.

A leap year in the Gregorian calendar occurs:

  • on every year that is evenly divisible by 4
  • except every year that is evenly divisible by 100
  • unless the year is also evenly divisible by 400
  • Write a script that prompts a user for a year. After the users enters the year, inform the user if the year is a leap year.
  • Test the script to make sure it operates correctly.
  • Save the script in a .ps1 file, this will be one of the files that you submit to D2L
  • Take a print screen to show that the script is working correctly
  • Submit the script and print screen files.

Homework Answers

Answer #1
File: leapyear.ps1
Code:

$year = read-Host -Prompt 'Enter the year'
if($year % 4 -eq 0) {
        if ($year % 100 -eq 0) {
            if($year % 400 -eq 0) {
                write-host("This is Leap Year")
            }    
            else{
                write-host("Not a leap year")
            }
        }
        else {
            write-host("This is a leap year")
        }
    }    
else {
    write-host("Not a leap Year")
}

Know the answer?
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
Similar Questions
Instructions PowerShell Assignment #1 Objective: Learn basic Powershell scripting in Windows Setup: A Windows computer with...
Instructions PowerShell Assignment #1 Objective: Learn basic Powershell scripting in Windows Setup: A Windows computer with the latest Powershell environment installed Script #1 – Hello World! Description:  The classical introductory exercise: Just say "Hello, World!". Purpose: A "Hello, World!" program is traditionally used to introduce novice programmers to a programming language. It is also to make sure that the interpreter is installed correctly, and that the user understands how to use it. Instructions:  Complete this assignment to make sure that you know...
In this Java programming assignment, you will practice using selection statements to determine whether a given...
In this Java programming assignment, you will practice using selection statements to determine whether a given year in the past or future qualifies as a “Leap Year”. I. Design a class called LeapYear in a file called LeapYear.java. This class will hold the main method and the class method that we will write in this assignment. II. Write an empty public static void main(String[] args) method. This method should appear inside the curly braces of the LeapYear class. III. Write...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
The Business Case for Agility “The battle is not always to the strongest, nor the race...
The Business Case for Agility “The battle is not always to the strongest, nor the race to the swiftest, but that’s the way to bet ’em!”  —C. Morgan Cofer In This Chapter This chapter discusses the business case for Agility, presenting six benefits for teams and the enterprise. It also describes a financial model that shows why incremental development works. Takeaways Agility is not just about the team. There are product-management, project-management, and technical issues beyond the team’s control. Lean-Agile provides...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT