Essay Help Services

CSC1401| Chinese Zodiac Specification Assignment | Science

Home Recent Questions CSC1401| Chinese Zodiac Specification Assignment | Science

Your Task

 Your task will be to write a program to accept user inputs for the date of birth, calculate the number of days the user has been alive, and give the corresponding Chinese Zodiac sign.

Inputs

The following inputs should be declared as variables and initialised at the beginning of your pro-gram:

- The year of birth (a valid 4 digit year);

- The month of birth (a valid integer number from 1 to 12, representing January to December);

- The date (in the month) of birth (an integer number from 1 to 31, representing a valid date of the month).

Code has been provided to handle the following tasks1:

- to receive inputs from the user;

- to convert the user inputs (String) to the proper type (Number).

//Accept user inputs for DOB and convert them into Number. The default value is set as 31/12/2016.

parseInt(prompt(’Enter the year of birth as a 4 digit integer’, ’2016’)); parseInt(prompt(’Enter the month of birth as an integer, ranging from 1 to 12’, ’12’)); parseInt(prompt(’Enter the date of birth as an integer, ranging from 1 to 31’, ’31’));

Such statements will return the user inputs in proper Number type. You need to create some variables to store such returned results for further calculations in the program. In this assignment, we assume that the user inputs are always valid, e.g., the value entered for month is an integer number within the range of 1 – 12, etc. You are not required to validate the values input by the user.

Functional Requirements

Calculation

1. Create a Date object for the date of birth based on the user input.

- Send the Date constructor the year, month number and date. Please notice that, in the Date constructor, the number for month is starting from 0, rather than 1.

2. Create a Date object for the current time;

- No arguments supplied to the constructor

3. Calculate the user’s age in milliseconds

- Dates are stored in milliseconds since 1 Jan 1970;

- Use the getTime() function to get a Date object’s time in milliseconds

- Deduct the user’s date of birth time from the current time

4. Calculate the user’s age in days

- Divide the user’s age in milliseconds by the number of milliseconds in a day.

- use the Math.floor() function to reduce the number to an integer.

5. Calculate the Chinese Zodiac

(a) Initialise an array object to host the String values of 12 Chinese Zodiac animal signs in the correct order;

(b) In 1024 the Chinese Zodiac started a new cycle with the animal “Rat”. Create a constant for the year of 1024;

(c) Use the minutes operator to calculate the number of years between the user’s year of birth and the constant created in (b);

(d) Use the mod operator to find the remainder after dividing the result of (c) by the constant created for the number of years in a Chinese Zodiac cycle;

(e) Use the reminder as an index to find the correct animal sign in the Chinese Zodiac sign array created in (a).

Output

1. An alert statement to display the user’s birthday by using the toDateString() function for Date object created for the user’s date of birth. For example, “Your date of birth is Tue Apr 01 1980 ”;

2. An alert statement to display how many days the user has been alive. For example, “You have been alive for 13489 days”;

3. An alert statement to display the corresponding Chinese Zodiac animal sign. For example, “Your Chinese Zodiac sign is Monkey”.


The following figures illustrate the results displayed regarding inputs of a user whose birthday is April 01, 1980, tested on March 07, 2017. Note that the layout of alert window and the font of text on di↵erent web browsers could be di↵erent, and they are not a concern in this assignment.

Testing

• Enter the user birthday into the “Your Age in Days” system on http://jalu.ch/coding/days/en and compare the result with that calculated by your program to test the days alive calculation;

• Compare the Chinese Zodiac result calculated in your program with the chart in http://en.wikipedia.org/wiki/Chinese zodiac to perform the logic test for your program.

Non-functional Requirements

Structure of the Source Code

- All code should appear in the script section in the head of the HTML document.

- Do not write any code in the HTML body. Deliver all functionality by JavaScript.

- In the script order your code as follows:

(a) Constants;

(b) Variables and objects (declared and initialised);

(c) Other statements.

Comments

- You are required to add at least three comments to the source code.

- Do not comment every single line, instead, comment on blocks of code with a common purpose.

- Do not simply translate the syntax into English for comments, instead, describe the purpose of the code.

Similar Posts

Search Here

Order Now

Latest Reviews

Facebook

Payments And Security