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...
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’...
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...
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...
please can you make it simple. For example using scanner or hard coding when it is...
please can you make it simple. For example using scanner or hard coding when it is a good idea instead of arrays and that stuff.Please just make one program (or class) and explain step by step. Also it was given to me a txt.htm 1.- Write a client program and a server program to implement the following simplified HTTP protocol based on TCP service. Please make sure your program supports multiple clients. The webpage file CS3700.htm is provided. You may...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
A loan made on March 14 is due September 13 of the following year. Find the...
A loan made on March 14 is due September 13 of the following year. Find the exact time for the loan in a​ non-leap year and a leap year. days. The exact time in a​ non-leap year is ? days The exact time in a leap year is ? days. Data Table Sequential Numbers for Dates of the Year Day of Month Jan. Feb. Mar. Apr. May June July Aug. Sept. Oct. Nov. Dec. 1 1 32 60 91 121...
21. A client who was admitted with pneumonia was complaining of abdominal pain from frequent non-...
21. A client who was admitted with pneumonia was complaining of abdominal pain from frequent non- productive coughing. When he does produce sputum, it is watery and yellowish-green. Which of the following are appropriate nursing interventions at this time? Select all that apply Give him a pillow for splinting Administer antitussive syrup, 30mg ordered prn. Place him in appropriate positions for postural drainage Encourage him to increase his oral fluid intake Request an order for increasing flow rate. 22. A...
Read the attached articles about the proposed merger of Xerox and Fujifilm. Utilizing your knowledge of...
Read the attached articles about the proposed merger of Xerox and Fujifilm. Utilizing your knowledge of external and internal analysis, business and corporate strategy, and corporate governance, please discuss the following questions: 1. What is the corporate strategy behind the merger of Xerox and Fujifilm? 2. Why did Xerox agree to the merger? Is this a good deal for Xerox? Discuss the benefits and challenges they face with the merger. 3. Why did Fujifilm agree to the merger? Discuss the...
What tools could AA leaders have used to increase their awareness of internal and external issues?...
What tools could AA leaders have used to increase their awareness of internal and external issues? ???ALASKA AIRLINES: NAVIGATING CHANGE In the autumn of 2007, Alaska Airlines executives adjourned at the end of a long and stressful day in the midst of a multi-day strategic planning session. Most headed outside to relax, unwind and enjoy a bonfire on the shore of Semiahmoo Spit, outside the meeting venue in Blaine, a seaport town in northwest Washington state. Meanwhile, several members of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT