On This Page
Overview
During this assignment, you will:
- Compile a program.
- Convert mathematical formulas to arithmetic expressions.
- Use methods from the Java
Math package.
- Document your program.
^ top
Specifications
Using the starter code, convert each of the following mathematical equations to an arithmetic expression.
a + b - c

(a - b)2


Code each expression after the expression-variable of the starter code that matches the equation number. For instance, equation 1 matches expr1 in the starter code. Thus, the arithmetic expression is assigned to expr1 of the starter code.
After you compile the program, You can run the program by typing at the command line something like:
java Expressions 1 4 2 3
where 1 4 2 3 matches up with a, b, c and d respectively.
The output of the program should look similar to the sample output shown below.
Sample Output
>java Expressions 1 4 2 3
a = 1.0, b = 4.0, c = 2.0, d = 3.0
Expression 1: 3.0
Expression 2: -17.22222222222222
Expression 3: 9.0
Expression 4: 5.0
Expression 5: 3.1622776601683795
Additional specification are:
- The name of the class must be
Expressions
- You must print the labels, such as Expression 1, to receive full credit.
- Create a file comment block at the top of your page formatted like the following:
/**
* CS-12J Asn 2
* Expressions.java
* Purpose: Prints results of various expressions to the screen.
*
* @author Ed Parrish
* @version 1.0 2/2/04
*/
Use your own name and date, of course.
- Make certain that you have no tab characters in your source code.
- In addition, make sure you have spaces before and after operators.
- Do not worry about magic numbers for this assignment.
Starter Code
public class Expressions {
// You can ignore the next few lines
public static void main(String[] args) {
double a = Double.parseDouble(args[0]);
double b = Double.parseDouble(args[1]);
double c = Double.parseDouble(args[2]);
double d = Double.parseDouble(args[3]);
System.out.println("a = " + a + ", b = " + b
+ ", c = " + c + ", d = " + d);
// Make changes after this line
double expr1 = 0; // change this line for expression 1
System.out.println("Expression 1: " + expr1); // do not change line
double expr2 = 0; // change this line for expression 2
System.out.println("Expression 2: " + expr2); // do not change line
double expr3 = 0; // change this line for expression 3
System.out.println("Expression 3: " + expr3); // do not change line
double expr4 = 0; // change this line for expression 4
System.out.println("Expression 4: " + expr4); // do not change line
double expr5 = 0; // change this line for expression 5
System.out.println("Expression 5: " + expr5); // do not change line
}
// Add extra credit after this line
}
^ top
Extra Credit
Adding the following to your program are worth extra credit points:
- Convert the following mathematical equation to an arithmetic expression with a label of
Expression 6 (1 point):

- Convert the following mathematical equation to an arithmetic expression with a label of
Expression 7 (1 point):
aebc
The letter e in the above formula is the mathematical symbol for the exponent which is the base of the natural logarithms. To represent this in Java, you will need to use the exp method of the Math class. For instructions on using the Math class, see the textbook on page 80.
Include the extra credit code in your Expressions.java file. Make certain that your README.txt file describes any extra credit attempted.
^ top
Grading Criteria
The instructor will evaluate your assignment using the following criteria. Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive.
Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.
For information on grading policies, including interpretation of scores, see the course information page.
Program Compilation
- 4: Source code compiles with no errors or warnings
- 2: Source code compiles with warnings
- 0: Does not compile or wrong file turned in
Functionality
Two (2) points for each correct arithmetic expression (10 points possible).
Programming Style
- 4: Code is well-documented
- Name, date, and program description in file comment block
- Follows specified format for file comment block
- Proper use of spaces around operators
- No tab characters are present in the source code
- As described in How To Document and Organize Java Code
- Correct file name used
- 3: Code has minor documentation errors
- Has 1 documentation error
- 2: Code has some documentation errors
- Has 2-3 documentation errors
- 1: Code has many documentation errors
- Has more than 3 documentation errors
- 0: No apparent attempt to document code
REAME.txt File
- 2:
README.txt file submitted with specified information included
- 1:
README.txt file submitted but some information was missing
- 0: No
README.txt file submitted
Maximum Score: 20, plus extra credit
^ top
What to Turn In
Submit your assignment following the instructions for homework. Include the following items for grading:
README.txt file
Expressions.java source code file
You must submit all the files needed to make your assignment function properly. Do not assume that the instructors has any files unless explicitly stated by the instructor. Your assignment must work as submitted.
^ top
Home
| WebCT
| Announcements
| Schedule
| Expectations
| Course info
Help
| FAQ's
| HowTo's
| Links
Last Updated: September 14 2004 @15:03:57
|