Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Assume that datel and date2 reference two objects of class IncDate as defined in Section 1.2 Organizing Classes, respectively. What would be the output

image text in transcribed
image text in transcribed
java
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Assume that datel and date2 reference two objects of class IncDate as defined in Section 1.2 "Organizing Classes," respectively. What would be the output of the following code? datel new IncDate (5, 5, 2000); date2 new IncDate (5, 5, 2000); System.out.println (datel); System.out.println (date); datel increment ; System.out.println(datel); System.out.println(date2); datel = date 2; System.out.println (datel); System.out.println (date); Make sure that the dates are in the format of "1/30/2010" (Do not pad leading for days or months). Refer to the tostring method defined on Page 3 of the textbook for more details. Line 1 Line 2 A/ Line 3 Line 4 Line 5 AJ Line 6 Programming Questions (40pts) You are provided with a Date class and an incomplete EnhancedDate class. The EnhancedDate class inherits from the Date class with two more methods: addDays (int numDays) This method adds a certain number of days to the date represented by the current Date object. The changes should be left on the current object. This task is done by first creating an object of the EnhancedDate class in the test driver with an initial date and then calling the addDays method on this object. For example, if the current EnhancedDate object, say current Date, contains the date 1/1/2016, then after the addDays (20) method is called on currentDate, the date in it would be 1/21/2016 because 20 days has been added to the original date. This is not a simple addition because you need to take care of different months as well as leap years. daysFrom (Date startDate) - This method computes the number of days elapsed from startDate, and returns an integer. If the startDate is earlier than the current day, the return should be positive, whereas if it is later than the current date, then this method should return a negative number. Hint: you can call the compareTo method provided in the Date class to check which of the two dates is older so that you can always count the days from the older date to the newer date. You may choose to use the above addDays method to simplify this implementation - you can keep adding a day to the older date until you bring it up to the newer date. Do NOT use any off-the-shelf Implementations for the above methods. You are required to do it from scratch using basic date structures! a. Completing the EnhancedDate class Your task is to implement the addDays and the days from methods in the EnhancedDate class to fulfill the required objectives. Note that you are only supposed to touch these two methods. You are NOT allowed to create any other methods, Instance variables, or make any changes to methods other than addDays and daysFrom or files other than "EnhancedDate.java". Points will be taken off If you fail to follow this rule. b. Code Testing You are provided with a test driver implemented by "TestDate.java" (Do not make any changes to this file!) so there is no need to write your own. You are also given a data file "testDates.dat" that contains 35 test dates. This is a binary file and you will not be able to view its content using a text editor. We have not covered how to read and write this type of files so do not worry if you have no idea how it works. We will introduce the topic later this semester. Depending on your programming environment, the data file might need to be placed in different folders so that you test driver can read it. For IGRASP, you can leave the data file in the same folder as your java files. For NetBeans, you should place it in your project folder in which you see directories like build, nbproject, and src, etc. Once you have completed the methods, you can run the test. You should create a plain text file named "output.txt", copy and paste the output (if your code crashes or does not compile, copy and paste the error messages) to this file and save it. Grading Rubric: Code does not compile: -10 Code compiles but crashes when executed: -5 Changes were made to things other than the addDays and days From methods: -5 Off-the-shelf implementation was used in the implementation: -35 Dates were hard-coded into any of the methods: -40 Has output file: 5 Code passes 35 test cases: 35 (each test case worth 1 point) Sample Output: The current date is 1/30/2010 and 2 days are added. The correct new date is 2/1/2010 and the one calculated by your program is 2/1/2010. Correct! The current date is 2/28/2011 and 2 days are added. The correct new date is 3/2/2011 and the one calculated by your program is 3/2/2011. correct! The current date is 2/28/2012 and 2 days are added. The correct new date is 3/1/2012 and the one calculated by your program is 3/1/2012. Correct! (1/1/2020).days From (12/31/2020) is supposed to return -365 and your reton - 365 COLA The correct new date 13 37172012 and the one calculated by your program is 3/1/2012. Correct! .. (1/1/2020) days from (12/31/2020) is supposed to return -365 and your return is -365 Correct! (1/30/2009).days From (2/2/2009) is supposed to return -3 and your return is -3 Correct! (5/1972030) days from (4/30/1902) is supposed to return 46771 and your return is 46771 Correct! (2/28/1904). daysFrom (7/19/1827) is supposed to return 27982 and your return is 27982 Correct! 16/8/1999).days From(6/8/1999) is supposed to return 0 and your return is o Correct! Total test cases: 35 Corbed 35 Warid The correct new date 13 37172012 and the one calculated by your program is 3/1/2012. Correct! .. (1/1/2020) days from (12/31/2020) is supposed to return -365 and your return is -365 Correct! (1/30/2009).days From (2/2/2009) is supposed to return -3 and your return is -3 Correct! (5/1972030) days from (4/30/1902) is supposed to return 46771 and your return is 46771 Correct! (2/28/1904). daysFrom (7/19/1827) is supposed to return 27982 and your return is 27982 Correct! 16/8/1999).days From(6/8/1999) is supposed to return 0 and your return is o Correct! Total test cases: 35 Corbed 35 Warid Assume that datel and date2 reference two objects of class IncDate as defined in Section 1.2 "Organizing Classes," respectively. What would be the output of the following code? datel new IncDate (5, 5, 2000); date2 new IncDate (5, 5, 2000); System.out.println (datel); System.out.println (date); datel increment ; System.out.println(datel); System.out.println(date2); datel = date 2; System.out.println (datel); System.out.println (date); Make sure that the dates are in the format of "1/30/2010" (Do not pad leading for days or months). Refer to the tostring method defined on Page 3 of the textbook for more details. Line 1 Line 2 A/ Line 3 Line 4 Line 5 AJ Line 6 Programming Questions (40pts) You are provided with a Date class and an incomplete EnhancedDate class. The EnhancedDate class inherits from the Date class with two more methods: addDays (int numDays) This method adds a certain number of days to the date represented by the current Date object. The changes should be left on the current object. This task is done by first creating an object of the EnhancedDate class in the test driver with an initial date and then calling the addDays method on this object. For example, if the current EnhancedDate object, say current Date, contains the date 1/1/2016, then after the addDays (20) method is called on currentDate, the date in it would be 1/21/2016 because 20 days has been added to the original date. This is not a simple addition because you need to take care of different months as well as leap years. daysFrom (Date startDate) - This method computes the number of days elapsed from startDate, and returns an integer. If the startDate is earlier than the current day, the return should be positive, whereas if it is later than the current date, then this method should return a negative number. Hint: you can call the compareTo method provided in the Date class to check which of the two dates is older so that you can always count the days from the older date to the newer date. You may choose to use the above addDays method to simplify this implementation - you can keep adding a day to the older date until you bring it up to the newer date. Do NOT use any off-the-shelf Implementations for the above methods. You are required to do it from scratch using basic date structures! a. Completing the EnhancedDate class Your task is to implement the addDays and the days from methods in the EnhancedDate class to fulfill the required objectives. Note that you are only supposed to touch these two methods. You are NOT allowed to create any other methods, Instance variables, or make any changes to methods other than addDays and daysFrom or files other than "EnhancedDate.java". Points will be taken off If you fail to follow this rule. b. Code Testing You are provided with a test driver implemented by "TestDate.java" (Do not make any changes to this file!) so there is no need to write your own. You are also given a data file "testDates.dat" that contains 35 test dates. This is a binary file and you will not be able to view its content using a text editor. We have not covered how to read and write this type of files so do not worry if you have no idea how it works. We will introduce the topic later this semester. Depending on your programming environment, the data file might need to be placed in different folders so that you test driver can read it. For IGRASP, you can leave the data file in the same folder as your java files. For NetBeans, you should place it in your project folder in which you see directories like build, nbproject, and src, etc. Once you have completed the methods, you can run the test. You should create a plain text file named "output.txt", copy and paste the output (if your code crashes or does not compile, copy and paste the error messages) to this file and save it. Grading Rubric: Code does not compile: -10 Code compiles but crashes when executed: -5 Changes were made to things other than the addDays and days From methods: -5 Off-the-shelf implementation was used in the implementation: -35 Dates were hard-coded into any of the methods: -40 Has output file: 5 Code passes 35 test cases: 35 (each test case worth 1 point) Sample Output: The current date is 1/30/2010 and 2 days are added. The correct new date is 2/1/2010 and the one calculated by your program is 2/1/2010. Correct! The current date is 2/28/2011 and 2 days are added. The correct new date is 3/2/2011 and the one calculated by your program is 3/2/2011. correct! The current date is 2/28/2012 and 2 days are added. The correct new date is 3/1/2012 and the one calculated by your program is 3/1/2012. Correct! (1/1/2020).days From (12/31/2020) is supposed to return -365 and your reton - 365 COLA The correct new date 13 37172012 and the one calculated by your program is 3/1/2012. Correct! .. (1/1/2020) days from (12/31/2020) is supposed to return -365 and your return is -365 Correct! (1/30/2009).days From (2/2/2009) is supposed to return -3 and your return is -3 Correct! (5/1972030) days from (4/30/1902) is supposed to return 46771 and your return is 46771 Correct! (2/28/1904). daysFrom (7/19/1827) is supposed to return 27982 and your return is 27982 Correct! 16/8/1999).days From(6/8/1999) is supposed to return 0 and your return is o Correct! Total test cases: 35 Corbed 35 Warid The correct new date 13 37172012 and the one calculated by your program is 3/1/2012. Correct! .. (1/1/2020) days from (12/31/2020) is supposed to return -365 and your return is -365 Correct! (1/30/2009).days From (2/2/2009) is supposed to return -3 and your return is -3 Correct! (5/1972030) days from (4/30/1902) is supposed to return 46771 and your return is 46771 Correct! (2/28/1904). daysFrom (7/19/1827) is supposed to return 27982 and your return is 27982 Correct! 16/8/1999).days From(6/8/1999) is supposed to return 0 and your return is o Correct! Total test cases: 35 Corbed 35 Warid

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

1. What will happen in the future

Answered: 1 week ago