This assignment requires you to write a java program to


Overview

This assignment requires you to write a Java program to carry out a series of operations as specified below. The appendix at the back of the assignment specification provides an example of the output required from the final program.The tasks required of your program will require you to demonstrate your understanding of the programming concepts.

  • • Declaring variables; assigning and testing their values;
  • • Input and output
  • • Reading a Class API, and using objects and behaviours of that class
  • • Decision-making (if and switch statements)
  • • Loops (for loops, while and/or do..while loops, nested loops)

Learning Outcomes Assessed

The following course learning outcomes are assessed by completing this assessment:

  • • K1. identify and use the correct syntax of a common programming language;
  • • K2. recall and use typical programming constructs to design and implement simple software solutions;
  • • K3. reproduce and adapt commonly used basic algorithms;
  • • K4. explain the importance of programming style concepts (documentation, mnemonic names,indentation);
  • • S1. utilise pseudocode and/or algorithms as a major program design technique;
  • • S2. write and implement a solution algorithm using basic programming constructs;
  • • S3. demonstrate debugging and testing skills whilst writing code;
  • • S4. describe program functionality based on analysis of given program code
  • • A1. develop self-reliance and judgement in adapting algorithms to diverse contexts;
  • • A2. design and write program solutions to identified problems using accepted design construct

Assessment Details

Your program must carry out the following tasks, in this order:

• Draw 60 asterisks (*) on the screen followed by a new line character

o This should be accomplished using an appropriate loop construct

• Prompt the user to enter a date. This should be achieved by first entering a year, then a month, then a day within that month – these will all be entered as integer values.

o If the user enters a year earlier than 1900 or later than 2100 they should be asked to re-enter a valid year. This process should repeat until they enter a valid value.

o If the user enters a month less than 1 or greater than 12 they should be asked to re-enter a valid month. This process should repeat until they enter a valid value.

o If the user enters a day less than 1 or greater than the number of days in their chosen month,they should be asked to re-enter a valid day. This should repeat until they enter a valid day.

Note: You do not need to consider leap years – you can assume February always has 28 days.

o The sections of program output for year, month and day should be separated by displaying a line of 30 dashes (-) as shown in the sample output at the back of this document. Printing each of these lines should be accomplished using an appropriate loop construct

o You should be able to do this after we have covered while and do

• Once a valid date has been entered by the user you should compare this to the date 1st of March 2016,and print a message stating the outcome of this comparison (that the user’s entered date is before,after or equal to the 1st March 2016).

o You must do this using the java.util.Date class

o Start by reading the online API for java.util.Date, focusing on the constructors and the comparison methods.

You will notice that Date has been deprecated. This means it has been replaced by another class (in this case GregorianCalendar) and its use is no longer recommended.

However it is better suited to the purposes of this assignment, so ignore any warnings which the compiler generates regarding deprecation.

o Use the values entered by the user to instantiate a Date variable

  • Carefully read the API documentation to ensure you do this correctly

o Instantiate a second Date variable to represent 1st March 2016

o Use methods from the Date class along with an appropriate decision construct to compare the two Dates, and print out a message – the message should include both dates as formatted by the Date class’ toString() method (as shown in the sample output)

• Draw another 60 asterisks (*) on the screen followed by a new line character

o This should be accomplished using an appropriate loop construct

For each integer from 5 to 10, print out the ‘hailstone sequence’ which starts with that number.

o A hailstone sequence is a series of numbers produced by starting with any integer value and repeatedly applying the following rule:

  • If the number is even, divide it by 2 (using integer division)
  • If the number is odd, multiply it by 3 and add 1
  • The sequence ends when it reaches the value of 1

o For example, consider what happens when we start with the value 6.

  • 6 is even, so we divide by 2 getting 3
  • 3 is odd so multiply by 3 and add 1, getting 10
  • 10 is even, so divide by 2 getting 5
  • 5 is odd so multiply by 3 and add 1 getting 16
  • 16 is even so divide by 2 getting 8
  • 8 is even so divide by 2 getting 4
  • 4 is even so divide by 2 getting 2
  • 2 is even so divide by 2 getting 1 and ending the sequence

o You can read more about hailstone sequences here: https://plus.maths.org/content/mathematicalmysteries-hailstone-sequences

o You must calculate and print the values in these sequences using nested loops – we will cover

these in Week 5

• Draw another 60 asterisks (*) on the screen followed by a new line character

o This should be accomplished using an appropriate loop construct

You should be testing your program as each stage is completed, and again once the program is complete. As well as your program code, you must submit a document detailing the testing which you have performed on your program. This should be formatted according to the University’s guidelines for academic work. This should detail the input data given to the program, why that particular data was chosen, and the expected and actual output from the program. You might choose to structure this as a table as shown below:

352_Untitled.png

Your testing should be thorough, including both valid and invalid data, as well as borderline cases. Your mark for this section will reflect the thoroughness of your testing and the quality of your documentation.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: This assignment requires you to write a java program to
Reference No:- TGS01469058

Now Priced at $40 (50% Discount)

Recommended (96%)

Rated (4.8/5)