COIT11222, 2017 Term Two - Page 1 of 10 COIT11222 Programming Fundamentals T2 2017 Assessment item 1—Java Console Program Due date: Week 6 T2-17 – Midnight, Friday 25 August 2017 Refer below for complete assessment item 1 requirements (Assignment One) ASSESSMENT Weighting: 15% Length: N/A 1 Objectives This assessment item relates to the course learning outcomes as in the Course Profile. Details For this assignment, you are required to develop a Java Console Programs to demonstrate you can use Java constructs including input/output via a command line and using GUI dialogs, Java primitive and built-in data types, Java defined objects, selection and looping statements, methods, and various other Java commands. Your program must produce the correct results. You are only allowed to use techniques which have been covered in the first five weeks of the subject and within the assignment literature, you must use a Scanner object for console input and no advanced data structures like arrays will be used What to submit for this assignment The Java source code: You will be able to complete the assignment in weekly parts in which you will produce four java source files. (More details below) Ass1a.java, Ass1b.java, Ass1c.java, and Ass1d.java. Once you have completed all of the programs and you are ready to submit, compress all source files into a single zip file for submission, do not include your report in the zip file. Only submit a zip not a rar file o Ass1.zip Also submit a report including, how long it took to create (approximately), any problems encountered and screen shots of the output produced. (Use Alt-PrtScrn to capture just the console window or your dialogs and you can paste it into your Word document) You should test every possibility in the program and annotate your test shots. o ReportAss1.docxCOIT11222, 2017 Term Two - Page 2 of 10 You will submit your files by the due date using the “Assignment 1” link on the Moodle course website in the Assessment Block or in the relevant week. Assignment specification This assignment will require you to write four small Java programs, do not panic! They will be small programs which will cover the first five weekly topics. Usually students were required to write one largish program to demonstrate the topics for the first five weeks. Students may get themselves into trouble when the first assignment is due as they have not practiced the basics skills necessary to complete the assignment. With the assignment divided into four programs you can complete each exercise as we cover the weekly topics, do not let yourself fall behind. More importantly, this is a progressive way to complete the assignment. Each small program is built on its previous one (you can re-use the previous small program code), except the first one - Ass1a.java, which is very simple. See Note 1 of Appendix. General Instructions Each program must contain a header comment which contains: Your name and student number, the name of the file, the date and a brief description of the purpose of the program: // Programmer: Eric Gen S01234567 // File: Ass1a.java // Date: August 25 2017 // Purpose: COIT11222 assignment one question one T2-17 // Use Scanner object to input data and display them All programs will be aligned and indented correctly, and contains relevant comments for declarations and statements. All variables and objects will be declared with a meaningful name and use lowercase camel notation: int totalTax; All code will be contained within a main method except for question four when a user defined method will be created and used, in addition to the main method. For this assignment you will not worry about checking numeric ranges or data types. Refer to a Java reference textbook and the course and lecture material (available on the course WEB site) for further information about the Java programming topics required to complete this assignment. Check the marking guide (last page) to ensure you have completed every task. You need to match all output exactly as the sample screenshots shown below. Distance and Rockhampton students can email questions directly to me, other metro campus students should seek help from your local tutor, you can still contact me if it is urgent, I usually respond to emails very promptly. Good luck --- Dr. Michael Li COIT11222 unit coordinator term 2 2017COIT11222, 2017 Term Two - Page 3 of 10 Question one (week 1&2 topics) Input of data types and arithmetic expressions This program will prompt for and read in a tax payer name using a Scanner object and output the name in another prompt. The program will also read the income of this tax payer and output the tax that this tax payer has to pay. At the stage, we assume that the tax rate for all incomes is 10%. You need to replicate the output as shown below. Implementation Create a class called Ass1a (file:Ass1a.java) and within it a main method. Import the Scanner class i.e. import java.util.Scanner; Within your main method create a Scanner object named inText. Create a prompt using System.out.print(“….”); To ask the user for the name of a tax payer. Declare a String object taxPayerName to store the tax payer’s name and use your inText Scanner object and the inbuilt method inText.nextLine(); The tax payer name is now stored in the String object taxPayerName. Hint: you can join variables and strings using the concatenation operator + “Enter the income for “ + taxPayerName + “etc... “ Create another Scanner object inNumber to read the tax payer’s income. Declare an integer variable to store the income and use your inNumber Scanner object and the inbuilt method inNumber.nextInt(); to read the number. Declare a double variable to represent the tax and declare a constant for tax rate 0.1 using the final keyword.COIT11222, 2017 Term Two - Page 4 of 10 How to calculate the tax at this stage The formula for the calculation of tax at this stage is: tax = income×TAX_RATE (Note: This assumes that for all incomes a single value of tax rate is used at the moment for simplicity. From next question we will deal with the different tax rates for different incomes.) Print out the result as above using the concatenation operator. Question two (week three topics) Decision statements Use the pseudo code below to create a class Ass1b (file: Ass1b.java) and a main method which uses decision statements. WRITE "Enter tax payer name==> " READ name WRITE "Enter income for the tax payer==> " READ income IF income is less than 18200 THEN tax=0; ELSE IF income is less than 37000 THEN tax=(income-18200)*0.19 ELSE IF income is less than 87000 THEN tax=3572+(income-37000)*0.325 ELSE IF income is less than 180000 THEN tax=19822+(income-87000)*0.37 ELSE tax=54232+(income-180000)*0.47 ENDIF WRITE “The tax that ” + name + “has to pay is $” + tax The above tax rate scheme is taken from Australian Taxation Office document- Personal Tax Rates 2016- 2017 (see Note 2 of the Appendix). The tax rate scheme looks complicated but actually the corresponding java code segment implementation is pretty easy. If necessary, we will put a hint file on the course website to help you. Don’t worry how to calculate the tax. This program is demonstrating the use of “if” statements in decision making. The program will read one tax payer name and income, and then use the if statements to calculate the tax value according to the above scheme. After the if statements the program will print the tax payer’s name and tax (see sample output below for three separate runs).COIT11222, 2017 Term Two - Page 5 of 10 Implementation Create a class Ass1b.java and a main method and also create Scanner objects as per question 1. Read in the tax payer name and income. Calculate the tax using nested if-else statements as the pseudo code on previous page. Finally output the tax as per the examples above. Follow the above pseudo code, enter a line or two of code and compile, always ensure you are working with clean (error free) code.COIT11222, 2017 Term Two - Page 6 of 10 Question three (week four topics) Repetition while and for loops Create a class Ass1c (file:Ass1c.java) to demonstrate the use of a repetition statement. Implementation Using your solution to question three and a while or for loop, repeat the entry of tax payer names and incomes N times where N is the largest digit in your student ID, if your largest digit is less than three then let N = 3. Hint: use N = 3 while testing and submit using the correct N value. N will be declared as an integer constant using the final keyword and you may need to declare other constants. You are to print a title before the input of the tax payer names and incomes (see sample output). Ensure you are using separate Scanner objects for reading numbers and text. When all of the income have been entered the average of the tax will be reported. Please note you do not need to store the data in an advanced structure such as an array. You will need to have a double variable to add up the taxes to calculate the average. Basically the code in this question is based on last question with adding a loop. Your average tax calculation has to produce a floating point result. To format your average to two decimal places you can use the printf statement with a format string. System.out.printf(“%s %.2f”, “$”, average); You could also use String.format: System.out.println(String.format(“%s %.2f”, “$”, average));COIT11222, 2017 Term Two - Page 7 of 10 Question four (week five topics) Methods and GUI I/O Create a class Ass1d (file:Ass1d.java) by using your previous question solution to question four. This question is identical to question three as the program will read in N tax payer names and incomes, and calculate the tax for each input, however we are going to create a user defined method and we will be using GUI dialog boxes for our I/O. Implementation Methods You will create a value returning method which will accept the income as a parameter. Use the following method header: private static double computeTax(int income) Copy and paste your “if else” code for calculating the tax according to the income from Ass1b.java into the body of our new method computeTax( ). Use the return statement to return the tax value. You can now call your method in the main method loop. double tax = computeTax(income); GUI I/O We will revisit the week two topic using JOptionPane for accepting GUI input and outputting information. First we will output a welcome message using JOptionPane.showMessageDialog. (Replace your console print output) Next we will replace the Scanner objects by using JOptionPane.showInputDialog.COIT11222, 2017 Term Two - Page 8 of 10 The showInputDialog method will return the string entered into the dialog text field String str = JOptionPane.showInputDialog(null, "Prompt"); We receive input from the dialog as a string, in order to convert strings to integers we need the Integer wrapper class and parseInt method (textbook pg 370). int anInt = Integer.parseInt(JOptionPane.showInputDialog(null, "Prompt")); After reading in and converting the income input to an integer you can use this variable to call your user defined method computeTax(). Using the returned tax value you can output this information using: JOptionPane.showMessageDialog You can use the String concatenation operator + to join the String objects with your text in the message dialog. When N tax payers have been entered, you will report the maximum tax value and the corresponding tax payer name. You need to declare a double variable for maximum tax and another String type variable for the corresponding tax payer name. Then inside the for loop, use an if statement to compare the assumed maximum tax value and current tax value.COIT11222, 2017 Term Two - Page 9 of 10 Appendix Note 1. Summary of program constructs Program Constructs Ass1a.java - Main method - Input by using Scanner objects - Output by using System.out.println() - Calculate tax by a simple formula Ass1b.java - Based on Ass1a.java - Use if-else statement to calculate tax Ass1c.java - Based on Ass1b.java - Add a loop Ass1d.java - Based Ass1b.java, or Ass1c.java - Define a user specific method- computeTax() - In main method, call computeTax(), and find maximum tax and corresponding tax payer name Note 2. ATO Tax Rates 2017COIT11222, 2017 Term Two - Page 10 of 10 Marking Scheme Total number of marks – 15 1 Code in general Code is indented and aligned correctly, layout including vertical white space is good 0.5 Code has header comment which includes student name, student ID, date, file name and purpose of the class 0.5 Code is fully commented including all variables 0.5 Variables have meaningful names and use camel notation 0.5 Variables are the correct type 0.5 2 Question one String read correctly using Scanner object 0.5 Integer is read correctly using a Scanner object 0.5 Tax is computed and displayed correctly 0.5 Output is formatted correctly (resembles sample output) 0.25 3 Question two If else statement correct 1 Correct tax is produced 0.5 Output is formatted correctly (resembles sample output) 0.5 4 Question three Constant N used equal to highest digit in student ID, and other constants 0.5 N tax payer names and incomes are read in a loop 1 Program title "Tax Computation System" printed 0.25 Tax printed for all tax payers 0.25 Average is calculated and printed correctly to two decimal places 0.75 Output is formatted correctly (resembles sample output) 0.25 5 Question four Method implementation 1 Double type value returned from method correctly 0.25 Method call correct 0.5 GUI welcome message 0.25 String read correctly from GUI Input dialog 0.25 Income read correctly from GUI Input dialog and converted to an integer 0.5 N tax payer names and incomes are read in a loop 0.25 Maximum tax value is calculated and printed with corresponding name 0.5 Dialogs appear as per specification (resembles sample output) 0.25 6 General Correct files submitted including types and names (zip and Word) 0.5 Only techniques covered during weeks 1-6 are used 0.5 7 Report Report presentation and comments including how long it took and any problems encountered 0.5 Screen shot(s) of testing 0.5