Question

In: Computer Science

This is just a very basic program/problem in Java I'm looking for some second opinions on....

This is just a very basic program/problem in Java I'm looking for some second opinions on.

1. Ask the user for a year input (positive integer - should be between 1500 and 2019, inclusive).

2. If the year input is not between 1500 and 2019, do not check for leap year, rather print that this year cannot be checked.

3. Take a year input from the user (should be between 1500 and 2019)

4. If the input year is a leap year, print that year is a leap year; otherwise, print that the year is not a leap year.

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new java program with name "LeapYear.java" is created, which contains following code.

LeapYear.java :

import java.util.*;//import package
//Java class
public class LeapYear {
   // entry point , main() method
   public static void main(String[] args) {
       // creating object of Scanner class
       Scanner sc = new Scanner(System.in);
       // asking user to enter year
       System.out.print("Enter year between 1500 and 2019 : ");
       int year = sc.nextInt();// reading year
       // checking year
       if (year > 1500 && year < 2019) {
           // checking leap year
           if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
               // print message when year is leap year
               System.out.println(year + " is leap year.");
           } else {
               // print message when year is not leap year
               System.out.println(year + " is not leap year.");
           }
       } else {
           // print message if invalid year is entered
System.out.println("Year cannot be checked.Enter year between 1500 and 2019");
       }

   }

}

======================================================

Output : Compile and Run LeapYear.java to get the screen as shown below

Screen 1 :LeapYear.java, Screen when year is not in the range

Screen 2 :LeapYear.java, Screen showing when year is leap

Screen 3 :LeapYear.java, Screen showing when year is not leap

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

Basic JAVA Question When we try to run this program, a problem occurs. What is this...
Basic JAVA Question When we try to run this program, a problem occurs. What is this problem called? And why does this problem occur here? public class Main {    public static void main(String[] args) {    PhoneNumber pn = new PhoneNumber();        System.out.println(pn.isTollFree());    } } class PhoneNumber { String number;    public boolean isTollFree() { return number.charAt(1) == '8'; } }
We are doing a lab on Grignard Reactions, i'm just looking to verify the system by...
We are doing a lab on Grignard Reactions, i'm just looking to verify the system by which to find this information: Add about 2 mmol Mg powder, recording the mass to the nearest milligram. In this experiment, magnesium will be the limiting reactant because a 5% excess of bromobenzene will be used. Using your mass of Mg, determine the mass of bromobenzene to be used, being sure to calculate a 5% molar excess.
I'm just looking for a better understanding of the process of what happens in each part...
I'm just looking for a better understanding of the process of what happens in each part that follows. What information should I include to help with understanding the question? In Part A, I'm asking about how a neutrophil chasing a bacterium detects and moves towards the bacterium. Then, how does the neutrophil change its course. Processes that I need help understanding and would like included in the explanation if possible are listed after the question. Part B asks how a...
(Intro/Basic) JAVA Write a small program that gets some numbers as command-line arguments and finds the...
(Intro/Basic) JAVA Write a small program that gets some numbers as command-line arguments and finds the maximum of those numbers. You can assume that the user will provide some command-line arguments when running the program (so you don’t have to worry about what to do if the user doesn’t provide any arguments -- that won’t happen). Also, you can assume that all the command line arguments will be floating-point numbers, i.e., numbers with a decimal point, like 2.95.
Needs to be in basic JAVA Write a program that does basic encrypting of text. You...
Needs to be in basic JAVA Write a program that does basic encrypting of text. You will ask the user the filename of a text file that contains a few sentences of text. You will read this text file one character at a time, and change each letter to another one and write out to an output file. The conversion should be done a -> b, b->c , … z->a, A->B, B->C, …. Z->A. This means just shift each letter...
Write the program in java Write a program that does basic encrypting of text. You will...
Write the program in java Write a program that does basic encrypting of text. You will ask the user the filename of a text file which contains a few sentences of text. You will read this text file one character at a time, and change each letter to another one and write out to an output file. The conversion should be done a -> b, b->c , … z->a, A->B, B->C, …. Z->A. This means just shift each letter by...
Making a program in Python with the following code types. I'm very confused and would love...
Making a program in Python with the following code types. I'm very confused and would love the actual code that creates this prompt and a brief explanation. Thanks! A comment on the top line of your program containing your name. A comment on the second line containing your section number. A comment on the third line containing the date. A comment on the fourth line containing your email address. A comment with the lab number and purpose of this lab....
Java I'm trying to create a program that replicates a theater ticket reservation system. I have...
Java I'm trying to create a program that replicates a theater ticket reservation system. I have a Seat class with members row(integer), seat(character) and ticketType(character). Where a ticket type can be 'A' adult, 'C' child, 'S' senior, or '.' recorded as empty. I have a Node generic class that points to other nodes(members): up, Down. Left, Right. It also has a generic payload. Lastly, I have an Auditorium class which is also generic. its member is a First Node<T>. As...
JAVA Please put detailed comments as well explaining your program. I'm in a beginning programming class,...
JAVA Please put detailed comments as well explaining your program. I'm in a beginning programming class, and so please use more basic techniques such as if else statements, switch operators, and for loops if needed. http://imgur.com/a/xx9Yc Pseudocode for the main method: Print the headings             Print the directions             Prompt for the month             If the month is an integer       (Hint: Use the Scanner class hasNextInt method.)                         Input the integer for the month                         Get the...
It's been a while since I've done this type of chemistry so I'm just very lost...
It's been a while since I've done this type of chemistry so I'm just very lost trying to figure out these problems. Could someone please help and if you could write out the equations or give an explanation as to how you came up with your answers. Thank you in advance! 1. You have 50 mL of a buffer solution that is 0.15 M in HA and 0.25 M in A-. Calculate the pH of the solution after you add...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT