Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java question Loop Chrome File Edit View History Bookmarks People Window Help 99

ID: 3875983 • Letter: J

Question

Java question Loop

Chrome File Edit View History Bookmarks People Window Help 99% C) Tue 11:11 PM a E (5) Major Nintendo Switch 3rd H Upload Assignment: Program x y D Program 1.pdf ×e Home I Chegg.com eduardo Secure l https://blackboard.kean .edu/bbcswebdav/pid-717865-dt-content-rid-2744692-1/courses/18SPCPS-2231-06/Program.pdf Write a Java Class that computes and prints all the leap years between a starting and ending year. A year is a leap year if it meets one of the two conditions below A year is a leap year if it is divisible by 4 and not divisible by 100 (For example, 1980) A year is a leap year if it is divisible by 400 (for example, 2000) Write a program that does the following: 1. Prompts the user for the starting year 2. Prompts the user for the ending year 3. Prints all the leap years between the start year and the ending year separated bya space 4. Ten years or less will be printed on each separate line of output 5. At the end, the program will print the total number of leap years between the start and end years entered by the user Enter the starting year 1900 Enter the ending year 2000 1904 1908 1912 1916 1920 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960 1964 1968 1972 1976 1980 1984 1988 1992 1996 2000 There are 25 years between 1900 and 2000 Use a good sample of values to test your program. This site might be useful for testing:

Explanation / Answer

* ArrayList provides methods to manipulate the size of the array that is used internally to store the List.
* The java.util.List Interface. The List interface specifes the methods that can be used with any implementing class, such as ArrayList.
* Scanner is a class in java.util package used for obtaining the input of the primitive types like int, double etc. and strings.
* List is an interface, not a class, and interfaces themselves cannot be instantiated.
* But ArrayList implements the interface List, so you can assign an instance of ArrayList to a variable of type List.
* The resulting object has all the properties of an ArrayList.
* In get val() we are reciving inputs to process
* In check() function we are calculating leap year + total number of leap years

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class Leap_Find {

int year1, year2;

Scanner scan;

List<Integer> list;

public static void main(String str[]) {

Leap_Find obj = new Leap_Find();

obj.getVal();

obj.check();

}

void getVal() {

scan = new Scanner(System.in);

System.out.println("Find leap years between two years");

System.out.println(" Enter the Starting year : ");

year1 = Integer.parseInt(scan.nextLine());

System.out.println("Enter the Ending year : ");

year2 = Integer.parseInt(scan.nextLine());

}

void check() {

System.out.println();

list = new ArrayList<Integer> ();

for(int i=year1; i<=year2; i++) {

if(i%400 == 0 || i%4 == 0) {

list.add(i);

System.out.println(i + " is a leap year");

}

}

System.out.println(" There are " + list.size() +" Years between" +" "+ year1 + " and " + year2 );

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote