ITECH1000/5000 Programming 1
{`ITECH1000/5000: Programming 1 School of Engineering and Information Technology Assignment 1 Federation University Australia `}
Purpose
To provide students with the opportunity to apply the knowledge acquired and skills developed during the first 6 weeks of the Course. These include understanding of primitive data types and the concept of collections (in the form of arrays) as well as structured programming including sequence, selection and repetition.
Learning Objectives
In the process of this assessment task you will:
- Identify and use the correct syntax of a common programming language (Java);
- Describe program functionality based on analysis of a given program;
- Recall and use typical programming constructs to analyse, design and implement simple software solutions; and
- demonstrate debugging and testing skills whilst writing code.
General Requirements
- Provide evidence of code comprehension skills by answering questions relating to the starting code provided; and
- Complete the analysis, design, implementation and debugging of a small program that is predominantly procedural in nature
Understanding and Enhancement of a Simple Menu Driven Program
Application Overview
For this assignment you have been provided with incomplete starter code that you must understand, modify and add to. The system provided simulates the collection, modification and reporting of game characters. The game characters have a unique id created in the program and have a number of attributes including a health rating and a power value. The system is run within the Eclipse IDE and provides a menu through the IDE console. The user must enter a pre-defined number of game characters before any of the other functionality can be used. At present, the following menu items are working:
- Create your characters;
- Display formatted information of all characters;
- Display a particular character;
- Display total legs and power for all characters; and
- Empower your character.
One function listed on the menu is not working:
- Display entered information of all characters
You must write the code for the missing function.
Additionally, there are some changes required to the existing code. These changes are required to demonstrate the variety of ways of dealing with sequencing, selection and repetition and also demonstrate your capabilities for understanding and changing the code.
PART A – Code Comprehension
The sample code provided in the GameCharacters.java class should be used to answer the following questions. Familiarise yourself with the operation of the application by running it and choosing the working options – 1,3,4,5,6:
- Identify in the code the way in which users interact with the program. Identify the object and list the lines of code where the object is used to receive information from the user. Also list the lines of code where the program sends output to the user.
- What is the purpose of the “\t” in some of the literal Strings presented in the code?
- How many game characters can be entered for this system? How many attributes does each character have? Identify the three lines of code where this information is established.
- Currently, if the user enters an incorrect menu selection, what happens? Explain why the error message is displayed and what method and line of code is responsible and why.
- The method menuSystem() is replaced with the code below. What would be shown for option 3 – display formatted information of all characters – if you had not yet entered any data (menuSelection ==1)? Where did the information displayed come from?
- Explain in your own words what is happening on each line of the method createCharacterCode(int x).
- After entering the required number of game characters, choose option 3 to display formatted information of all characters and complete the following table of variable values after executing each line of the method decodeCharacterCode(int _code, int _row). Use a _row value of 1 and if a variable is not defined at any stage, use the text ‘not defined’:
Line _code _row decodedCharCode 314 315 316 316 318 319 - Now change the value of the FACTOR constant to 1000. Compile and run the application entering another set of game characters and choose option 3 to display the information. The code and studentID are incorrect on the report. What has gone wrong?
- In the createCharacterCode(int x) method, line 212 has the operation almostCharacterCode = almostCharacterCode * FACTOR; What would happen if you changed the “*” to a “/”? What primitive data type is almostCharacterCode and what would a more appropriate data type be if you changed the “*” to a “/”?
- In the displayCharacterDetails(int _a) method a switch statement has been used to assist in assembling the String that lists the attributes of each character. The break keyword is used in this switch statement. What would happen if the break statement was removed after the first case (line 297)? You should discuss what generally happens with a switch statement when you remove the break and what actually happened here from an application perspective. What java error occurs?
- When entering characters, how many times is the createCharacterCode(int x) method executed? In the method itself, the condition if (almostCharacterCode == 0) exists. What other variable could have been used instead of almostCharacterCode to achieve the same outcome?
- Explain the purpose of the boolean variable finished in the addPowerToCharacter () method and how it is used.
PART B – Programming Requirements
- Provide the code for the displayAllCharactersRaw () method. You are expected to just list what has been entered by the user in “raw” form as well as the generated character code without any interpretation (i.e. the data as stored in the two dimensional array). In your solution you must use nested for loops and the constants for array dimensions. You must also only have one print statement in the outer loop detailing the attributes for the current character. This is done by using a String and concatenating to it. Look at the charAttrs variable in the displayCharacterDetails(int _a) method for an example of this.
- Add any functionality required to allow two new power types to be added. Hint: you do not need to write any new lines of code. The power types and their values should be unique to each student.
- In the createCharacters () method, change the while loop for obtaining the studentID to a priming read while loop. Look at your lecture notes for week 4 for information on this.
- In the displayCharacterDetails(int _a) method, replace the switch statement with a series of if/else if combinations to achieve the same functionality.
- In the displayTotalLegsAndPower() method replace the for loop with a while loop. Look at your lecture notes from week 5 for information about this.
- In the obtainCharacterAttribute(String _introText, String[] _typesText, int _min, int _max) method change the while loop to a do while loop.
PART C – Testing
An important part of verifying what you have done is testing. As per your lecture notes from week 5 you should consider:
- Ensuring that the program is what the client is asking for (you have to be both client and programmer here);
- Testing the design of the program to check that it meets the requirements;
- Desk checking the code written; and
- Testing the implementation of the code.
When testing, you should be able to distinguish between syntax, runtime and logic errors. Syntax errors are expected to be eliminated before submission (Eclipse IDE helps with this). Runtime and Logic errors are also expected to be eliminated if sufficient testing has occurred.
You should at this early stage satisfy yourself and provide evidence that any changes you have made in PART B work as they should and have not had any adverse impact on other components.
As a minimum you should provide evidence of the output of the system and its various functions before the changes and evidence of this after the changes. It is suggested that you make use of tables to display the data and testing.
ITECH1000/5000: Programming 1 Assignment 1 Federation University Australia
Overview
This is an individual assignment that requires you to design, develop and test a small procedural Java program.
Learning Outcomes Assessed
The following course learning outcomes are assessed by completing this assessment:
- Identify and use the correct syntax of a common programming language
- Recall and use typical programming constructs to design and implement simple software solutions
- Reproduce and adapt commonly used basic algorithms
- Utilise pseudocode and/or algorithms as a major program design technique
- Write and implement a solution algorithm using basic programming constructs
- Demonstrate debugging and testing skills whilst writing code
- Develop self-reliance and judgement in adapting algorithms to diverse contexts
- Design and write program solutions to identified problems using accepted design constructs
Assessment Details
Your task is to design, develop and test a small application which will allow a mobile phone user to compare the cost of their phone usage under plans from two different phone providers.
Stage 1: Design
This stage requires you to prepare documentation that describes the function of the program and how it is to be tested. There is no coding or code testing involved in this stage. A document template has been provided for your use.
Requirements:
- Read through Stage 2: Program Development to obtain details of the requirements of this program.
- Write an algorithm that describes how the program will operate.
- All program requirements – base, standard and advanced – must be included, even if you do not end up including all these requirements in your program code.
- The algorithm must be structured logically so that the program would function correctly.
- Prepare and document test cases that can be used to check that the program works correctly, once it has been coded. You do NOT need to actually run the test cases in this stage; this will occur in Stage 3: Testing.
- All program requirements – base, standard and advanced, must be included, even if you do not end up including all these requirements in your program code.
- Make sure the test cases include checking of data entered by the user to make sure that only valid data is accepted. If the user enters invalid data, the user should be informed of this and given another chance to enter the data. NB: As we have not covered exception handling, you may assume that the user will always enter a value of the correct type (i.e. an integer when an integer is requested).
- Test cases should be documented using a template like the one below. You may include extra information if you wish. At this stage, the Actual Result column will be left blank.
Test Case |
Expected Result |
Actual Result |
The user enters a negative number when prompted to enter the number of MB of data used: Enter the amount of data in MB: -5 |
The user should be informed of the error and prompted to re-enter a positive number: Value must be positive. Please try again: |
Stage 2: Program Development
Using the Design Documentation to assist you, develop a Java program that allows the user to enter details of their phone usage and then compare the bill which would result from this usage under different billing plans. These requirements have been broken into three groups:
- Base Functionality includes the minimal level of requirements to achieve the essential components of this assignment. This group of requirements focuses on getting the code to work and on using the programming constructs we cover in class. You can expect to use constants, variables, loops, conditional statements and arithmetic operators for these requirements and you should look for opportunities to use these wherever you can. You will not receive full marks for implementing a requirement, even if it works, if you have not used the appropriate programming construct to do so.
At this level, you can decide if it is easier for you to code everything within a single method, or to modularize it straight away.
- Standard Functionality ensures the code is modularized, and that method calls are used to ensure the program flows correctly. It allows data to pass from one method to another as parameters. It also includes implementing one additional billing plan which is slightly more complex than the two plans used in the Base Functionality.
- Advanced Functionality provides a challenge task, and is best left until all the other requirements have been addressed. It requires looking at a Java API to find out how to use a class we have not covered in the course, and using this to apply a discounting to phone calls made on a weekend.
All three groups require that you follow coding conventions, such as proper layout of code, using naming conventions and writing meaningful comments throughout your program.
Base Functionality:
- Display a welcome message when the program starts
- The welcome message should have a row of equals signs (=) at the top and the bottom, just long enough to extend over the text. Hint: Use a For loop for this.
- The first line of the message should read “FEDERATION UNIVERSITY PHONE BILL COMPARISON SYSTEM” and be approximately centered in the row of equals signs by printing white space first. Hint: Can you modify the For loop from the previous step to print the white spaces?
- The second line of the message should be blank.
- The third line should read “Developed by” followed by your name and a comma, then “ student ID ”, then your student id, then finally “ for ITECH1000/5000 Sem 1 2017”.
- The fourth line should be blank, and the fifth should be another row of ====
- Provide a menu from which the user can select to Enter Usage Details, Display Cost Under Plan A, Display Cost Under Plan B, Clear Usage, or Exit System. This menu should be repeated each time after the user has chosen and completed an option until the user chooses to Exit. The user selects an option by entering the number next to it. If an invalid number is selected, the user is advised to make another selection.
MAIN MENU Please select an option from the menu:
- Enter Usage Details
- Display Cost Under Plan A
- Display Cost Under Plan B
- Clear Usage Details
- Exit System
6
Value must be between 1 and 5. Please try again:
0
Value must be between 1 and 5. Please try again: 1
- When the user selects the Enter Usage Details option, provide another menu from which the user can select Phone Call, SMS, Data Usage, or Return to Main Menu. The user selects an option by entering the number next to it. If an invalid number is selected, the user is told to make another selection.
ENTER USAGE DETAILS MENU
Please select an option from the menu:
- Phone Call
- SMS
- Data Usage
- Return to main menu
- Should the user select Phone Call, they are prompted to enter the length of the call in seconds. The value entered must be positive – if not, the user should be prompted to reenter a new value. After entering a valid call length, the user is returned to the Enter Usage Details Menu so that they may choose to enter additional usage details.
1
Enter call length in seconds:
0
Value must be positive. Please try again:
27
ENTER USAGE DETAILS MENU
Please select an option from the menu:
- Phone Call
- SMS
- Data Usage
- Return to main menu
- Should the user select SMS, the program should simply increment the count of the number of SMS messages. No further information is required so the program should simply display the total number of SMS messages recorded so far, and then return to the Enter Usage Details Menu.
2
Total number of SMS so far = 1
- Should the user select Data Usage, they should be prompted to enter the amount of data used in MB (it will be assumed that this is an integer value). The value entered must be positive – if not, the user should be prompted to re-enter a new value. After entering a valid value, the user is returned to the Enter Usage Details Menu so that they may choose to enter additional usage details.
3
Enter the amount of data in MB:
-5
Value must be positive. Please try again:
120
- When the user selects the Display Cost Under Plan A option, the program should display a summary of the usage details which have been entered, and their cost under Plan A, along with the total cost, formatted as shown in the screenshot below. The cost structure for Plan A is listed in the following table. Once the bill summary has been displayed, the program should return to the Main Menu.
Usage Item |
Item Cost – Plan A |
Per phone call (flag fall charge) |
$0.23 |
Per second of total time over all phone calls |
$0.02 |
Per SMS |
$0.12 |
Per MB of data usage |
$0.03 |
Cost under Plan A
{`====
Number of calls = 3 $0.69
Total call time (secs) = 202 $4.4
Number of SMS = 3 $0.36 Data usage (MB) = 120 $3.60
====
TOTAL COST $8.69
To assist in formatting the display of the costs in this step, you may copy the following method into your code and make use of it.
// Print the specified value in cents in dollar and cents format privatestaticvoid displayAsDollarsAndCents(int cents)
{
System.out.print("$" + (cents/100) + "." + (cents%100));
}
`}
- When the user selects the Display Cost Under Plan B option, the program should do the same as in Step 4, but using Plan B’s cost structure instead, which is listed in the following table, and then return to the Main Menu.
Usage Item |
Item Cost – Plan B |
Per phone call (flag fall charge) |
$0.17 |
Per second of total time over all phone calls |
$0.03 |
Per SMS |
$0.15 |
Per MB of data usage |
$0.02 |
Cost under Plan B
=====
Number of calls = 3 $0.51
Total call time (secs) = 202 $6.6
Number of SMS = 3 $0.45 Data usage (MB) = 120 $2.40
=====
TOTAL COST $9.42
- When the user selects Clear Usage Details the value of all variables related to the usage (number of calls, total length of calls, number of SMS, total data usage) should all be reset to 0. A message reporting this should be displayed as shown below (including the rows of equals signs), and the program should return to the Main Menu.
====== ALL USAGE DETAILS HAVE BEEN RESET TO 0
======
- When the user selects Exit System, quit the program with a message to the user.
====== Thank you for using this software. We hope you found it useful.
=======
Standard Functionality:
- Add an additional option to the Main Menu to Display Cost Under Plan C. When this option is selected, the program should display the cost under this Plan in the same way as previously done for Plans A and B, but using Plan C’s pricing structure as shown below. Note that Plan C charges data at a different rate based on whether the user has exceed the cap of 100MB or not. Usage up to and including the first 100MB is charged at the lower rate; any further usage above 100MB is charged at a higher rate.
Usage Item |
Item Cost – Plan C |
Per phone call (flag fall charge) |
$0.11 |
Per second of total time over all phone calls |
$0.03 |
Per SMS |
$0.09 |
Per MB of data usage up to 100MB |
$0.02 |
Per MB of data usage over 100MB |
$0.10 |
- Modularize the code, correctly using method calls and passing data between methods as parameters.
Advanced Functionality:
- All the companies have introduced a new policy that phone calls are not timed if they are made on weekends (only the flagfall charge is applied). Modify the code from Stage 3, so that when the user selects the Enter Usage Details option, they are first prompted to enter a date (as a day, then a month, then a year). The program should check whether this data is on a weekend, and if so there is no need to ask the user to enter the length of the call when the Phone Call option is selected (note that the flagfall charge is still incurred).
- Use the java.util.GregorianCalendar class to store the data entered by the user.
- If you have a GregorianCalendar object called g, you can obtain a number representing the day of the week by calling
g.get (GregorianCalendar.DAY_OF_WEEK);
This returns a value from 1 to 7 representing the day of the week corresponding to the current data stored in the GregorianCalendar object. 1 is Sunday and 7 is Saturday.
Stage 3: Testing
Using a copy of the test cases developed in Stage 1: Design, test the program you have developed in Stage 2: Program Development. Document your results, including both failed and successful tests. Note: Please do not leave out any failed tests. If your testing highlights that your program has not worked correctly, then the failed tests help to demonstrate that you have been testing your program properly.
To show that you have tested your program, include small (but readable) screen captures in your Actual Results as well as any explanatory comments. Microsoft Windows includes a Snipping Tool that is useful for taking captures of the relevant parts of the screen.
You may test your program in phases if you wish. Stage 2: Program Development provides three separate groups of functionality in the requirements, working from the minimal level of requirements through to more advanced concepts. Each of these groups can be tested individually.
Base Functionality:
This phase requires you to check that the base functions (displaying welcome message when the program starts, showing a menu of options until the user chooses to exit, entering and clearing usage details, viewing bills under Plans A and B, and exiting the system) have been implemented.
Standard Functionality:
In addition to the Base Functionality, this section includes implementing viewing of bills under Plan C. This new functionality must also be tested.
If you originally wrote and tested the Base Functionality by including all the code in a single method, this phase also requires that you modularize your code, and use method calls and pass data between methods to ensure your program still runs correctly. This means all your code will need to be retested to ensure that all the previous functionality still works.
Advanced Functionality:
This phase requires testing the code that gets a date from the user, which tests if that date is on the weekend, and which ignores the length of any calls made on the weekend.
ITECH1000/5000: Programming 1 School of Engineering and Information Technology Assignment 1 Federation University Australia
Assignment 1
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 covered in Weeks 1-5 of the course:
- 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:
- identify and use the correct syntax of a common programming language;
- recall and use typical programming constructs to design and implement simple software solutions;
- reproduce and adapt commonly used basic algorithms;
- explain the importance of programming style concepts (documentation, mnemonic names, indentation);
- utilise pseudocode and/or algorithms as a major program design technique;
- write and implement a solution algorithm using basic programming constructs;
- demonstrate debugging and testing skills whilst writing code;
- describe program functionality based on analysis of given program code
- develop self-reliance and judgement in adapting algorithms to diverse contexts;
- A2. design and write program solutions to identified problems using accepted design constructs
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 o You should be able to do this after Week 4
- 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.
- 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.
- 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.
- 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
- You should be able to do this after we have covered while and do..while loops in Week 5
- 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).
- You must do this using the java.util.Date class
- 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.
- 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
- 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)
- The relevant material for this will be covered in Weeks 2 and 3
- 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
- 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:
Test case |
Justification |
Expected outcome |
Actual outcome |
Year = 2500 |
Testing for a year greater than the maximum allowed |
“Error – value outside of range” |
“Error – value outside of range” |
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.
Submission
Your assignment should be completed according to the General Guidelines for Presentation of Academic Work.
The following criteria will be used when marking your assignment:
- successful completion of the required tasks
- quality of code that adheres to the programming standards for the course including:
- comments and documentation
- code layout
- meaningful variable names
- use of constants
You are required to provide documentation, contained in an appropriate file, which includes:
- a front page - indicating your name, a statement of what has been completed and acknowledgement of the names of all people (including other students and people outside of the university) who have assisted you and details on what parts of the assignment that they have assisted you with
- details of test data and evidence that the testing was conducted
- list of references used (APA style); please specify if none have been used.
Using the link provided in Moodle, please upload the following in one zip file:
- your code (SurnameStudentIdAssign1.java)
- your report (surnameStudentIDAssign1.docx)
If you encounter any problems in uploading files to moodle please report this to your lecturer or other staff member as soon as possible.
It is your responsibility to check that you are submitting the correct version of your files.
NOTE: If you use any resources apart from the course material to complete your assignment you MUST provide an in-text citation within your documentation and/or code, as well as providing a list of references in APA formatting. This includes the use of any websites, online forums, books or text books. If you are unsure of how to do this please ask for help.
Marking Criteria/Rubric
Your program will be marked based on the extent to which it correctly implements the required functionality. The marking scheme will also take into account whether your code is written in a good style, as covered in classes. For example it should be well commented, use meaningful variable names which are consistent with the Java conventions, and be clearly laid out with correct and consistent indenting.
For complete marks your program should also make use of the principles of modularisation as covered in Week 6. It is suggested that you initially develop your program without using methods, as you start this in Weeks 3 to 4 once the relevant material has been covered. Once it is working correctly, make a backup copy which you can submit if your attempt at code modularisation is successful. Then attempt to identify repeated or very similar sections of code, and convert them into methods (using parameters if appropriate).
Displaying lines of **** and ---- where required |
/10 |
User entry of a date |
/25 |
Creation and comparison of Date objects |
/10 |
Displaying hailstone sequences |
/25 |
Modularisation of code / use of methods |
/10 |
Testing and documentation |
/10 |
Following correct coding style - Note: this will be limited by the % of the program which you attempt |
/10 |
Total /20 marks |
/100 |
Sample Program Output
************************************************************ ------ Enter a year. Enter a value between 1900 and 2100: 2217 Error - your value is outside of the range allowed. Try again. Enter a value between 1900 and 2100: 1817 Error - your value is outside of the range allowed. Try again. Enter a value between 1900 and 2100: 2004 ------- Now enter a month. Enter a value between 1 and 12: -1 Error - your value is outside of the range allowed. Try again. Enter a value between 1 and 12: 2 ----- Now enter a day. Enter a value between 1 and 28: 29 Error - your value is outside of the range allowed. Try again. Enter a value between 1 and 28: 4 -------------- Wed Feb 04 00:00:00 EST 2004 is before Tue Mar 01 00:00:00 EST 2016 ************************************************************ 5: 16 8 4 2 1 6: 3 10 5 16 8 4 2 1 7: 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 8: 4 2 1 9: 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 10: 5 16 8 4 2 1 ****************