Design algorithms and solve problems incorporating the three control structures. For each program in this homework, develop flowcharts, then implement the design in Java. You do not need to include function calls in your flowchart diagrams.
Leap Year Detector
Design and implement a Java program that asks the user to enter
a year, and then displays a message indicating whether that year is
a leap year or not. Algorithm: if the year is evenly divisible by
4, it is a leap year.
Add a while or do-while loop to the program. Provide opportunities
to the user to do it again.
Note the two examples below uses different approaches to decide whether or not the program should "do-it-again". Take integer 1 or 0 as the answer to whether or not repeat the program is easier. This approach would satisfy the homework requirements. You don't have to implement take 'y' or 'n' for the answer, but you are welcome to take the challenge!
Sample output example 1:
Enter a year I will tell you if it's a leap year:
2000
2000 is a leap year!
Do you wish to test another year? 1 for yes, 0 for no. Enter 1 or
0:
1
Enter a year I will tell you if it's a leap year:
2001
2001 is not a leap year!
Do you wish to test another year? 1 for yes, 0 for no. Enter 1 or
0:
0
Thank you. Have a nice day!
Sample output example 2:
Enter a year I will tell you if it's a leap year:
2000
2000 is a leap year!
Do you wish to test another year?
y
Enter a year I will tell you if it's a leap year:
2001
2001 is not a leap year!
Do you wish to test another year?
n
Thank you. Have a nice day!
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
int year,ch;
while(true) {
System.out.println("Enter a year I will tell you if it's a leap
year: ");
year=sc.nextInt();
if(isLeap(year))
System.out.println(year+" is a leap
year!");
else
System.out.println(year+" is not a leap
year!");
System.out.println("Do you wish to test another year? 1 for yes, 0
for no. Enter 1 or 0: ");
ch=sc.nextInt();
if(ch==0)
break;
}
System.out.println("Thank you. Have
a nice day");
}
private static boolean isLeap(int year) {
boolean leap = false;
// if any year is divisable by 4
than there are many chances for leap year except few
if (year % 4 == 0) {
// if it is
divisable by 100 than it shoud also divisable by 400 like 2000
etc
if (year % 100
== 0) {
// year is divisible by 400, so the year is a
leap year
if (year % 400 == 0)
leap = true;
else
leap = false;
} else
leap = true;
} else
leap =
false;
return leap;
}
}
Design algorithms and solve problems incorporating the three control structures. For each program in this homework,...
Instructions ASSIGNMENT 2 is at bottom of the question. Very simple program and these intructions are only to modify it slightly, should only take about 10 minutes says my proffessor. Your file should be named “Main.java”. Ask the user how many year inputs he wants to check - an integer. Assume that the user always gives an input which is between 1 and 5 (inclusive). Next, ask the user for K number of year inputs where K = the number...
Design an application with a single class and two static methods: method main and method isLeap. Static method isLeap accepts year as integer and returns boolean value true or false depending whether year is leap or not. public static boolean isLeap ( int year ) The year is leap year if it is divisible by 4, but not divisible by 100 , except if it is divisible by 400. Examples 2003 is not a leap year 2020 is leap year...
(python) Leap Year Detector Design a program that asks the user to enter a year, and then displays a message indicating whether that year is a leap year or not. Use the following logic to develop your algorithm: If the year is evenly divisible by 100 and is also evenly divisible by 400, then it is a leap year. For example, 2000 is a leap year but 2010 is not. If the year is not evenly divisible by 100, but...
Java Program 4: Methods Purpose: To practice using both void and value-returning methods and understand when, where, and how to use them. The following problem employs the use of both void and value-returning methods: (Be sure to start with an algorithm to help you organize your ideas and provide a blueprint as to how to approach the problem. Think about what kind of return type your method will need. Carefully examine and follow ALL the program specifications (for full credit)....
This question deals with extending already existing Java code via a while loop. Ask the user how many year inputs he wants to check - an integer. Assume that the user always gives an input which is between 1 and 5 (inclusive). Next, ask the user for K number of year inputs where K = the number user has given as input before (inside a while loop). Check for each year input whether that year is a leap year or...
Java Programming USE ONLY 1 CLASS. Class main is all that is required 1. Ask the user for a year as an input (positive integer - should be between 1500 and 2020, and can include 1500 and 2020). 2. If the year input is not between 1500 and 2020, do not check for leap year. Instead, print that this year cannot be checked. 3. If the input year provided by the user is a leap year, print that year is...
Has to be written in C++ Write a program that asks the user to enter the month (1-12) and the year (0-2019). Validate the input and print an error and stop the program if an invalid month or year was entered. The program should then display the number of days in that month. Use the following criteria to identify leap years: Determine whether the year is divisible by 100. If it is, then it is a leap year if and...
In this homework, you will design a program to perform the following task: Write a program that would allow a user to enter student names and Final grades (e.g. A,B,C,D,F) from their courses. You do not know how many students need to be entered. You also do not know how many courses each of the students completed. Design your program to calculate the Grade Point Average (GPA) for each student based on each of their final grades. The program should...
in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of...
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...