Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview: HW06: CS12Date Due: Tuesday 10/03/23, 11:59pm (39 pts) In this assignment, you will experiment with using the API methods of an existing Java

Overview: HW06: CS12Date Due: Tuesday 10/03/23, 11:59pm (39 pts) In this assignment, you will experiment withPreliminaries: First, do the following: a) As always, start by reviewing all the relevant lecture materialsRequirements: In your CS12DateClientFL.java code, do each of the following. For each problem:  Use the7) Prompt the user for the month, day and year of YOUR birthday this year (3 prompts) using Scanner, asSample output: Your resulting outputs should pretty closely resemble these, except for YOUR birthday infoThis year's birthday month? > 7 This year's birthday day? > 18 This year's birthday year?> 2023 7) This

Overview: HW06: CS12Date Due: Tuesday 10/03/23, 11:59pm (39 pts) In this assignment, you will experiment with using the API methods of an existing Java class, CS12Date, as discussed in the lecture materials. This is a simple "teaching" Java class I created, that provides various calendar date capabilities. Use the sample outputs provided on pgs.5-6 to help you along. When you are faced with familiarizing yourself with a "new-to-you" Java class, review its published API, but also experiment with it by doing the following: Create objects of that class type, using its various constructor methods. Do "something" with the objects, by exercising their various API methods. Display the objects before and after, by using their available display methods. Make sure you understand if the objects are behaving as described by their API. Java Objectives: 1) Using existing classes and creating objects [CSLO-2] 2) The CS12Date class and API [CSLO-2] 3) Displaying objects, explicitly using toString() and implicitly [CSLO-2] 4) Experimenting with the methods of a class API [CSLO-3] 5) Perform before-and-after testing using methods of the API [CSLO-4] Problem Summary: Solve a series of date-related problems, one at a time, using the CS12Date class Exercise most of the methods of the CS12Date API, and print the results Perform before-and-after testing using the created objects Preliminaries: First, do the following: a) As always, start by reviewing all the relevant lecture materials first. In particular, make sure to look over the source code examples and code walk-thrus, and the demo video for using CS12Date. b) When it becomes available, please view the Week 6 office hour recording, for a demo of this assignment and setting it up. c) IMPORTANT: download CS12Date.java file into your working directory. It must be present alongside your client program, otherwise you may (WILL) encounter "cannot find symbol" errors. d) In the same directory, create CS12DateClientFL.java, using your template as a starting point. Reverting back to one main() method is fine for this assignment; you don't need multiple methods for each problem, like you did last time. e) Also have the CS12Date API on-hand as a reference for completing this assignment. You'll find this PDF file in the weekly code examples ZIP file. Then, in your CS12DateClientFL.java code, do the following: f) Set up one Scanner object for user inputs. See the example given in the Scanner app note and its sample code. When you need a month, day, or year, the needed code will look something like this: import java.util.Scanner; //this one line appears BEFORE the public class... statement Scanner input = new Scanner(System.in); // done ONCE, inside your main() g) Upfront, declare only (for now) the following "scratch" (reusable) data in your program: 4 CS12Date variables (objects): today, myBday, halloween, christmas; 3 int variables month, day, and year You will reuse these variables/objects to address the various program tasks. Just declare these for now, no need to instantiate them just yet. I prefer to see you instantiate each of these dates problem-by-problem, as the program spec calls for them. h) Use code such as this for EACH month, day, or year to be read for the upcoming steps: System.out.print("Enter month for... > "); month = input.nextInt(); //use existing declared variables for each M/D/Y input Requirements: In your CS12DateClientFL.java code, do each of the following. For each problem: Use the specified constructor form and/or method! Different constructor forms and/or methods are specified for various problems. Make sure all of your outputs are clearly labeled with the problem number Don't cram all outputs together, give yourself some blank space between outputs From here on: please provide overall commenting (narrative) of your program's logic flow. Tell the reader what each problem does, beyond just the simple problem #. Use summary before-comments, NOT end-comments on each and every line! 1) Using the CS12Date default constructor, instantiate a new date object today with its default values (today's date). Print out this date object explicitly using its toString() method with System.out.println(), AND also implicitly, using System.out.println() with just the name of the date object. Both dates should print identically, but implicit (object name only) is simpler and always the way to go. 2) Print today one more time, except this time use its print () method. Use the overloaded print form, and provide it some descriptive labeling message. 3) Using one of the CS12Date month-day-year constructor forms, instantiate a new date object called halloween (note the initial lower case convention), and set its date to that of Halloween this year (October 31st). Print the date using whatever means you wish. 4) Using the CS12Date month-day constructor form, instantiate a new date object called myBday to November 1st of this year. (THIS SHOULD REALLY BE NOV 1", NOT YOUR BIRTHDAY. Yeah, this probably isn't right, but you'll update it later). Print this date using whatever means you wish. DO NOT use your own birthdate in this step, we'll update it later. 5) Using the CS12Date default constructor, instantiate a new default date object called christmas (note the initial lower case convention), then update it from the default date to the date of this coming Christmas using the setDate() method. This represents 2 separate operations. Print the date using whatever means you wish. 6) Advance the step 4 date myBday by 3 days, by using the nextDate() method 3x. Print the new date using whatever means you wish. Then advance the date myBday by one more week, using the laterDate() method, and print the new date using whatever means you wish. 7) Prompt the user for the month, day and year of YOUR birthday this year (3 prompts) using Scanner, as described above in (e) and using the variables declared in (f). Then, using all 3 of the individual mutator (set) methods, and the 3 int vars just read in, update current date of myBday to the date of your birthday this year. Print the date using whatever means you wish. 8) On what date number of the year (1-365 or 1-366) is/was this year's birthday? Use the myBday date and getDateNum() to find the result, then print both your birthday AND this ordinal date together as a one-line String output. For this problem, try and inline the needed expression directly into your print statement! 9) Print both today's date and your birthday from #7, and check whether today is your birthday (if it is, Happy Birthday!). Use either date object (today or myBday) and its equals() method, compare it to the other date using equals(), and print out the T/F verdict. For this problem, try and inline the needed expression directly into your print statement! Since all Java objects are ultimately descended from type Object, use the other CS12Date object for the input parameter Object obj. See the example code in CS12DateUsage.java on Canvas for an example of this if needed. 10) Using the today and myBday dates, compare one date to the other one using the compare() method, using both orderings (see the sample outputs). Print the results. For this problem, try and inline the needed expressions directly into your print statements! Then, also compare today to itself, and print the result. So there should be 3 results in all. The compare() method tells us the relative ordering of two CS12 Date dates: compare() > 0: compare() < 0: compare() = 0: input CS12Date is in future relative to CS12Date object's date input CS12Date is in past relative to CS12Date object's date both CS12Dates are the same See the API for details. You may need to use compare() on a future assignment! 11) Before proceeding, reset the following individual integer variables: month=0, day=0, year=0. Reset the 3 local int variables only, not by using the 3 mutator methods. Then, using the 3 individual accessor (get) methods, reprint the date of this year's birthday in myBday, except print it in "dashes" form, MM-DD-YYYY. You will need to use string concatenation. Can you inline the needed 3 expressions directly into the print statement?? Print the new date as a String using println(). Note that you aren't "altering" the original myBday, you are just taking it apart using the accessors, and "reassembling" it to create a new String, which you will then print using System.out.println(). Sample output: Your resulting outputs should pretty closely resemble these, except for YOUR birthday info (you can label the outputs however you wish). Make sure you are using the specified constructor forms or methods, and put some blank space between problems for readability! --JGRASP exec: java CS12DateClientRL la) today explicitly using tostring() - 9/9/2023 1b) today implicitly using just object name - 9/9/2023 ......... 2) This is default constructor date of today www year: month: day: text: toString(): day in year: leap year? year: month: day: text: 3) Halloween using -d-y constructor specifically toString(): day in year: leap year? year: month: 2023 9 9 day: text: toString(): day in year: leap year? ====== 9/9/2023 252 false 2023 10 31 >Your today date will differ 4) Imaginery birthday using m-d constructor specifically 10/31/2023 304 false 2023 11 1 11/1/2023 305 false YES, use this specific date and NOT your own birthday! ******* 5) Christmas using default constructor THEN setDate(): 12/25/2023 6a) 3 days past so-called birthday using nextDate(): 11/4/2023 6b) 1 week past so-called birthday using laterDate(): 11/11/2023 This year's birthday month? > 7 This year's birthday day? > 18 This year's birthday year?> 2023 7) This year's birthday using mutators is/was: =========== ====== year: month: day: text: toString(): day in year: leap year? 2023 7 18 This should be YOUR birthdate this year, not mine 7/18/2023 199 false Updated myBday, using above inputs 8) This year's birthday 7/18/2023 is was day #: 199 9) Is today 9/9/2023 my birthday 7/18/2023? false 10a) compare today to my birthday: -1 10b) compare my birthday to today: 1 10c) compare today to today: 0 11) This year's birthday with dashes is still: 7-18-2023 ----GRASP: operation complete. Common things to check before code review or submitting: Put a blank line between each problem, don't crowd the outputs together Use the specified constructor of method forms cited, follow the program spec CLOSELY! Every date setup should NOT use a full constructor, for example o There are TWO ways to advance the date needed in #6 Do NOT hardwire your own birthday or birthdate into the code!! After you do enter your own birthday in #7, update myBday with those 3 inputs Use specified methods to do this Comment your code problem by problem Before-comments preferred over end-comments for program logic Declare ALL vars and objects upfront, not as the need for them arises In general, follow the program spec, sample outputs, and rubric closely! Make use of the code review option if possible, for max points o Or have Bowyn look your code over during his hours

Step by Step Solution

3.36 Rating (152 Votes )

There are 3 Steps involved in it

Step: 1

Solutions Step 1 Here is the code for the given task it includes all the problems given Make sure to integrate this code into your CS12DateClientFLjava file import javautilScannerpublic class CS12DateClientFL public static void mainString args Step f Set up Scanner object for user inputs Scanner input new ScannerSystemin Step g Declare variables CS12Date ... 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_2

Step: 3

blur-text-image_3

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

Intermediate Accounting

Authors: Kin Lo, George Fisher

3rd Edition Vol. 1

133865940, 133865943, 978-7300071374

More Books

Students also viewed these Programming questions