1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
schepotkina [342]
3 years ago
11

In this lab, you add the input and output statements to a partially completed Java program. When completed, the user should be a

ble to enter a year, a month, and a day to determine if the date is valid. Valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31.
Instructions


Notice that variables have been declared for you.


Write the simulated housekeeping() method that contains input statements to retrieve a year, a month, and a day from the user.


Add statements to the simulated housekeeping() method that convert the String representation of the year, month, and day to ints.
Computers and Technology
1 answer:
leonid [27]3 years ago
8 0

Answer:

import javax.swing.JOptionPane;

public class BadDate {

  private static final int MINIMUM_YEAR = 0, MINIMUM_MONTH = 1, MAXIMUM_MONTH = 12, MINIMUM_DAY = 1, MAXIMUM_DAY = 31;

  private int year = 0;

  private int month = 0;

  private int day = 0;

  public void housekeeping() {

      String yearData = JOptionPane.showInputDialog("Enter year");

      String monthData = JOptionPane.showInputDialog("Enter month");

      String dayData = JOptionPane.showInputDialog("Enter day");

      this.year = Integer.parseInt(yearData);

      this.month = Integer.parseInt(monthData);

      this.day = Integer.parseInt(dayData);

  }

 

  public boolean isLeapYear(){

      if(((this.year % 400) == 0) || (((this.year % 4) == 0) && ((this.year % 100) != 0)))

          return true;

      else

          return false;

  }

  public void endOfJob() {

      boolean validDate = true;

     

      if((month < MINIMUM_MONTH) || (MAXIMUM_MONTH < month))

          validDate = false;

      else {

          if(((month == 1) || (month == 3) || (month == 5) || (month == 7) ||

                  (month == 8) || (month == 10) || (month == 12)) && ((day < 1) || (31 < day)))

              validDate = false;

         

          else if(((month == 4) || (month == 6) || (month == 9) || (month == 11)) && ((day < MINIMUM_DAY) || (30 < day)))

              validDate = false;

         

          else if(month == 2) {

              if(isLeapYear() && ((day < MINIMUM_DAY) || (29 < day)))

                  validDate = false;

              else if((day < MINIMUM_DAY) || (28 < day))

                  validDate = false;

          }

      }

     

      if (validDate) {

          JOptionPane.showMessageDialog(null, "Date: " + this.month + "/" + this.day + "/" + this.year);

          System.out.println(this.month + "/" + this.day + "/" + this.year + " is a valid date");

      } else {

          JOptionPane.showMessageDialog(null, this.month + "/" + this.day + "/" + this.year + " is an invalid date");

          System.out.println(this.month + "/" + this.day + "/" + this.year + " is an invalid date");

      }

  }

  public static void main(String args[]) {

     

      BadDate date = new BadDate();

      date.housekeeping();

      date.endOfJob();

  }

}

Explanation:

  • Take the year, month and day from user  as an input.
  • Check if the year of this date is a leap year inside the isLeapYear method.
  • Inside the housekeeping method , take the year, the month and day  to ensure that date is valid .
  • Display positive response by printing valid date if date is correct.
  • Otherwise alert user that an invalid date was entered.
You might be interested in
The term used to describe the shape and layout of a computer component such as a motherboard or hard drive is ______ factor.
Olegator [25]
The answer is form factor
8 0
3 years ago
My pc suddenly freezes and i can't open any apps or task manager. Apps do not open at all and if i restart from the start it get
eduard

Answer:

Explanation:

You might need a new computer or a new mother board

7 0
3 years ago
You have been asked to troubleshoot a legacy system running a critical component on your employer's network. Initial findings in
timurjin [86]

Answer:

HDB

Explanation:

According to my research on information technology and linux based systems, I can say that based on the information provided within the question the name for this disk in linux is called an HDB. This refers to Hard Disk B, this is the case since it is a secondary master drive. While primary master drive would be called HDA or hard drive A.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

8 0
3 years ago
Horses developed longer legs over time in response to pressure from predators that they needed to outrun to survive.
sergejj [24]
This is true. Horses did develop that
7 0
3 years ago
Corey wrote a code that will display his name every time he presses the down arrow key but there is a bug in it. Display letter
brilliants [131]

Answer:

Explanation:

display letter c, type letter r, type letter o, type letter 3, type letter y- i think thats it but i dee cay this is confusing

7 0
3 years ago
Other questions:
  • "The OSI model has seven layers and the DoD has four. At which layer does SMTP works in both models"?
    15·1 answer
  • Whaat was the first sound recording machine
    12·2 answers
  • When you define a table's primary key, the dbms automatically creates a(n) _____ index on the primary key column(s) you declared
    14·1 answer
  • The media is a phase that people often use to refer to:
    6·1 answer
  • 1.which of the following CANNOT be copyrighted?
    7·1 answer
  • Which of the following, (1) money deposited in a bank account, (2) student recording her answer to a question in an online test,
    14·1 answer
  • Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards
    10·1 answer
  • Assignment 1: silly sentences edhesive
    7·1 answer
  • IN WHICH COUNTRY DO THEY LET YOU PLAY MINECRAFT IN SCHOOL?
    8·2 answers
  • Which of the following jobs usually requires some level of formal higher education other than vocational training?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!