Question

In: Computer Science

I cant not seem to get this right. I have tried and tried can I please...

I cant not seem to get this right. I have tried and tried can I please get help. Thank you!

Writing a Modular Program in Java Summary In this lab, you add the input and output statements to a partially completed Java program. When completed, the user should be able 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. Include the output statements in the simulated endOfJob() method. The format of the output is as follows: month/day/year is a valid date. or month/day/year is an invalid date. Execute the program entering the following date: month = 5, day = 32, year =2014 Observe the output of this program. Execute the program entering the following date: month = 9, day = 21, year = 2002 Observe the output of this program. The program is entered as the following: /* Program Name: BadDate.java Function: This program determines if a date entered by the user is valid. Input: Interactive Output: Valid date is printed or user is alerted that an invalid date was entered. */ import java.util.Scanner; public class BadDate { public static void main(String args[]) { // Declare variables String yearString; String monthString; String dayString; int year; int month; int day; boolean validDate = true; final int MIN_YEAR = 0, MIN_MONTH = 1, MAX_MONTH = 12, MIN_DAY = 1, MAX_DAY = 31; // This is the work of the housekeeping() method // Get the year, then the month, then the day Scanner input = new Scanner(System.in); // variable = input.nextLine(); // Convert Strings to integers // This is the work of the detailLoop() method // Check to be sure date is valid if( year <= MIN_YEAR ) // invalid year validDate = false; else if ( month < MIN_MONTH || month > MAX_MONTH ) // invalid month validDate = false; else if ( day < MIN_DAY || day > MAX_DAY ) // invalid day validDate = false; // This is the work of the endOfJob() method // Test to see if date is valid and output date and whether it is valid or not if( validDate == true ) { // Output statement } else { // Output statement } } // end of main() method } // end of BadDate class

Solutions

Expert Solution

Code Screenshots:

Sample Output 1:

Sample Output 2:

Code to Copy:

import java.util.Scanner;

public class BadDate

{

      //Declare the variables globally.

      String yearString ;

      String monthString;

      String dayString;

      int year;

      int month;

      int day;

      boolean validDate = true;

      final int MIN_YEAR = 0,

                  MIN_MONTH = 1,

                  MAX_MONTH = 12,

                  MIN_DAY = 1,

                  MAX_DAY = 31;

     

      //Define the method houseKeeping().

      public void housekeeping()

      {

            //Define an object

            //of the Scanner class.

            Scanner input = new Scanner(System.in);

           

            //Prompt the user

            //to enter the year.

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

           

            //Read and store the input.

            yearString = input.nextLine();

           

            //Prompt the user

            //to enter the month.

            System.out.println("Enter the month: ");

           

            //Read and store the input.

            monthString = input.nextLine();

           

            //Prompt the user to enter the day.

            System.out.println("Enter the day: ");

           

            //Read and store the input.

            dayString = input.nextLine();

           

            //Convert the string to the integer.

            year = Integer.parseInt(yearString);

           

            //Convert the string to the integer.

            month = Integer.parseInt(monthString);

           

            //Convert the string to the integer.

            day = Integer.parseInt(dayString);

           

            //Close

            input.close();

      }

      public void endOfJob()

      {

            System.out.print(month+"/"+day+"/"+year);

            if(validDate)

            {

                  System.out.println(" is a valid date.");

            }

            else

            {

                  System.out.println(" is not"

                              + " a valid date.");

            }

      }

      public void detailLoop()

      {

            if( year <= MIN_YEAR )

                  // invalid year

                  validDate = false;

            else if ( month < MIN_MONTH || month > MAX_MONTH )

                  // invalid month

                  validDate = false;

            else if ( day < MIN_DAY || day > MAX_DAY )

                  // invalid day

                  validDate = false;

      }

      public static void main(String args[])

      {

            // Declare variables

           

            BadDate obj = new BadDate();

            // This is the work of the housekeeping() method

            // Get the year, then the month, then the day

            // Convert Strings to integers

            obj.housekeeping();

           

           

            // This is the work of the detailLoop() method

            // Check to be sure date is valid

            obj.detailLoop();

            // This is the work of the endOfJob() method

            // Test to see if date is valid and output date and whether it is valid or not

            obj.endOfJob();

           

      }     // end of main() method

}


Related Solutions

I have tried this multiple times and I can't get the right answer. The 2014 balance...
I have tried this multiple times and I can't get the right answer. The 2014 balance sheet of Jordan’s Golf Shop, Inc., showed long-term debt of $5.2 million, and the 2015 balance sheet showed long-term debt of $5.45 million. The 2015 income statement showed an interest expense of $170,000. The 2014 balance sheet showed $520,000 in the common stock account and $5.5 million in the additional paid-in surplus account. The 2015 balance sheet showed $560,000 and $5.7 million in the...
The anwsers that was given is not correct. I have tried but cant figure it out>...
The anwsers that was given is not correct. I have tried but cant figure it out> out You are evaluating a project for The Ultimate recreational tennis racket, guaranteed to correct that wimpy backhand. You estimate the sales price of The Ultimate to be $440 per unit and sales volume to be 1,000 units in year 1; 1,250 units in year 2; and 1,325 units in year 3. The project has a 3-year life. Variable costs amount to $245 per...
I have done some of this on my own but just cant seem to be able...
I have done some of this on my own but just cant seem to be able to finish this correctly. Dual-energy X-ray absorptiometry (DXA) is a technique for measuring bone health. One of the most common measures is total body bone mineral content (TBBMC). A highly skilled operator is required to take the measurements. Recently, a new DXA machine was purchased by a research lab, and two operators were trained to take the measurements. TBBMC for eight subjects was measured...
Please, I need to get this right. No one is yet to get it right, it...
Please, I need to get this right. No one is yet to get it right, it has been answered on Chegg but is wrong In a psychrometric process, Volume of a classroom = 300 m^3. and temperature in the room is T= 20 oC, P=100 kPa relative humidity = 50% if all the water vapor of air in the room is converted to liquid at the same temperature, what is the volume of the liquid water (mL). I believe the...
Can you please select the right answer. I did not  get a good score on this quizz....
Can you please select the right answer. I did not  get a good score on this quizz. Thank you Question 6 5 / 5 pts Define the following terms associated with healthcare insurance: If the answers do not show in their entirety, they are pasted below: The maximum amount an insurer will pay for a certain service A health condition written into the health insurance policy indicating what is not covered by the policy The amount of expenses the patient must...
Questions about Enron Scandal I cant seem to find answers for: 1. What was the name...
Questions about Enron Scandal I cant seem to find answers for: 1. What was the name of the questionable accounting practice promoted by Skilling and how did it work? How did Andy Fastow hide losses through accounting practices? 2. What happened in California and how could it have been prevented? 3. What was the role of the Wall Street financial analysts in the Enron fraud and what question did Bethany McLean ask of Enron that the financial analysts did not...
Hello I have these questions, Can I please get some assistance, I need not so long...
Hello I have these questions, Can I please get some assistance, I need not so long or short answers please How to decide what job to take. Is that a marginal decision? What is an explicit cost? What is an implicit cost? How is accounting profit calculated? How is economic profit calculated?
"How can I connect to Hadoop Hive using Python? I've tried using PyHive but always get...
"How can I connect to Hadoop Hive using Python? I've tried using PyHive but always get the error: ...could not start SASL... no mechanism available: unable to find a callback: 2"
I have tried to answer the following questions. Please let me know if I missed one...
I have tried to answer the following questions. Please let me know if I missed one and why. 1) A light car and a heavy car are headed toward each other from opposite directions at the same speed. The ground is level. Which of the two will be harder to stop? the heavier car 2) Instead of stopping the cars, you jump out of the way. The two cars crash head-on. After the crash what do you see? The two...
For my economy class I need to annswer these questions but I just dont get/cant find...
For my economy class I need to annswer these questions but I just dont get/cant find the right inf. The Presentville – Futureville case: 1. Explain what motivated each group to make the decisions they made.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT