Calculate the number of days the user has been alive

Assignment Help JAVA Programming
Reference no: EM132349874

Assignment - Specification

Chinese Zodiac

Goals and Topics

The assignment problem is straightforward. All necessary details have been supplied. The solution of the problem will be straight line code which will use the programming concepts and strategies covered in Workshops 1-3. The subgoals are:

- Understanding values, variables constants, arrays, objects, operations, and the use of functions
- Translating simple design into JavaScript code
- The mechanism of editing, interpreting, building, running, and testing a program
- Commenting source code
- Becoming confident and comfortable with programming in small scale problem solving

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

Constants and Variables

Within the script section, create constants and variables following professional conventions and initialise them with right values. Some constants have been suggested in the following table.

Table 1: Constants

Description

Value

Number of milliseconds in a day

1000*60*60*24

The cycle of Chinese Zodiac

12

The year starting a Chinese Zodiac cycle

1024

The array to store 12 zodiac signs

'Rat', 'Ox', 'Tiger', 'Rabbit', 'Dragon', 'Snake',

'Horse', 'Goat', 'Monkey', 'Rooster', 'Dog',  'Pig'

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 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 minues 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 reminder 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 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 different web browsers could be different, and they are not a concern in this assignment.

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.

Attachment:- Chinese Zodiac Specification.rar

Reference no: EM132349874

Questions Cloud

What has been the impact of kelo vs the city of new london : What has been the impact of Kelo vs the City of New London, CT in Land-Use Control in rural communities of the US?
Legislation to protect homeowners from foreclosure : During the past 5 years or so, Congress has aggressively passed legislation to protect homeowners from foreclosure. In your opinion, is that appropriate?
Which piece of federal legislation do you consider : Which piece of federal legislation do you consider to be the most critical law that protects the public in matters related to fair housing? Why?
Us constitution and the bill of rights : Do you agree or disagree with this position that the federal government's obligation to regulate the housing industry and real estate is linked to the US
Calculate the number of days the user has been alive : CSC1401 - Foundation Programming - University of Southern Queensland - write a program to accept user inputs for the date of birth, calculate the number of days
Established a monopoly under the sherman act : Ines Inventor creates a new telecommunications device that she markets under her the brand name Alter Ego. The device combines the functionality of a telephone
What will be an example of circumstances : What will be an example of circumstances that will trigger the application of Statute of Frauds due to the one-year rule?
Higher price was the product of undue influence : Bully Corporation contracted to sell Wimp Corporation materials that Wimp needed to fulfill a contract it had with a third party.
Are laws effective in maintaining standard uses : Are laws effective in maintaining standard uses of property and in setting boundaries on what businesses can do?

Reviews

len2349874

7/31/2019 11:11:21 PM

13 Non-functional Requirements The program has a complete structure including all head, body, script sections defined by appropriate tags Identifiers of variables and constants are following professional conventions Constants and variables are used in calculation and expression instead of explicit values At least three comments are added to describe the purpose of blocks of code Subtotal 1 14 1 15 1 16 1 4 TOTAL 16

len2349874

7/31/2019 11:11:15 PM

5 Functional Requirements The program is running without any syntax errors All constants and variables are declared and initialised appropriately The array for Chinese Zodiac signs is created and used correctly The Date objects are created and used correctly Functions including those of Date and Math objects are used correctly The user’s days alive is calculated correctly The user’s Chinese Zodiac sign is calculated correctly The calculating results are displaying appropriately Subtotal 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 8

len2349874

7/31/2019 11:11:08 PM

Table 2: Marking Criteria ID REQUIREMENTS MARK 1 Statement of Completeness The statement is in appropriate length of 200-300 of student’s own words The “State of assignment” reflects the true state of completeness The “Problems encountered” discusses problems and dealing strategies The “reflection” discusses learnt lessons and reasonable suggestions Subtotal 1 2 1 3 1 4 1 4

len2349874

7/31/2019 11:10:53 PM

The assignment will be marked out of 16 and scaled down to a grade out of 8. Table 2 presents the marking criteria. If all criteria are satisfied you will receive 16 marks. If not all criteria are met, part marks may be given. Check your own submission against these criteria before you submit.

len2349874

7/31/2019 11:10:46 PM

Plan to complete the assignment on time. Do not write all of the code in one sitting and expect that everything will be working smoothly like a magic. First step Read assignment specification, clarify anything unclear by putting a post on the As- signment 1 Forum, think about how to do it, how to test it, devise high-level algorithms for each independent part of the assignment. Begin to type program (with comments), in incremental stages. Seek help on assignment forum if needed. Second step Re-read the specification, continue to refine design of various sections to code, bring up any problems to the assignment forum if necessary. Finish initial coding. Third step Fully test the program; have another review on the source code; re-read the speci- fication (especially marking criteria) to make sure you have done exactly what is required. Complete the “Statement of Completeness”.

len2349874

7/31/2019 11:10:32 PM

What You Need to Submit – Two Files For a complete submission you need to submit two files as specified below. The assignment submission system will accept only the files with extensions specified in this section. 1. Statement of Completeness in a file saved in .pdf format with 200–300 of your own words describes: - The state of your assignment, such as, any known functionality that has not been implemented and delivered, etc. (It is expected that most people will implement all of the functionality required by this assignment.) - Problem encountered, such as, any technical problems that you encountered during the assignment work and how you dealt with them; - Reflection, such as, any lessons learnt in doing the assignment and suggestions to future programming study or work. 2. The program in a file saved with an .html extension contains the source code implemented following the functional and non-functional requirements.

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd