博客原文:https://bornforthis.cn/1v1/06-KAI/02-Part-1-Birth-Date-Application-30-pts.html
公众号原文:https://mp.weixin.qq.com/s/HIoKBl0bIrdfn4Tjxvc6XQ
Part 1: Birth Date Application: (30 pts)Use MOD % and / division to separate digits for Birthday date Birthdays.java
Ask for the user to enter a two people’s birthday as an 8 digit-number! The user should enter the birthday for each person in an 8-digit format (“YYYYMMDD”). Then your program should compare the two birthday dates to determine which person is older, or if they have the same age.
要求用户输入两个人的生日作为一个 8 位数的数字!
用户应该以 8 位数字格式
(“YYYYMMDD”)
输入每个人的生日。然后你的程序应该比较两个生日日期,以确定谁更年长,或者他们是否有相同的年龄。
For example, President’s Obama’s birthday is Aug 4,1961. So, it should be entered as 19610804 (YYYYMMDD). We can assume that the user enters good data with 8 digits for each birthday so you do not have to do any data validation.
例如,奥巴马总统的生日是1961年8月4日。因此,它应该输入为19610804 (YYYYMMDD)。我们可以假设用户为每个生日输入 8 位数字,这样您就不必进行任何数据验证。
- This program should separate each 8-digit-number into three separate numbers to represent the day, month, and the year, in that order.Only use the mathematical operators to separate the digits (will cover this during class).
这个程序应该将每个8位数字按顺序分成三个单独的数字,分别表示日、月和年。只使用数学运算符来分隔数字 (将在课堂上讨论)。
Thus, in our example the program would assign 4 to a first variable from the right, let’s say day, then assign 8 to a second variable, let’s say month and 1961 to the number variable, let’s say year. (Do not worry about leading zeroes for days and months.)
因此,在我们的例子中,程序会将 4 赋值给右边的第一个变量,比如 day,然后将 8 赋值给第二个变量,比如 month,将 1961 赋值给 number 变量,比如 year。(不用担心天数和月份的前导零。)
Next the program should print out the date of birth written in the following standard format MM/DD/YYYY for each person. So, the output for Obama’s date of birth should be as follow: 8/4/1961
接下来,程序将为每个人打印出以以下标准格式写的出生日期 MM/DD/YYYY。因此,奥巴马出生日期的输出应该如下: 8/4/1961
Also, your program should be able to print which person is older or the other possibility that they are the same age. You should use control structure allowing program to make decision (smart). So, result should be decided by program and not you.
另外,你的程序应该能够打印出哪个人更老,或者他们是相同年龄的其他可能性。你应该使用允许程序做出决策(智能)的控制结构。所以,结果应该由程序决定,而不是由你决定。
Example (Comparing Obama’s to Beyoncé Birthday):
Enter the birthday in 8-digit format for person’s # 1: (YYYYMMDD): 19610804
Enter the birthday in 8-digit format for person’s # 2, (YYYYMMDD): 19810904
For this example, the following result will be printed:
Enter name for person #1: Obama
Enter name for person #2: Beyoncé
Obama’s date of birth is: 8/4/1961
Beyoncé’s date of birth is: 9/4/1981
Obama is Older than Beyoncé!
Grading Criteria:
A. Program Execution (90%)
Meeting all of the require
答案
1. 整数分割
2. 年月日分割
3. 编写成对象
4. main
5. 标准代码