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....
answer in basic JAVA im in and INTRO JAVA CLASS Problem 2: Point of Sale System...
answer in basic JAVA im in and INTRO JAVA CLASS Problem 2: Point of Sale System The McDowell Restaurant chain has asked you to write a menu program for their new Fast-food service machines. Your program already prints the following menu like this: ********************************************************************** McDowell’s Restaurant ********************************************************************** Make your selection from the menu below: 1. Regular Hamburger $1.50 2. Regular Cheeseburger $1.75 3. Fish Sandwich $2.50 4. Half-pounder with cheese $2.75 5. French Fries $0.99 6. Large Soft Drink $1.25...
Java Recursion (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem....
Java Recursion (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem. Recursion may appear in various contexts and in different forms. For fast implementation, we should always aim at transforming recursions into a simpler form of computation. In this assignment, the task is to evaluate X(·), which is defined as follows:               |0,if m = 0 or n = 0               | X(m,n−1),if n is odd and m is even X(m,n) = | X(m−1,n),if m...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT