Building Java Programs: A Back To Basics Approach (5th Edition)
5th Edition
ISBN: 9780135471944
Author: Stuart Reges, Marty Stepp
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 8, Problem 2PP
Program Plan Intro
Date
Program plan:
Filename: “Date.java”
- Include the required header files.
- Define the “Date” class
- Declare the required integer private variables.
- Define the constructor.
- Call the “super” method.
- Set the day, month, and year.
- Define the “addDays” method.
- Return the day by forward in time by the given number of days.
- Define the “addWeeks” method.
- Calculate the weeks.
- Check the “day” is greater than 31.
- Calculate the difference in date.
- Increment the month
- Set the day
- Define the “daysTo” method.
- Declare the required variables.
- Call the “getDay” method and store the result in “day1” variable.
- Call the “getMonth” method and store the result in “month1” variable.
- Call the “getYear” method and store the result in “year1” variable.
- Check the “year1” is greater than “year”
- Calculate the difference in years
- Check the “month1” is greater than “month”
- Calculate the difference in months
- Otherwise, Calculate the difference in months
- Check the “day1” is greater than “day”
- Calculate the difference in days
- Otherwise, Calculate the difference in days.
- Return the result.
-
- Otherwise,
- Calculate the difference in years
- Check the “month1” is greater than “month”
- Calculate the difference in months
- Otherwise, Calculate the difference in months
- Check the “day1” is greater than “day”
- Calculate the difference in days
- Otherwise, Calculate the difference in days.
- Return the result.
- Otherwise,
-
- Define the “getDay” method
- Return the day
- Define the “setDay” method
- Set the day
- Define the “getMonth” method
- Return the month
- Define the “setMonth” method
- Set the month.
- Define the “getYear” method
- Return the year
- Define the “setYear” method
- Set the Year.
- Define the “isLeapYear” method
- Set the “isLeap” is false
- Check the “year” mod 400 is 0
- Set the “isLeap” is true
-
- Check the “year” mod 100 is 0
- Set the “isLeap” is false
- Check the “year” mod 4 is 0
- Set the “isLeap” is true
- Otherwise, set the “isLeap” is false.
- Return the result.
- Check the “year” mod 100 is 0
-
- Set the “isLeap” is true
- Define the “toString” method
- Return the year, month, and day.
Filename: “Test.java”
- Define the “Test” class.
- Define the main method.
- Create an object for “Date” class
- Call the “toString” method and display the year, month, and day.
- Call the “addDays” method with an argument as 5.
- Call the “toString” method and display the year, month, and day.
- Call the “addWeeks” method with an argument as 2.
- Call the “toString” method and display the year, month, and day.
- Create an object for “Date” class
- Call the “daysTo” method and display the result.
- Define the main method.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Building Java Programs: A Back To Basics Approach (5th Edition)
Ch. 8.1 - Prob. 1SCPCh. 8.1 - Prob. 2SCPCh. 8.1 - Prob. 3SCPCh. 8.1 - Prob. 4SCPCh. 8.1 - Prob. 5SCPCh. 8.2 - Prob. 6SCPCh. 8.2 - Prob. 7SCPCh. 8.2 - Prob. 8SCPCh. 8.2 - Prob. 9SCPCh. 8.2 - Prob. 10SCP
Ch. 8.2 - Prob. 11SCPCh. 8.2 - Prob. 12SCPCh. 8.2 - Prob. 13SCPCh. 8.2 - Prob. 14SCPCh. 8.2 - Prob. 15SCPCh. 8.2 - Prob. 16SCPCh. 8.3 - Prob. 17SCPCh. 8.3 - Prob. 18SCPCh. 8.3 - (You must complete Self-Check Problem 7 before...Ch. 8.3 - Prob. 20SCPCh. 8.3 - Prob. 21SCPCh. 8.4 - Prob. 22SCPCh. 8.4 - Prob. 23SCPCh. 8.4 - Prob. 24SCPCh. 8.4 - Prob. 25SCPCh. 8.4 - Prob. 26SCPCh. 8.4 - Prob. 27SCPCh. 8.4 - How does encapsulation allow you to change the...Ch. 8.5 - Prob. 29SCPCh. 8.5 - Prob. 30SCPCh. 8.5 - Prob. 31SCPCh. 8 - Prob. 1ECh. 8 - Add the following mutator method to the Point...Ch. 8 - Add the following accessor method to the Point...Ch. 8 - Add the following accessor method to the Point...Ch. 8 - Add the following accessor method to the Point...Ch. 8 - Add the following accessor method to the Point...Ch. 8 - Add the following mutator method to the TimeSpan...Ch. 8 - Add the following mutator method to the TimeSpan...Ch. 8 - Add the following mutator method to the TimeSpan...Ch. 8 - Add the following mutator method to the Stock...Ch. 8 - Suppose the following BankAccount class has been...Ch. 8 - Add a toString method to the BankAccount class...Ch. 8 - Add a transfer method to the BankAccount class...Ch. 8 - Prob. 14ECh. 8 - Add the following accessor method to your Line...Ch. 8 - Add the following constructor to your Line...Ch. 8 - Add the following accessor method to your Line...Ch. 8 - Write a class called Rectangle that represents a...Ch. 8 - Add the following constructor to your Rectangle...Ch. 8 - Add the following accessor methods to your...Ch. 8 - Add the following method to your Rectangle...Ch. 8 - Add the following method to your Rectangle...Ch. 8 - Add the following method to your Rectangle...Ch. 8 - Prob. 2PPCh. 8 - Prob. 3PP
Knowledge Booster
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education