IMAT4038 – Term 1965 By Dr. Scottie MAN
IMAT4038 Programming Assignment – Integer Calculator
In this programming assignment, you are going to develop an integer calculator to do integer addition and subtraction using Java programming language. The user inputs the mathematical expression at the Command-Line Interface (CLI). For example, the user can input -3+6-8. Your Java program parses the user inputs, does calculations, and shows the result at the CLI.
Requirements and Deliverable
Copyright By PowCoder代写 加微信 powcoder
• Twelve hours (12 hours) are given to you to work on this assignment,
• You are required to upload your source code (.java) to SOUL;
o Make sure source code can be compiled otherwise ZERO marks are given,
o Make sure to upload your code before the due date otherwise ZERO marks are given,
• Use of string-searching libraries are NOT ALLOWED (e.g java.util.regex, but not limited to
it). Otherwise ZERO marks are given.
File Name Convention
In order to easily distinguish the Java code(s) you submitted to SOUL, you must prefix your file names and class names with a capital letter “S” followed by your student ID as shown in following examples.
e.g. Student ID: Java file name: Java class name:
20158967 S20158967.java S20158967
IMAT4038 – Term 1965 By Dr. Scottie MAN
Task 1 – Check user input (Marks: 20%)
Your Java program should ask the user to input the mathematical expression. Then, your program should check the input to make sure its length does not exceed 10 characters. If it happens, your program should print the error message and ask the user to re-enter the expression.
Hint: Use “while loop”, and length() function from String. Please refer to the screenshots below:
Fig. 1.1 Waiting user to input expression
Fig. 1.2 Showing error message when the expression exceeds 10 characters
IMAT4038 – Term 1965 By Dr. Scottie MAN
Task 2 – Parse user input and Perform calculations (Marks: 70%)
Once the expression has no error, your Java program should parse the expression to locate the mathematical operator (+ or -), and then perform the calculations. Once an operator is found, your Java program can accumulate the result to an integer variable that is initialized to zero. You can refer to the following suggestion.
Hint: Use “for loop”; length() function, substring() function, and charAt() function, from String.
Suggestion:
1. Declare an integer variable called sum, and initialize it to zero (e.g. sum = 0),
2. Create a for loop to identify the mathematical operator (e.g. + and -),
a. Once an operator is identified, the corresponding numerical number located at the left-hand side of the operator can be extracted and accumulate to the variable sum mentioned above,
b. Once the last numerical number is identified, its value should be extracted and accumulate to the variable sum mentioned above,
3. Finally print the value of variable sum to the CLI.
Java program can handle no operator (10% out of 70%). For example:
Java program can handle one operator (10% out of 70%). For example:
Java program can handle two operators (20% out of 70%). For example:
IMAT4038 – Term 1965 By Dr. Scottie MAN
Java program can handle more than two operators (30% out of 70%). For example:
Task 3 – Print out the Answer (Marks: 10%)
Once the expression is parsed and the calculation is done, the result should be printed to the CLI.
Please refer to the screenshots below:
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com