Question

Find the Month and Day. Working with 2 parallel arrays. One holds the months of the...

Find the Month and Day.

Working with 2 parallel arrays. One holds the months of the years, the other array holds the # of days in each month.

This lab will determine what Month and DayOfMonth for any given day of the year.

1). Name the lab "Lab4_MonthAndDay". Remember, case sensistive.

2). Ask user to input a # between 1 and 365. Validate the input.

3). Also ask user to input the year, between year 1 and year 202. Validate the input.

3). Use the input to determine the month, and the day of the month. For example, day 32 is February 1st. Day 70 is March 11.

in Java

Homework Answers

Answer #1

import java.util.*;

public class Day_month {

    public static void main(String args[]) {

        Scanner sc= new Scanner(System.in);

            System.out.println("Enter a year between 2001 and 2020");

            int year= sc.nextInt();

            if(year>=2001 && year<= 2020){

                if(year%4==0 && year%100==0 && year%400==0){

                    int []days= {31,29,31,30,31,30,31,31,30,31,30,31};

                    System.out.println("Enter days between 1 to 365");

                    int day = sc.nextInt();

                    if(day>=1 && day<=366)

                     Lab4_MonthAndDay(day, days);

                }

                else

               {

                   int []days= {31,28,31,30,31,30,31,31,30,31,30,31};

                   System.out.println("Enter days between 1 to 365");

                   int day = sc.nextInt();

                   if(day>=1 && day<=365)

                   Lab4_MonthAndDay(day, days);

               }

            }

    }

    public static void Lab4_MonthAndDay(int day, int []days){

        String []months= {"January","February","March","April","May","June","July","August","September","October","November","December"};

        int copy= day;int i=0;

        for(i=0; i<12; i++){

            if(day> days[i])

              day= day- days[i];

            else

              break;

        }

        System.out.println("Day "+copy+" is "+months[i]+" "+day);

    }

}

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
Lab 3 – Pseudocode and Parallel Arrays This lab requires you to think about the steps...
Lab 3 – Pseudocode and Parallel Arrays This lab requires you to think about the steps that take place in a program by writing pseudocode. Read the following program prior to completing the lab. Design an application in which the number of days for each month in the year is stored in an array. (For example, January has 31 days, February has 28, so on. Assume that the year is not a leap year.) Also, use a parallel array to...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January - December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
Create a simple Java class for a Month object with the following requirements:  This program...
Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
Write a program (C language) that will read the number of a month and will print...
Write a program (C language) that will read the number of a month and will print the number of days in the month. Ignore leap years. Use 28 days for February. Have the program runs in a continuous loop, allowing the user to enter a month number, see that number of days, and repeat. Use month number = 0 to exit the loop and the program. Program must meet the following criteria: 1.Your name and the name of the program...
Q: Design a program that lets the user enter the total rainfall for each of 12...
Q: Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Create parallel arrays for the month names and rainfall amounts for each month. Use month names (i.e. January, February, March, etc.) when printing out the months with the highest and lowest amounts. Include a modular...
USE PYTHON ONLY PLEASE Zeller’s congruence is an algorithm developed by Christian Zeller to calculate the...
USE PYTHON ONLY PLEASE Zeller’s congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h = (q + 26(m+1)//10 + k + k//4 +j//4 +5j) % 7 where - h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). - q is the day of the month. - m is the month (3: March, 4: April, ..., 12: December). January...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT