|
|
Java Student Project |
||
|
|||
Calculator |
|||
|
|
|
||
| Ability Level: | Beginner | ||
|
|
|
||
| Estimated Time: | 40 minutes | ||
|
|
|
||
| Objectives: |
|
||
|
|
|
||
| Materials & Resources: |
|
||
|
|
|
||
| Overview: | Create a program that displays the result of sales transaction. The calculation requires three numbers. The first number represents the product price. The second number is the salesperson commission. These two numbers should be added together. The third value represents a customer discount; subtract this third number from the result of the addition. Create two classes. The first class contains the method to do the calculation. The three numbers are passed to this method by a statement in the other class. The display is performed in the class that calls the calculation method. This program must be
user friendly, outputting the name of the program, the
program author, and date written. Read the hints in this
project for further understanding. |
||
|
|
|
||
| Instructions: | See the notes in overview above. | ||
|
|
|
||
| Hints: | Some important
points to keep in mind in doing this project:
1.
Although there are differences, if you have programmed
using other programming languages, you can think of methods of
being similar to procedures, functions or subroutines. 2.
A method must include the following: a.
A declaration (or header or definition) b.
An opening curly bracket c.
A body d.
A closing curly bracket 3.
The method declaration contains the following: a.
Optional access modifiers b.
The return type for the method c.
The method name d.
An opening parenthesis e.
An optional list of method arguments (you separate the
arguments which commas if there is more than one) f.
A closing parenthesis 4.
If you want one class to call another class’s method,
both classes should reside in the same folder.
If they are not saved in the same place, your computer
will issue the error message, “undefined variable or class
name.” 5.
At any call, the println()
method can receive any one of an infinite number of arguments.
No matter what message is sent to println(),
the message displays correctly. 6.
Hidden implementation methods often are referred to as
existing in a black box. 7. If two method arguments are the same type – for example, two doubles – passing them to a method in the wrong order results in a logical error. If an argument expects arguments of diverse types, then passing arguments in reverse order constitutes a syntax error. 8. The arguments in a method call often are referred to as actual parameters. The variables in the method declaration that accept the values from the actual parameters are the formal parameters. 9. When coding two classes with methods, only use 'public' with the file name. The other class should be named with a different identifier. |
||